Class Configuration


  • public class Configuration
    extends java.lang.Object
    Implements a multi-layered configuration. There are three layers of configuration - in order of increasing precedence: defaults, configuration and runtime. Defaults and configured properties can be loaded (from a .properties file) or set (from a Map), while runtime properties are retrieved from System.getProperties().
    Author:
    Sam Adams
    • Constructor Summary

      Constructors 
      Constructor Description
      Configuration()
      Construct a new configuration with no parameters.
      Configuration​(java.util.Map<java.lang.String,​java.lang.String> params)
      Construct a new configuration with the specified parameters.
      Configuration​(Configuration parentConfig, java.util.Map<java.lang.String,​java.lang.String> params, java.util.Properties configuration)
      Construct a new configuration with the specified parent configuration, and parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getProperty​(java.lang.String key)
      Gets the property's value.
      void loadConfiguration​(java.io.InputStream in)
      Load the configured properties.
      void loadDefaults​(java.io.InputStream in)
      Load the default property values.
      void setConfiguration​(java.util.Map<java.lang.String,​java.lang.String> config)
      Sets the configured properties.
      void setDefaults​(java.util.Map<java.lang.String,​java.lang.String> defaults)
      Sets the default property values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Configuration

        public Configuration()
        Construct a new configuration with no parameters.
      • Configuration

        public Configuration​(java.util.Map<java.lang.String,​java.lang.String> params)
        Construct a new configuration with the specified parameters.
        Parameters:
        params -
      • Configuration

        public Configuration​(Configuration parentConfig,
                             java.util.Map<java.lang.String,​java.lang.String> params,
                             java.util.Properties configuration)
        Construct a new configuration with the specified parent configuration, and parameters.
        Parameters:
        parentConfig -
        params -
    • Method Detail

      • loadDefaults

        public void loadDefaults​(java.io.InputStream in)
                          throws java.io.IOException
        Load the default property values. Existing defaults with the same name will be overridden. Invokes java.util.Properties.load().
        Parameters:
        in -
        Throws:
        java.io.IOException
      • setDefaults

        public void setDefaults​(java.util.Map<java.lang.String,​java.lang.String> defaults)
        Sets the default property values. Existing defaults with the same name will be overridden.
        Parameters:
        defaults -
      • loadConfiguration

        public void loadConfiguration​(java.io.InputStream in)
                               throws java.io.IOException
        Load the configured properties. Invokes java.util.Properties.load().
        Parameters:
        in -
        Throws:
        java.io.IOException
      • setConfiguration

        public void setConfiguration​(java.util.Map<java.lang.String,​java.lang.String> config)
        Sets the configured properties.
        Parameters:
        config -
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        Gets the property's value.
        Parameters:
        key -
        Returns:
        The value for the specified key, or null if no property of that name exists.