1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 
  34 #ifndef PACKAGE_H
  35 #define PACKAGE_H
  36 
  37 
  38 #include "Platform.h"
  39 #include "PlatformString.h"
  40 #include "FilePath.h"
  41 #include "PropertyFile.h"
  42 
  43 #include <map>
  44 #include <list>
  45 
  46 class PackageBootFields {
  47 public:
  48     enum MemoryState {msManual, msAuto};
  49     
  50 public:
  51     TOrderedMap FJVMArgs;
  52     std::list<TString> FArgs;
  53     
  54     TString FPackageRootDirectory;
  55     TString FPackageAppDirectory;
  56     TString FPackageLauncherDirectory;
  57     TString FAppID;
  58     TString FPackageAppDataDirectory;
  59     TString FClassPath;
  60     TString FMainJar;
  61     TString FMainClassName;
  62     bool FIsRuntimeBundled;
  63     TString FJVMRuntimeDirectory;
  64     TString FJVMLibraryFileName;
  65     TString FSplashScreenFileName;
  66     bool FUseJavaPreferences;
  67     TString FCommandName;
  68     
  69     TPlatformNumber FMemorySize;
  70     MemoryState FMemoryState;
  71 };
  72 
  73 
  74 class Package {
  75 private:
  76     Package(Package const&); // Don't Implement.
  77     void operator=(Package const&); // Don't implement
  78 
  79 private:
  80     PackageBootFields* FBootFields;
  81     TString FJVMUserArgsConfigFileName;
  82     
  83     DebugState FDebugging;
  84 
  85     //PropertyFile* FJVMUserConfig; // Contains JVM user overrides
  86     TOrderedMap FJVMUserArgsOverrides;
  87     TOrderedMap FDefaultJVMUserArgs; // Contains JVM user defaults
  88     TOrderedMap FJVMUserArgs; // Contains a merge of JVM defaults and user overrides
  89 
  90 
  91     Package(void);
  92 
  93     void Initialize();
  94     void MergeJVMDefaultsWithOverrides();
  95     TString GetMainJar();
  96     void SaveJVMUserArgOverrides(TOrderedMap Data);
  97     
  98 public:
  99     static Package& GetInstance();
 100     ~Package(void);
 101 
 102     void FreeBootFields();
 103 
 104     void SetCommandLineArguments(int argc, TCHAR* argv[]);
 105 
 106     TOrderedMap GetJVMArgs();
 107     TOrderedMap GetDefaultJVMUserArgs();
 108     TOrderedMap GetJVMUserArgOverrides();
 109     void SetJVMUserArgOverrides(TOrderedMap Value);
 110     TOrderedMap GetJVMUserArgs();
 111 
 112     std::list<TString> GetArgs();
 113 
 114     TString GetPackageRootDirectory();
 115     TString GetPackageAppDirectory();
 116     TString GetPackageLauncherDirectory();
 117     
 118     TString GetJVMUserArgsConfigFileName();
 119 
 120     TString GetAppID();
 121     TString GetPackageAppDataDirectory();
 122     TString GetClassPath();
 123     TString GetMainClassName();
 124     bool IsRuntimeBundled();
 125     TString GetJVMLibraryFileName();
 126     TString GetJVMRuntimeDirectory();
 127     TString GetSplashScreenFileName();
 128     bool HasSplashScreen();
 129     TString GetCommandName();
 130     
 131     TPlatformNumber GetMemorySize();
 132     PackageBootFields::MemoryState GetMemoryState();
 133     
 134     DebugState Debugging();
 135 };
 136 
 137 #endif //PACKAGE_H