|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.tenduke.utils.PropertyBasedConfigurationProvider
com.tenduke.utils.Configuration
public final class Configuration
Configuration is a singleton class that provides configuration initialization and access to configuration
parameters. The singleton instance of the class is intended to represent application main configuration.
PropertyBasedConfigurationProvider, which this class extends, can be used for other contexts where configuration
needs to be handled using similar interface.
Configuration uses internally Properties, and by default configuration is stored in
file where Properties are represented in XML format defined by java.util.Properties.
Configuration allows user to define the file from which configuration is loaded. Configuration file path is resolved in the following order:
Use instance() method to access the singleton Configuration. Methods of this instance
(PropertyBasedConfigurationProvider.getString(String), PropertyBasedConfigurationProvider.getInt(String), PropertyBasedConfigurationProvider.getBoolean(String) etc.) provide
typed access to the configuration parameters.
Table of configuration keys defined by this class.
| Key name | Description | Default value |
|---|---|---|
| system.default.locale |
System default locale. If the key is undefined or empty, then the default locale is obtained
with java.util.Locale.getDefault() method.
|
java.util.Locale.getDefault()
|
| default.tmp.dir | Directory for temporary files. |
./tmp
|
JVM system properties used in this class are described in the following table:
| System property | Description | Default value |
|---|---|---|
| 10duke.configuration.main | Main configuration file url. If relative url is given, it is resolved as being relative to JVM process execution directory. |
./conf/conf.xml
|
| Field Summary | |
|---|---|
static java.net.URI |
DEFAULT_CONFIGURATION_MAIN
The default main configuration name URI, if the JVM system property KEY_CONFIGURATION_MAIN does not exist or contains
an invalid value. |
static java.lang.String |
DEFAULT_TEMP_DIR
Default temporary directory used if no value for DEFAULT_TEMP_DIRECTORY_CONFIGURATION_KEY is found. |
static java.lang.String |
DEFAULT_TEMP_DIRECTORY_CONFIGURATION_KEY
Configuration key for default temporary directory. |
static java.lang.String |
KEY_CONFIGURATION_MAIN
Name of a JVM system property whose value defines the main configuration name. |
| Fields inherited from class com.tenduke.utils.PropertyBasedConfigurationProvider |
|---|
PROPERTIES_DOC_TYPE, VARIABLES_URL_PARAMETER_NAME |
| Method Summary | |
|---|---|
static java.net.URI |
getConfigurationUrl()
Gets url of the primary configuration file. |
static java.net.URI |
getConfigurationUrlWithoutFilename()
Gets url of the primary configuration file without file name part. |
java.util.Locale |
getSystemDefaultLocale()
Get system default locale. |
java.lang.String |
getTemporaryDirectory(java.lang.String name)
Gets a named temporary directory as a string. |
void |
initializeConfiguration()
Initializes configuration. |
void |
initializeConfiguration(java.io.File confFile)
Initializes configuration from the specified file. |
void |
initializeConfiguration(java.lang.String configPath)
Initializes the main configuration from the given path. |
void |
initializeConfiguration(java.net.URI configUri)
Initializes the main configuration from the given URI. |
void |
initializeConfiguration(java.net.URL urlConfig)
Initializes configuration from the specified URL. |
static Configuration |
instance()
Singleton instance of the Configuration class. |
void |
logLocationInformation()
Log useful information about paths. |
protected void |
parseConfiguration(java.io.InputStream inputStream,
java.net.URI baseUrl)
Parses the main configuration and (re)initializes ConsoleLogWriter settings. |
protected void |
parseConfiguration(java.lang.String configPath)
Parses the main configuration and (re)initializes ConsoleLogWriter settings. |
protected void |
parseConfiguration(java.net.URI configUri)
Parses the main configuration and (re)initializes ConsoleLogWriter settings. |
protected void |
parseConfiguration(java.net.URL urlConfig)
Parses the main configuration and (re)initializes ConsoleLogWriter settings. |
static java.net.URI |
resolveAndNormalize(java.lang.String relative)
Given a relative url String, resolves that relative to the location of primary configuration (see getConfigurationUrl()). |
static java.net.URI |
resolveAndNormalize(java.net.URI relative)
Given a URI, resolves that relative to the location of primary configuration (see getConfigurationUrl()). |
static void |
setConfigurationUrl(java.net.URI configurationUrl)
Sets url locating the primary configuration file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.net.URI DEFAULT_CONFIGURATION_MAIN
KEY_CONFIGURATION_MAIN does not exist or contains
an invalid value. The default main URI is conf.xml
public static final java.lang.String DEFAULT_TEMP_DIR
public static final java.lang.String DEFAULT_TEMP_DIRECTORY_CONFIGURATION_KEY
public static final java.lang.String KEY_CONFIGURATION_MAIN
10duke.configuration.main
| Method Detail |
|---|
public static java.net.URI getConfigurationUrl()
throws java.net.URISyntaxException
KEY_CONFIGURATION_MAIN is looked for. It the property does not exist, then
DEFAULT_CONFIGURATION_MAIN is used as the primary configuration url.
java.net.URISyntaxException - If the JVM system property cannot be converted to URI
public static java.net.URI getConfigurationUrlWithoutFilename()
throws java.net.URISyntaxException
getConfigurationUrl() without filename part.
java.net.URISyntaxException - Thrown if configured primary configuration url is invalid, or if resolved url without filename is invalid.public java.util.Locale getSystemDefaultLocale()
Locale.getDefault() is used.
public java.lang.String getTemporaryDirectory(java.lang.String name)
getTemporaryDirectory in interface ConfigurationProvidergetTemporaryDirectory in class PropertyBasedConfigurationProvidername - Configuration entry name.
public void initializeConfiguration()
throws java.net.URISyntaxException,
java.io.IOException
Initializes configuration.
After calling this thread safe method the configuration parameters can be accessed via methods of
Configuration.instance().
java.net.URISyntaxException - If the JVM system property Configuration.KEY_CONFIGURATION_MAIN is defined, but contains an
invalid URI
java.io.IOException - If I/O error occurred or if a scheme defined by an URI is not supported
public void initializeConfiguration(java.io.File confFile)
throws java.io.IOException,
java.net.URISyntaxException
Initializes configuration from the specified file.
After calling this thread safe method the configuration parameters can be accessed via methods of
Configuration.instance().
confFile - The configuration file.
java.io.IOException - If I/O error occurred
java.net.URISyntaxException - Thrown if path of the given confFile can not be converted to URI.
public void initializeConfiguration(java.lang.String configPath)
throws java.io.IOException,
java.net.URISyntaxException
Initializes the main configuration from the given path.
After calling this thread safe method the configuration parameters can be accessed via methods of
Configuration.instance().
configPath - Path to the main configuration
java.io.IOException - if I/O error occurred or if the scheme defined by configPath is not supported
java.net.URISyntaxException - If configPath is not valid URI
public void initializeConfiguration(java.net.URI configUri)
throws java.io.IOException
Initializes the main configuration from the given URI.
After calling this thread safe method the configuration parameters can be accessed via methods of
Configuration.instance().
configUri - URI to the main configuration
java.io.IOException - If I/O error occurred or if the scheme defined by configPath is not supported
public void initializeConfiguration(java.net.URL urlConfig)
throws java.io.IOException,
java.net.URISyntaxException
Initializes configuration from the specified URL.
After calling this thread safe method the configuration parameters can be accessed via methods of
Configuration.instance().
urlConfig - The configuration URL.
java.io.IOException - If an error occurred when opening a stream from the URL
java.net.URISyntaxException - Thrown if the given URL can not be converted to URI.public static Configuration instance()
public void logLocationInformation()
Log useful information about paths.
protected void parseConfiguration(java.io.InputStream inputStream,
java.net.URI baseUrl)
throws java.io.IOException
ConsoleLogWriter settings.
parseConfiguration in class PropertyBasedConfigurationProviderinputStream - Input stream to the main configurationbaseUrl - Base url used to resolve relative urls of documents included by the document read using the inputStream.
java.io.IOException - If I/O error occurred
protected void parseConfiguration(java.lang.String configPath)
throws java.io.IOException,
java.net.URISyntaxException
ConsoleLogWriter settings.
parseConfiguration in class PropertyBasedConfigurationProviderconfigPath - Path to the main configuration
java.io.IOException - If I/O error occurred
java.net.URISyntaxException - If configPath is not valid URI
protected void parseConfiguration(java.net.URI configUri)
throws java.io.IOException
ConsoleLogWriter settings.
parseConfiguration in class PropertyBasedConfigurationProviderconfigUri - URI to the main configuration
java.io.IOException - If I/O error occurred
protected void parseConfiguration(java.net.URL urlConfig)
throws java.io.IOException,
java.net.URISyntaxException
ConsoleLogWriter settings.
parseConfiguration in class PropertyBasedConfigurationProviderurlConfig - URL to the main configuration
java.io.IOException - If I/O error occurred
java.net.URISyntaxException - Thrown if the given URL can not be converted to URI.
public static java.net.URI resolveAndNormalize(java.lang.String relative)
throws java.net.URISyntaxException
Given a relative url String, resolves that relative to the location of primary configuration (see getConfigurationUrl()).
This method uses the resolve(URI uri) method from Java URI class. Using an absolute URI in
relative resolves to absolute URI.
relative - URI relative to the primary configuration location (see getConfigurationUrl()).
java.net.URISyntaxException - If the configuration url was not correly set up or if the relative string represents
an invalid URI
public static java.net.URI resolveAndNormalize(java.net.URI relative)
throws java.net.URISyntaxException
Given a URI, resolves that relative to the location of primary configuration (see getConfigurationUrl()).
This method uses the resolve(URI uri) method from Java URI class except that the root URI scheme
is ignored when doing the resolving. This allows using scheme and relative path in the primary configuration url, e.g.,
resolving a URI myConf.xml against primary configuration url file:conf/conf.xml resolves to
file:conf/myConf.xml.
By URI standard the file:conf/conf.xml is opaque and thus myConf.xml would be the resolving result if the
scheme would not be ignored.
Using an absolute URI, i.e. URI with scheme, in relative returns the original relative (but new object).
relative - URI relative to the primary configuration location (see getConfigurationUrl()).
java.net.URISyntaxException - If the primary configuration url was not correctly set uppublic static void setConfigurationUrl(java.net.URI configurationUrl)
configurationUrl - Primary configuration url as a URI. URI is used for techical reasons. However, the given URI should always
locate, not only identify, the configuration file.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||