Package net.sourceforge.jnlp.config
Class DeploymentConfiguration
- java.lang.Object
-
- net.sourceforge.jnlp.config.DeploymentConfiguration
-
public final class DeploymentConfiguration extends java.lang.ObjectManages the various properties and configuration related to deployment. See: http://download.oracle.com/javase/1.5.0/docs/guide/deployment/deployment-guide/properties.html
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDeploymentConfiguration.ConfigType
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,Setting>currentConfigurationthe current deployment propertiesprivate javax.naming.ConfigurationExceptionloadingExceptionstatic java.lang.StringLOCAL_DEPLOYMENT_PROPERTIES_FILE_PATHstatic java.lang.StringLOCKED_POSTFIXprivate static LoggerLOGprivate static java.text.SimpleDateFormatpatternprivate java.net.URLsystemPropertiesFileThe system's subdirResult deployment.config fileprivate booleansystemPropertiesMandatoryis it mandatory to load the system properties?private java.util.Map<java.lang.String,Setting>unchangeableConfigurationthe deployment properties that cannot be changedstatic java.lang.StringUSER_HOME_DIR_TOKENprivate java.lang.StringuserCommentsprivate InfrastructureFileDescriptoruserDeploymentFileDescriptorSource of always right and only path to file (even if underlying path changes)private java.io.FileuserPropertiesFileThe user's subdirResult deployment.config file
-
Constructor Summary
Constructors Constructor Description DeploymentConfiguration()DeploymentConfiguration(InfrastructureFileDescriptor configFile)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckAndFixConfiguration(java.util.Map<java.lang.String,Setting> initial)Check that the configuration is valid.(package private) static booleancheckUrl(java.net.URL file)voidcopyTo(java.util.Properties target)Copies the current configuration into the targetprivate static voiddumpConfiguration(java.util.Map<java.lang.String,Setting> config, java.io.PrintStream out)Dumps the configuration to the PrintStreamprivate java.net.URLfindSystemConfigFile()Looks in the following locations:java.util.Set<java.lang.String>getAllPropertyNames()javax.naming.ConfigurationExceptiongetLoadingException()java.lang.StringgetProperty(java.lang.String key)Get the value for the given keyjava.util.List<java.lang.String>getPropertyAsList(java.lang.String key)java.util.Map<java.lang.String,Setting>getRaw()private java.util.Optional<Setting>getSetting(java.lang.String key)booleanisLocked(java.lang.String key)voidload()Initialize this deployment configuration by reading configuration files.voidload(boolean fixIssues)Initialize this deployment configuration by reading configuration files.private static java.lang.StringloadComments(java.net.URL path)(package private) static java.util.Map<java.lang.String,Setting>loadProperties(DeploymentConfiguration.ConfigType type, java.net.URL file, boolean mandatory)Loads the properties from the given file into a map ofSettings.private booleanloadSystemConfiguration(java.net.URL configFile)Reads the system configuration file and sets the relevant system-properties related variablesprivate java.util.Map<java.lang.String,Setting>loadSystemProperties()First loads thedeployment.configfile to determine the URL of the system properties.voidlock(java.lang.String key)private voidmergeMaps(java.util.Map<java.lang.String,Setting> finalMap, java.util.Map<java.lang.String,Setting> srcMap)Merges two maps while respecting whether the values have been locked or not.private static java.util.Map<java.lang.String,Setting>parsePropertiesFile(java.net.URL propertiesFile)Reads a properties file and returns a map representing the propertiesprivate voidprocessPropertiesWithHomeDirToken(java.util.Map<java.lang.String,Setting> properties)voidresetToDefaults()voidsave()Saves all properties that are not part of default or system propertiesvoidsetLoadingException(javax.naming.ConfigurationException ex)voidsetProperty(java.lang.String key, java.lang.String value)Sets the value of corresponding to the key.voidunlock(java.lang.String key)static java.lang.StringVVPossibleBrowserValues()convenient method to show VVPossibleBrowserValues with all four params
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
LOCKED_POSTFIX
public static final java.lang.String LOCKED_POSTFIX
- See Also:
- Constant Field Values
-
LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH
public static final java.lang.String LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH
- See Also:
- Constant Field Values
-
USER_HOME_DIR_TOKEN
public static final java.lang.String USER_HOME_DIR_TOKEN
- See Also:
- Constant Field Values
-
userComments
private java.lang.String userComments
-
loadingException
private javax.naming.ConfigurationException loadingException
-
systemPropertiesMandatory
private boolean systemPropertiesMandatory
is it mandatory to load the system properties?
-
systemPropertiesFile
private java.net.URL systemPropertiesFile
The system's subdirResult deployment.config file
-
userDeploymentFileDescriptor
private final InfrastructureFileDescriptor userDeploymentFileDescriptor
Source of always right and only path to file (even if underlying path changes)
-
userPropertiesFile
private java.io.File userPropertiesFile
The user's subdirResult deployment.config file
-
currentConfiguration
private final java.util.Map<java.lang.String,Setting> currentConfiguration
the current deployment properties
-
unchangeableConfiguration
private final java.util.Map<java.lang.String,Setting> unchangeableConfiguration
the deployment properties that cannot be changed
-
pattern
private static final java.text.SimpleDateFormat pattern
-
-
Constructor Detail
-
DeploymentConfiguration
public DeploymentConfiguration()
-
DeploymentConfiguration
DeploymentConfiguration(InfrastructureFileDescriptor configFile)
-
-
Method Detail
-
getSetting
private java.util.Optional<Setting> getSetting(java.lang.String key)
-
isLocked
public boolean isLocked(java.lang.String key)
-
lock
public void lock(java.lang.String key)
-
unlock
public void unlock(java.lang.String key)
-
setLoadingException
public void setLoadingException(javax.naming.ConfigurationException ex)
-
getLoadingException
public javax.naming.ConfigurationException getLoadingException()
-
resetToDefaults
public void resetToDefaults()
-
checkUrl
static boolean checkUrl(java.net.URL file)
-
load
public void load() throws javax.naming.ConfigurationExceptionInitialize this deployment configuration by reading configuration files. Generally, it will try to continue and ignore errors it finds (such as file not found).- Throws:
javax.naming.ConfigurationException- if it encounters a fatal error.
-
load
public void load(boolean fixIssues) throws javax.naming.ConfigurationException, java.net.MalformedURLExceptionInitialize this deployment configuration by reading configuration files. Generally, it will try to continue and ignore errors it finds (such as file not found).- Parameters:
fixIssues- If true, fix issues that are discovered when reading configuration by resorting to the default values- Throws:
javax.naming.ConfigurationException- if it encounters a fatal error.java.net.MalformedURLException
-
loadSystemProperties
private java.util.Map<java.lang.String,Setting> loadSystemProperties() throws java.net.MalformedURLException, javax.naming.ConfigurationException
First loads thedeployment.configfile to determine the URL of the system properties. The deployment config file must contain a property with the keyConfigurationConstants.KEY_SYSTEM_CONFIG. Optionally it can require the system properties to exist with the kyeConfigurationConstants.KEY_SYSTEM_CONFIG_MANDATORY.- Returns:
- the system properties
- Throws:
java.net.MalformedURLExceptionjavax.naming.ConfigurationException- See Also:
findSystemConfigFile(),loadSystemConfiguration(URL)
-
copyTo
public void copyTo(java.util.Properties target)
Copies the current configuration into the target- Parameters:
target- properties where to copy actual ones
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Get the value for the given key- Parameters:
key- the property key- Returns:
- the value for the key, or null if it can not be found
-
getPropertyAsList
public java.util.List<java.lang.String> getPropertyAsList(java.lang.String key)
-
getAllPropertyNames
public java.util.Set<java.lang.String> getAllPropertyNames()
- Returns:
- a Set containing all the property names
-
getRaw
public java.util.Map<java.lang.String,Setting> getRaw()
- Returns:
- a map containing property names and the corresponding settings
-
setProperty
public void setProperty(java.lang.String key, java.lang.String value)Sets the value of corresponding to the key. If the value has been marked as locked, it is not changed- Parameters:
key- the keyvalue- the value to be associated with the key
-
checkAndFixConfiguration
private void checkAndFixConfiguration(java.util.Map<java.lang.String,Setting> initial)
Check that the configuration is valid. If there are invalid values,set those values to the default values. This is done by using check() method of the ValueChecker for each setting on the actual value. Fixes are made in-place.- Parameters:
initial- a map representing the initial configuration
-
processPropertiesWithHomeDirToken
private void processPropertiesWithHomeDirToken(java.util.Map<java.lang.String,Setting> properties)
-
findSystemConfigFile
private java.net.URL findSystemConfigFile() throws java.net.MalformedURLExceptionLooks in the following locations:Unix: - /etc/.java/deployment.config - ${JAVA_HOME}/lib/deployment.config Windows: - ${WINDIR}\Sun\Java\deployment.config - ${JAVA_HOME}/lib/deployment.config- Returns:
- the location of system-level deployment.config file, or null if none can be found
- Throws:
java.net.MalformedURLException
-
loadSystemConfiguration
private boolean loadSystemConfiguration(java.net.URL configFile) throws javax.naming.ConfigurationExceptionReads the system configuration file and sets the relevant system-properties related variables- Throws:
javax.naming.ConfigurationException
-
loadProperties
static java.util.Map<java.lang.String,Setting> loadProperties(DeploymentConfiguration.ConfigType type, java.net.URL file, boolean mandatory) throws javax.naming.ConfigurationException
Loads the properties from the given file into a map ofSettings. If the given properties file does not exist or the URL is invalid and not mandatory, an empty Map is returned. If the file is considered to be mandatory but does not exist, a ConfigurationException is thrown.- Parameters:
type- the ConfigType to loadfile- the File to load Properties frommandatory- indicates if reading this file is mandatory- Throws:
javax.naming.ConfigurationException- if the file is mandatory but does not exist or cannot be read properly
-
save
public void save() throws java.io.IOExceptionSaves all properties that are not part of default or system properties- Throws:
java.io.IOException- if unable to save the filejava.lang.IllegalStateException- if save() is called before load()
-
parsePropertiesFile
private static java.util.Map<java.lang.String,Setting> parsePropertiesFile(java.net.URL propertiesFile) throws java.io.IOException
Reads a properties file and returns a map representing the properties- Parameters:
propertiesFile- the file to read Properties from- Throws:
java.io.IOException- if an IO problem occurs
-
mergeMaps
private void mergeMaps(java.util.Map<java.lang.String,Setting> finalMap, java.util.Map<java.lang.String,Setting> srcMap)
Merges two maps while respecting whether the values have been locked or not. All values from srcMap are put into finalMap, replacing values in finalMap if necessary, unless the value is present and marked as locked in finalMap- Parameters:
finalMap- the destination for putting valuessrcMap- the source for reading key value pairs
-
dumpConfiguration
private static void dumpConfiguration(java.util.Map<java.lang.String,Setting> config, java.io.PrintStream out)
Dumps the configuration to the PrintStream- Parameters:
config- a map of key,value pairs representing the configuration to dumpout- the PrintStream to write data to
-
loadComments
private static java.lang.String loadComments(java.net.URL path)
-
VVPossibleBrowserValues
public static java.lang.String VVPossibleBrowserValues()
convenient method to show VVPossibleBrowserValues with all four params- Returns:
- translation of VVPossibleBrowserValues with all params in
-
-