Class BaseConfiguration

java.lang.Object
com.portal.pcm.configuration.BaseConfiguration
All Implemented Interfaces:
Configuration
Direct Known Subclasses:
PropertiesConfiguration

public class BaseConfiguration extends Object implements Configuration
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 Details

    • BaseConfiguration

      public BaseConfiguration()
      Default (private) constructor used in creating hierarchical entries.
  • Method Details

    • addKey

      public void addKey(String key, String value)
      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

      public Set<String> getBlockKeys(String key) throws ConfigurationException
      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:
      getBlockKeys in interface Configuration
      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

      public Set<String> getBlockKeys() throws ConfigurationException
      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:
      getBlockKeys in interface Configuration
      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

      public Set<String> getValueKeys(String key) throws ConfigurationException
      Gets the keys for 'leaf' values for a given location in the configuration hierarchy (i.e. not 'blocks')
      Specified by:
      getValueKeys in interface Configuration
      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

      public Set<String> getValueKeys() throws ConfigurationException
      Gets the keys for 'leaf' values for the current location in the configuration hierarchy (i.e. not 'blocks')
      Specified by:
      getValueKeys in interface Configuration
      Returns:
      a set of String keys for the values.
      Throws:
      ConfigurationException - if the key requested is not a block in the configuration.
    • getOptionalBlock

      public Configuration getOptionalBlock(String key) throws ConfigurationException
      Attempt to get a block of configuration for the key provided (without raising an error if it does not exist)
      Specified by:
      getOptionalBlock in interface Configuration
      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

      public Configuration getBlock(String key) throws ConfigurationException
      Attempt to get a block of configuration for the key provided (raise an error if it does not exist)
      Specified by:
      getBlock in interface Configuration
      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

      public Integer getOptionalInteger(String key, Integer defValue) throws ConfigurationException
      Attempt to get an integer from the configuration for the key provided.
      Specified by:
      getOptionalInteger in interface Configuration
      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

      public Integer getOptionalInteger(String key) throws ConfigurationException
      Attempt to get an integer from the configuration for the key provided.
      Specified by:
      getOptionalInteger in interface Configuration
      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

      public Integer getInteger(String key) throws ConfigurationException
      Attempt to get an integer from the configuration for the key provided.
      Specified by:
      getInteger in interface Configuration
      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

      public Long getOptionalLong(String key, Long defValue) throws ConfigurationException
      Attempt to get a long from the configuration for the key provided.
      Specified by:
      getOptionalLong in interface Configuration
      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

      public Long getOptionalLong(String key) throws ConfigurationException
      Attempt to get a long from the configuration for the key provided.
      Specified by:
      getOptionalLong in interface Configuration
      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

      public Long getLong(String key) throws ConfigurationException
      Attempt to get a long from the configuration for the key provided.
      Specified by:
      getLong in interface Configuration
      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

      public Boolean getOptionalBoolean(String key, Boolean defValue) throws ConfigurationException
      Attempt to get a boolean from the configuration for the key provided.
      Specified by:
      getOptionalBoolean in interface Configuration
      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

      public Boolean getOptionalBoolean(String key) throws ConfigurationException
      Attempt to get a boolean from the configuration for the key provided.
      Specified by:
      getOptionalBoolean in interface Configuration
      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

      public Boolean getBoolean(String key) throws ConfigurationException
      Attempt to get a boolean from the configuration for the key provided.
      Specified by:
      getBoolean in interface Configuration
      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

      public String getString(String key) throws ConfigurationException
      Attempt to get a string from the configuration for the key provided.
      Specified by:
      getString in interface Configuration
      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

      public String getOptionalString(String key, String defValue) throws ConfigurationException
      Attempt to get a string from the configuration for the key provided.
      Specified by:
      getOptionalString in interface Configuration
      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

      public String getOptionalString(String key) throws ConfigurationException
      Attempt to get a string from the configuration for the key provided.
      Specified by:
      getOptionalString in interface Configuration
      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

      public String toString()
      Get a pretty-printed string representation of the configuration object.
      Specified by:
      toString in interface Configuration
      Overrides:
      toString in class Object
      Returns:
      the string representation of the configuration in hierarchical form.
    • toProperties

      public Properties toProperties()
      Convert a configuration into a Properties object
      Specified by:
      toProperties in interface Configuration
      Returns:
      A valid Properties object