public final class GlobalSettings extends Object
This class provides a global access to the settings for the application. It needs to be setup prior to using most of the classes used in this application.
This class uses two main access points:
The repository and config may be specified using System properties,
respectively berlioz.repository
and berlioz.config
.
load()
,
setRepository(File)
,
setMode(String)
Modifier and Type | Field and Description |
---|---|
static String |
CONFIG_DIRECTORY
Name of the configuration directory in the repository.
|
static String |
DEFAULT_MODE
Name of the default configuration to use.
|
static String |
LIBRARY_DIRECTORY
Name of the directory in the repository that contains all the schemas / DTD for the XML files
used by Berlioz.
|
Modifier and Type | Method and Description |
---|---|
static int |
countProperties()
Returns the number of properties defined in the file.
|
static String |
get(BerliozOption option)
Return the property value for the specified Berlioz option.
|
static String |
get(String name)
Return the requested property.
|
static boolean |
get(String name,
boolean def)
Returns the requested property or it default value.
|
static File |
get(String name,
File def)
Returns the requested property as a file or its default file value.
|
static int |
get(String name,
int def) |
static String |
get(String name,
String def)
Returns the requested property or it default value.
|
static File |
getDirProperty(String name)
Returns the requested property as a file.
|
static File |
getFileProperty(String name)
Returns the requested property as a file.
|
static File |
getLibrary()
Returns the directory containing the DTDs and schemas for the XML in use in the
system.
|
static String |
getMode()
Returns the configuration to use.
|
static Properties |
getNode(String name)
Returns the entries for the specified node as
Properties . |
static File |
getPropertiesFile()
Returns the properties file to use externally.
|
static File |
getRepository()
Returns the main repository or
null if it has not been setup. |
static String |
getVersion()
Returns the build version of Berlioz.
|
static boolean |
has(BerliozOption option)
Indicates whether the property value for the specified Berlioz option is enabled.
|
static boolean |
load()
Loads the properties.
|
static Enumeration<String> |
propertyNames()
Enumerates the properties in the global settings.
|
static void |
registerListener(ConfigListener listener)
Add a listener to invoke when the settings are being loaded or reloaded.
|
static void |
setConfig(String name)
Deprecated.
Use
setMode(String) instead. |
static void |
setMode(String name)
Sets the configuration mode to use.
|
static void |
setRepository(File dir)
Sets the repository to the specified file if it exists and is a directory.
|
public static final String CONFIG_DIRECTORY
public static final String LIBRARY_DIRECTORY
public static final String DEFAULT_MODE
public static File getRepository()
null
if it has not been setup.null
.public static int countProperties()
public static String getVersion()
public static String getMode()
public static File getLibrary()
This method will return a file only if the repository has been properly set,
and will be the directory defined by LIBRARY_DIRECTORY
in the repository.
public static File getPropertiesFile()
null
.public static String get(String name) throws IllegalStateException
Returns null
if the property is not found or defined.
If the properties file has not been loaded, this method will invoke the load()
method before returning an Enumeration
.
name
- the name of the propertynull
.IllegalStateException
- If this class has not been setup properly.public static String get(BerliozOption option) throws IllegalStateException
Returns the default
value if the property is not found or defined.
If the properties file has not been loaded, this method will invoke the load()
method before returning an Enumeration
.
option
- the name of the propertyIllegalStateException
- If this class has not been setup properly.public static boolean has(BerliozOption option)
Returns the default
value if the property is not found or defined.
If the properties file has not been loaded, this method will invoke the load()
method.
option
- the name of the propertytrue
or not.IllegalStateException
- If this class has not been setup properly.IllegalArgumentException
- If this class has not been setup properly.NullPointerException
- If the specified option is null
.public static String get(String name, String def) throws IllegalStateException
The given default value is returned only if the property is not found.
If the properties file has not been loaded, this method will invoke the load()
method before returning an Enumeration
.
name
- The name of the property.def
- A default value for the property.IllegalStateException
- If this class has not been setup properly.public static int get(String name, int def) throws IllegalStateException
name
- The name of the property.def
- A default value for the property.IllegalStateException
- If this class has not been setup properly.public static boolean get(String name, boolean def) throws IllegalStateException
The given default value is returned only if the property is not found.
If the properties file has not been loaded, this method will invoke the load()
.
name
- The name of the property.def
- A default value for the property.IllegalStateException
- If this class has not been setup properly.public static File get(String name, File def) throws IllegalStateException
The given default value is returned if:
If the properties file has not been loaded, this method will invoke the load()
.
name
- The name of the property.def
- A default value for the property.IllegalStateException
- If this class has not been setup properly.public static File getDirProperty(String name) throws IllegalStateException
The given default value is returned if:
If the properties file has not been loaded, this method will invoke the load()
.
name
- The name of the property.IllegalStateException
- If this class has not been setup properly.public static File getFileProperty(String name) throws IllegalStateException
The given default value is returned if:
If the properties file has not been loaded, this method will invoke the load()
.
name
- The name of the property.IllegalStateException
- If this class has not been setup properly.public static Properties getNode(String name)
Properties
.name
- The name of the database.IllegalStateException
- If this class has not been setup properly.public static Enumeration<String> propertyNames() throws IllegalStateException
IllegalStateException
- If this class has not been setup properly.public static void setRepository(File dir) throws IllegalArgumentException
Does nothing if the specified file is null
.
If the specified file does not exist or is not a directory, the repository will remain unchanged.
dir
- The directory to use as the main repository.IllegalArgumentException
- If the specified file is not a valid repository.public static void setMode(String name)
name
- The name of the mode to use.NullPointerException
- If the name of the mode is null
.@Deprecated public static void setConfig(String name) throws IllegalArgumentException
setMode(String)
instead.name
- The name of the configuration to use.IllegalArgumentException
- If the name of the configuration is null
.public static boolean load() throws IllegalStateException
There are several mechanism to load the properties.
First, this method will try to use the properties file that might have been setup with
the #setPropertiesFile(File)
method.
If all of the above fail, the properties will remain empty, this method will return
false
to indicate that the properties could not be loaded.
Errors will only be reported to the System
error output, the complete stack
trace will be available.
In all cases, the file must be conform to the java properties specifications.
true
if the properties were loaded; false
otherwise.IllegalStateException
- If this class has not been setup properly.Properties
,
System.getProperty(java.lang.String)
,
ClassLoader.getResourceAsStream(java.lang.String)
public static void registerListener(ConfigListener listener)
listener
- The listener to register.Copyright © 2016 Allette Systems. All rights reserved.