Package com.portal.pcm.configuration
Class BaseConfiguration
java.lang.Object
com.portal.pcm.configuration.BaseConfiguration
- All Implemented Interfaces:
Configuration
- Direct Known Subclasses:
PropertiesConfiguration
Configuration class which provides a hierarchical view of the configuration values that
are loaded from one or more sources ...
The configuration is structured hierarchically so that one can retrieve sub-sets of the
Configuration easily for passing around.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault (private) constructor used in creating hierarchical entries. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a key (of the form "a.b.c") and its value to the configuration structure.Attempt to get a block of configuration for the key provided (raise an error if it does not exist)Gets all the lower-level keys for the current block in the configuration that are blocks of configuration (i.e.getBlockKeys(String key) Gets all the lower-level keys for a given block in the configuration that are blocks of configuration (i.e.getBoolean(String key) Attempt to get a boolean from the configuration for the key provided.getInteger(String key) Attempt to get an integer from the configuration for the key provided.Attempt to get a long from the configuration for the key provided.getOptionalBlock(String key) Attempt to get a block of configuration for the key provided (without raising an error if it does not exist)getOptionalBoolean(String key) Attempt to get a boolean from the configuration for the key provided.getOptionalBoolean(String key, Boolean defValue) Attempt to get a boolean from the configuration for the key provided.getOptionalInteger(String key) Attempt to get an integer from the configuration for the key provided.getOptionalInteger(String key, Integer defValue) Attempt to get an integer from the configuration for the key provided.getOptionalLong(String key) Attempt to get a long from the configuration for the key provided.getOptionalLong(String key, Long defValue) Attempt to get a long from the configuration for the key provided.getOptionalString(String key) Attempt to get a string from the configuration for the key provided.getOptionalString(String key, String defValue) Attempt to get a string from the configuration for the key provided.Attempt to get a string from the configuration for the key provided.Gets the keys for 'leaf' values for the current location in the configuration hierarchy (i.e.getValueKeys(String key) Gets the keys for 'leaf' values for a given location in the configuration hierarchy (i.e.Convert a configuration into a Properties objecttoString()Get a pretty-printed string representation of the configuration object.
-
Constructor Details
-
BaseConfiguration
public BaseConfiguration()Default (private) constructor used in creating hierarchical entries.
-
-
Method Details
-
addKey
Add a key (of the form "a.b.c") and its value to the configuration structure. The key will be parsed and split to create a hierarchical structure (a => b => c). This only supports String values (which may later be retrieved as Integers, Booleans, Strings etc.)- Parameters:
key- The key string to use (e.g. "a.b.c")value- The value for this entry (e.g. "abc")
-
getBlockKeys
Gets all the lower-level keys for a given block in the configuration that are blocks of configuration (i.e. not 'leaf' values).- Specified by:
getBlockKeysin interfaceConfiguration- Parameters:
key- the key to the section of the configuration we're interested in.- Returns:
- a set of String keys for the block (or an empty set if there are none)
- Throws:
ConfigurationException- if the key refers to a 'leaf' value, not a block
-
getBlockKeys
Gets all the lower-level keys for the current block in the configuration that are blocks of configuration (i.e. not 'leaf' values).- Specified by:
getBlockKeysin interfaceConfiguration- Returns:
- a set of String keys for the block (or an empty set if there are none)
- Throws:
ConfigurationException- if the key refers to a 'leaf' value, not a block
-
getValueKeys
Gets the keys for 'leaf' values for a given location in the configuration hierarchy (i.e. not 'blocks')- Specified by:
getValueKeysin interfaceConfiguration- Parameters:
key- the key to the section of the configuration we're interested in.- Returns:
- a set of String keys for the values.
- Throws:
ConfigurationException- if the key requested is not a block in the configuration.
-
getValueKeys
Gets the keys for 'leaf' values for the current location in the configuration hierarchy (i.e. not 'blocks')- Specified by:
getValueKeysin interfaceConfiguration- Returns:
- a set of String keys for the values.
- Throws:
ConfigurationException- if the key requested is not a block in the configuration.
-
getOptionalBlock
Attempt to get a block of configuration for the key provided (without raising an error if it does not exist)- Specified by:
getOptionalBlockin interfaceConfiguration- Parameters:
key- the key to the section of the configuration we're interested in.- Returns:
- a pointer to the Configuration or null if it does not exist.
- Throws:
ConfigurationException- if the key requested is not a block in the configuration (i.e. it is a 'leaf value').
-
getBlock
Attempt to get a block of configuration for the key provided (raise an error if it does not exist)- Specified by:
getBlockin interfaceConfiguration- Parameters:
key- the key to the section of the configuration we're interested in.- Returns:
- a pointer to the Configuration.
- Throws:
ConfigurationException- if the key requested is not a block in the configuration or does not exist.
-
getOptionalInteger
Attempt to get an integer from the configuration for the key provided.- Specified by:
getOptionalIntegerin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.defValue- the default value to use if the key value is not found.- Returns:
- The integer value of the configuration parameter or the default value if not found
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not an integer
-
getOptionalInteger
Attempt to get an integer from the configuration for the key provided.- Specified by:
getOptionalIntegerin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The integer value of the configuration parameter (or null if not found).
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, is not an integer.
-
getInteger
Attempt to get an integer from the configuration for the key provided.- Specified by:
getIntegerin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The integer value of the configuration parameter.
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not an integer, or is not found
-
getOptionalLong
Attempt to get a long from the configuration for the key provided.- Specified by:
getOptionalLongin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.defValue- the default value to use if the key value is not found.- Returns:
- The long value of the configuration parameter or the default value if not found
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not a long
-
getOptionalLong
Attempt to get a long from the configuration for the key provided.- Specified by:
getOptionalLongin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The long value of the configuration parameter (or null if not found).
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, is not a long.
-
getLong
Attempt to get a long from the configuration for the key provided.- Specified by:
getLongin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The long value of the configuration parameter.
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not a long, or is not found
-
getOptionalBoolean
Attempt to get a boolean from the configuration for the key provided.- Specified by:
getOptionalBooleanin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The boolean value of the configuration parameter or the default value (if not found)
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not a boolean
-
getOptionalBoolean
Attempt to get a boolean from the configuration for the key provided.- Specified by:
getOptionalBooleanin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The boolean value of the configuration parameter or null if not found
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not a boolean
-
getBoolean
Attempt to get a boolean from the configuration for the key provided.- Specified by:
getBooleanin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The boolean value of the configuration parameter or null if not found
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not a boolean
-
getString
Attempt to get a string from the configuration for the key provided.- Specified by:
getStringin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The string value of the configuration parameter
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not found
-
getOptionalString
Attempt to get a string from the configuration for the key provided.- Specified by:
getOptionalStringin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The string value of the configuration parameter (or the default value if not found)
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not a string
-
getOptionalString
Attempt to get a string from the configuration for the key provided.- Specified by:
getOptionalStringin interfaceConfiguration- Parameters:
key- the key to the configuration entity we're interested in.- Returns:
- The string value of the configuration parameter (or null if not found)
- Throws:
ConfigurationException- if the key requested is not a value in the configuration, or is not a string
-
toString
Get a pretty-printed string representation of the configuration object.- Specified by:
toStringin interfaceConfiguration- Overrides:
toStringin classObject- Returns:
- the string representation of the configuration in hierarchical form.
-
toProperties
Convert a configuration into a Properties object- Specified by:
toPropertiesin interfaceConfiguration- Returns:
- A valid Properties object
-