Class SettingsCore<T extends Enum<T> & SettingsCore.SettingsAPI>
- java.lang.Object
-
- org.apache.commons.configuration2.event.BaseEventSource
-
- org.apache.commons.configuration2.AbstractConfiguration
-
- org.apache.commons.configuration2.CompositeConfiguration
-
- com.nordstrom.automation.settings.SettingsCore<T>
-
- Type Parameters:
T- Implementations ofSettingsCoresupply a context-specific enumeration (which extendsEnum<T>) to provide the collection of settings needed in this context. This enumeration must implement theSettingsCore.SettingsAPIinterface 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.CompositeConfigurationThis class extendsCompositeConfiguration, using the facilities provided by this class to produce an aggregated configuration from three sources in the following order of precedence:- System properties
- (optional) Stored properties, typically from a properties file
- (optional) Default values, typically specified in the enumeration
getStoredConfig()- Your implementation returns a populatedConfigurationobject.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: Typical implementations overridegetSettingsPath(), which will support most scenarios.
NOTE: Stored properties are declared in Apache's extended syntax. SeePropertiesConfigurationfor details.
NOTE: By overriding thegetStoredConfig()method, you're able to incorporate any arbitraryConfigurationobject you need into your settings - including anotherCompositeConfigurationobject.
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.
getDefaults()with a method that simply returns 'null'.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSettingsCore.SettingsAPIThis 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 StringPROPS_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.InputStreamgetInputStream()Get stored property declarations as an input stream.
NOTE: Property values are typically stored in property files.StringgetSettingsPath()Get the path to a stored property declarations file.URLgetSettingsUrl()Get the URL for a stored property declarations file.org.apache.commons.configuration2.ConfigurationgetStoredConfig()Get stored property declarations as a configuration object.static voidinjectProperties(String propsFile)If a properties file is specified via a System property namedpropsFileor the [propsFile] argument, the settings in this file are injected into the System properties collection.protected voidpropagateIfNotMissingFile(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
-
-
-
-
Field Detail
-
PROPS_FILE
public static final String PROPS_FILE
- See Also:
- Constant Field Values
-
-
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
Configurationobject (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()
-
getSettingsUrl
public URL getSettingsUrl()
Get the URL for a stored property declarations file.- Returns:
- property file URL (may be 'null')
- See Also:
getSettingsPath(),getInputStream(),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_STRATEGYfor 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 namedpropsFileor 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 byDEFAULT_LOCATION_STRATEGY- Parameters:
propsFile- properties file name (may be 'null')
-
-