Class SettingsCore<T extends Enum<T> & SettingsCore.SettingsAPI>

  • Type Parameters:
    T - Implementations of SettingsCore supply a context-specific enumeration (which extends Enum<T>) to provide the collection of settings needed in this context. This enumeration must implement the SettingsCore.SettingsAPI interface to provide clients with a common method for retrieving configuration keys and to give the core settings implementation access to the constants and default values of the enumeration.
    All Implemented Interfaces:
    Cloneable, org.apache.commons.configuration2.Configuration, org.apache.commons.configuration2.event.EventSource, org.apache.commons.configuration2.ImmutableConfiguration, org.apache.commons.configuration2.sync.SynchronizerSupport

    public class SettingsCore<T extends Enum<T> & SettingsCore.SettingsAPI>
    extends org.apache.commons.configuration2.CompositeConfiguration
    This class extends CompositeConfiguration, using the facilities provided by this class to produce an aggregated configuration from three sources in the following order of precedence:
    1. System properties
    2. (optional) Stored properties, typically from a properties file
    3. (optional) Default values, typically specified in the enumeration
    To specify stored properties for your configuration, override one of following methods:

    • getStoredConfig() - Your implementation returns a populated Configuration object.
    • getInputStream() - Your implementation returns an input stream supplying key/value pairs.
    • getSettingsUrl() - Your implementation returns the URL from which to load your settings.
    • getSettingsPath() - Your implementation returns the path from which to load your settings.
    NOTE: These methods are listed in order of evaluation, stopping at the first non-null response.
    NOTE: Typical implementations override getSettingsPath(), which will support most scenarios.
    NOTE: Stored properties are declared in Apache's extended syntax. See PropertiesConfiguration for details.
    NOTE: By overriding the getStoredConfig() method, you're able to incorporate any arbitrary Configuration object you need into your settings - including another CompositeConfiguration object.

    Two methods have been provided for you to supply default values for your configuration:

    • Specify default values as arguments of the constant declarations in your settings enumeration and override the SettingsCore.SettingsAPI.val() method. Specifying 'null' for a setting's default value indicates that no default exists.
    • Alternatively, you can override the getDefaults() method with your own implementation.
    NOTE: For settings collections with no default values, you can eliminate unnecessary processing in the core API by overriding getDefaults() with a method that simply returns 'null'.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  SettingsCore.SettingsAPI
      This interface defines the methods of enumerations declaring configuration settings that are used by the core settings implementation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String PROPS_FILE  
    • Constructor Summary

      Constructors 
      Constructor Description
      SettingsCore​(Class<T> enumClass)
      Instantiate a configuration object for the specified enumeration class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected Map<String,​String> getDefaults()
      Get defined system property default values
      NOTE: Default values are optional.
      InputStream getInputStream()
      Get stored property declarations as an input stream.
      NOTE: Property values are typically stored in property files.
      String getSettingsPath()
      Get the path to a stored property declarations file.
      URL getSettingsUrl()
      Get the URL for a stored property declarations file.
      org.apache.commons.configuration2.Configuration getStoredConfig()
      Get stored property declarations as a configuration object.
      static void injectProperties​(String propsFile)
      If a properties file is specified via a System property named propsFile or the [propsFile] argument, the settings in this file are injected into the System properties collection.
      protected void propagateIfNotMissingFile​(org.apache.commons.configuration2.ex.ConfigurationException thrown)
      Propagate the specified configuration exception if it wasn't caused by a missing file.
      • Methods inherited from class org.apache.commons.configuration2.CompositeConfiguration

        addConfiguration, addConfiguration, addConfigurationFirst, addConfigurationFirst, addPropertyDirect, clearInternal, clearPropertyDirect, clone, containsKeyInternal, getConfiguration, getInMemoryConfiguration, getKeysInternal, getKeysInternal, getList, getNumberOfConfigurations, getPropertyInternal, getSource, getStringArray, isEmptyInternal, removeConfiguration, setListDelimiterHandler
      • Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration

        addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, containsKey, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setPropertyInternal, setSynchronizer, setThrowExceptionOnMissing, size, sizeInternal, subset, unlock
      • Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource

        addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
      • Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration

        getEnum, getEnum
    • Constructor Detail

      • SettingsCore

        public SettingsCore​(Class<T> enumClass)
                     throws org.apache.commons.configuration2.ex.ConfigurationException,
                            IOException
        Instantiate a configuration object for the specified enumeration class.
        Parameters:
        enumClass - enumeration class from which to construct the configuration
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException - If a failure is encountered while initializing this configuration object.
        IOException - If a failure is encountered while reading from a configuration input stream.
    • Method Detail

      • getStoredConfig

        public org.apache.commons.configuration2.Configuration getStoredConfig()
        Get stored property declarations as a configuration object.
        Returns:
        populated Configuration object (may be 'null')
        See Also:
        getSettingsPath(), getSettingsUrl(), getInputStream()
      • getInputStream

        public InputStream getInputStream()
        Get stored property declarations as an input stream.
        NOTE: Property values are typically stored in property files.
        Returns:
        property list (key and element pairs) as an input stream (may be 'null')
        See Also:
        getSettingsPath(), getSettingsUrl(), getStoredConfig()
      • getSettingsPath

        public String getSettingsPath()
        Get the path to a stored property declarations file.

        NOTE: The returned path can be absolute, relative, or a simple filename. See DEFAULT_LOCATION_STRATEGY for details of the strategy employed by the underlying file-based configuration API to locate the specified file.

        Returns:
        property file path (may be 'null')
        See Also:
        getSettingsUrl(), getInputStream(), getStoredConfig()
      • getDefaults

        protected Map<String,​String> getDefaults()
        Get defined system property default values
        NOTE: Default values are optional. Entries for properties without default values should be omitted.
        Returns:
        defined system property default values (may be 'null')
      • propagateIfNotMissingFile

        protected void propagateIfNotMissingFile​(org.apache.commons.configuration2.ex.ConfigurationException thrown)
        Propagate the specified configuration exception if it wasn't caused by a missing file.
        Parameters:
        thrown - configuration exception to be evaluated
      • injectProperties

        public static void injectProperties​(String propsFile)
        If a properties file is specified via a System property named propsFile or the [propsFile] argument, the settings in this file are injected into the System properties collection. Note that existing System properties override property file settings.

        NOTE: The strategy employed to locate the specified file is defined by DEFAULT_LOCATION_STRATEGY
        Parameters:
        propsFile - properties file name (may be 'null')