public class ConcurrentCompositeConfiguration extends ConcurrentMapConfiguration implements AggregatedConfiguration, org.apache.commons.configuration.event.ConfigurationListener, java.lang.Cloneable
getProperty(String) will return any properties defined by Configuration1.
Only if Configuration1 doesn't have the property, then
Configuration2 will be checked.
There are two internal configurations for properties that are programmatically set:
addProperty(String, Object) or setProperty(String, Object)
called directly on this class. This configuration will be called "container configuration" as it serves as the container of
such properties. By default, this configuration remains at the last of the configurations list. It can be treated as
a "base line" configuration that holds hard-coded parameters that can be overridden by any of other configurations added at runtime.
You can replace this configuration by your own and change the position of the configuration in the list by calling
setContainerConfiguration(AbstractConfiguration, String, int).
setOverrideProperty(String, Object)) to override values from any other
configurations on the list. As contrast to container configuration, this configuration is always consulted first in
getProperty(String).
ConcurrentMapConfiguration or ConcurrentCompositeConfiguration using
ConfigurationUtils to achieve
maximal performance and thread safety.
Example:
// configuration from local properties file
String fileName = "...";
ConcurrentMapConfiguration configFromPropertiesFile =
new ConcurrentMapConfiguration(new PropertiesConfiguration(fileName));
// configuration from system properties
ConcurrentMapConfiguration configFromSystemProperties =
new ConcurrentMapConfiguration(new SystemConfiguration());
// configuration from a dynamic source
PolledConfigurationSource source = createMyOwnSource();
AbstractPollingScheduler scheduler = createMyOwnScheduler();
DynamicConfiguration dynamicConfiguration =
new DynamicConfiguration(source, scheduler);
// create a hierarchy of configuration that makes
// 1) dynamic configuration source override system properties and,
// 2) system properties override properties file
ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
finalConfig.add(dynamicConfiguration, "dynamicConfig");
finalConfig.add(configFromSystemProperties, "systemConfig");
finalConfig.add(configFromPropertiesFile, "fileConfig");
// register with DynamicPropertyFactory so that finalConfig
// becomes the source of dynamic properties
DynamicPropertyFactory.initWithConfigurationSource(finalConfig);
| Modifier and Type | Field and Description |
|---|---|
static int |
EVENT_CONFIGURATION_SOURCE_CHANGED |
DISABLE_DELIMITER_PARSING, map| Constructor and Description |
|---|
ConcurrentCompositeConfiguration()
Creates an empty CompositeConfiguration object which can then
be added some other Configuration files
|
ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration)
Creates a ConcurrentCompositeConfiguration object with a specified container
configuration.
|
ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration,
java.util.Collection<? extends org.apache.commons.configuration.AbstractConfiguration> configurations)
Creates a ConcurrentCompositeConfiguration with a specified container
configuration, and then adds the given collection of configurations.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
Add a child configuration without a name.
|
void |
addConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name)
Adds a new child configuration to this configuration with an optional
name.
|
void |
addConfigurationAtFront(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name) |
void |
addConfigurationAtIndex(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name,
int index)
Add a configuration with a name at a particular index.
|
void |
addProperty(java.lang.String key,
java.lang.Object value)
Add the property with the container configuration.
|
void |
clear()
Removes all child configurations and reinitializes the container
configuration.
|
void |
clearOverrideProperty(java.lang.String key)
Remove the overriding property set by
setOverrideProperty(String, Object) |
void |
clearProperty(java.lang.String key)
Clear the property with the container configuration.
|
java.lang.Object |
clone()
Returns a copy of this object.
|
void |
configurationChanged(org.apache.commons.configuration.event.ConfigurationEvent event)
Event listener call back for configuration update events.
|
boolean |
containsKey(java.lang.String key)
Check if the any of the sub configurations contains the specified key.
|
org.apache.commons.configuration.Configuration |
getConfiguration(int index)
Return the configuration at the specified index.
|
org.apache.commons.configuration.Configuration |
getConfiguration(java.lang.String name)
Returns the configuration with the given name.
|
java.util.List<java.lang.String> |
getConfigurationNameList() |
java.util.Set<java.lang.String> |
getConfigurationNames()
Returns a set with the names of all configurations contained in this
configuration.
|
java.util.List<org.apache.commons.configuration.AbstractConfiguration> |
getConfigurations()
Get the configurations added.
|
org.apache.commons.configuration.Configuration |
getContainerConfiguration()
Returns the container configuration In this configuration
changes are stored.
|
int |
getIndexOfConfiguration(org.apache.commons.configuration.AbstractConfiguration config) |
int |
getIndexOfContainerConfiguration() |
java.util.Iterator<java.lang.String> |
getKeys()
Get all the keys contained by sub configurations.
|
java.util.Iterator<java.lang.String> |
getKeys(java.lang.String prefix)
Get the list of the keys contained in the sub configurations that match the
specified prefix.
|
java.util.List |
getList(java.lang.String key,
java.util.List defaultValue)
Get a List of objects associated with the given configuration key.
|
int |
getNumberOfConfigurations()
Return the number of configurations.
|
java.lang.Object |
getProperty(java.lang.String key)
Read property from underlying composite.
|
org.apache.commons.configuration.Configuration |
getSource(java.lang.String key)
Returns the configuration source, in which the specified key is defined.
|
java.lang.String[] |
getStringArray(java.lang.String key)
Get an array of strings associated with the given configuration key.
|
void |
invalidate() |
boolean |
isEmpty() |
boolean |
isPropagateEventFromSubConfigurations()
Return whether sub configurations should propagate events to
listeners to this configuration.
|
boolean |
removeConfiguration(org.apache.commons.configuration.Configuration config)
Remove a configuration.
|
org.apache.commons.configuration.Configuration |
removeConfiguration(java.lang.String name)
Removes the configuration with the specified name.
|
org.apache.commons.configuration.AbstractConfiguration |
removeConfigurationAt(int index) |
void |
setContainerConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name,
int index)
Adds a child configuration and makes it the container
configuration.
|
void |
setContainerConfigurationIndex(int newIndex)
Change the position of the container configuration to a new index.
|
void |
setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Sets a flag whether added values for string properties should be checked
for the list delimiter.
|
void |
setListDelimiter(char listDelimiter)
Sets the character that is used as list delimiter.
|
void |
setOverrideProperty(java.lang.String key,
java.lang.Object finalValue)
Override the same property in any other configurations in the list.
|
void |
setPropagateEventFromSubConfigurations(boolean propagateEventToParent)
Set whether sub configurations should propagate events to
listeners to this configuration.
|
void |
setProperty(java.lang.String key,
java.lang.Object value)
Set the property with the container configuration.
|
addConfigurationListener, addErrorListener, addPropertyDirect, addPropertyImpl, clearConfigurationListeners, clearErrorListeners, clearPropertyDirect, copy, fireError, fireEvent, getConfigurationListeners, getErrorListeners, getProperties, loadProperties, removeConfigurationListener, removeErrorListener, setPropertyImpladdErrorLogListener, append, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getSubstitutor, interpolate, interpolate, interpolatedConfiguration, interpolateHelper, isDelimiterParsingDisabled, isScalarValue, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setLogger, setThrowExceptionOnMissing, subsetcreateErrorEvent, createEvent, isDetailEvents, setDetailEventsequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, subsetpublic static final int EVENT_CONFIGURATION_SOURCE_CHANGED
public ConcurrentCompositeConfiguration()
public ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration)
setProperty(String, Object)
and addProperty(String, Object).containerConfiguration - the configuration to use as container configurationpublic ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration,
java.util.Collection<? extends org.apache.commons.configuration.AbstractConfiguration> configurations)
containerConfiguration - container configuration to useconfigurations - the collection of configurations to addpublic void configurationChanged(org.apache.commons.configuration.event.ConfigurationEvent event)
configurationChanged in interface org.apache.commons.configuration.event.ConfigurationListenerevent - the update eventpublic void invalidate()
public final void addConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
addConfiguration(AbstractConfiguration, String)
with the name being null.addConfiguration in interface AggregatedConfigurationconfig - the configuration to addpublic void addConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name)
addConfiguration in interface AggregatedConfigurationconfig - the configuration to add (must not be null)name - the name of this configuration (can be null)public java.util.List<org.apache.commons.configuration.AbstractConfiguration> getConfigurations()
getConfigurations in interface AggregatedConfigurationpublic java.util.List<java.lang.String> getConfigurationNameList()
getConfigurationNameList in interface AggregatedConfigurationpublic int getIndexOfConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
public int getIndexOfContainerConfiguration()
public void setContainerConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name,
int index)
throws java.lang.IndexOutOfBoundsException
config - the configuration to be addedname - the name of the configuration to be addedindex - index to add this configurationjava.lang.IndexOutOfBoundsExceptionpublic void setContainerConfigurationIndex(int newIndex)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic void addConfigurationAtIndex(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name,
int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsExceptionpublic void addConfigurationAtFront(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name)
public boolean removeConfiguration(org.apache.commons.configuration.Configuration config)
removeConfiguration in interface AggregatedConfigurationconfig - The configuration to removepublic org.apache.commons.configuration.AbstractConfiguration removeConfigurationAt(int index)
removeConfigurationAt in interface AggregatedConfigurationpublic org.apache.commons.configuration.Configuration removeConfiguration(java.lang.String name)
removeConfiguration in interface AggregatedConfigurationname - the name of the configuration to be removedpublic int getNumberOfConfigurations()
getNumberOfConfigurations in interface AggregatedConfigurationpublic final void clear()
clear in interface org.apache.commons.configuration.Configurationclear in class ConcurrentMapConfigurationpublic void setOverrideProperty(java.lang.String key,
java.lang.Object finalValue)
public void clearOverrideProperty(java.lang.String key)
setOverrideProperty(String, Object)public void setProperty(java.lang.String key,
java.lang.Object value)
getProperty(String) on this key may not return the same value set by this method
if there is any other configuration that contain the same property and is in front of the
container configuration in the configurations list.setProperty in interface org.apache.commons.configuration.ConfigurationsetProperty in class ConcurrentMapConfigurationpublic void addProperty(java.lang.String key,
java.lang.Object value)
getProperty(String) on this key may not return the same value set by this method
if there is any other configuration that contain the same property and is in front of the
container configuration in the configurations list.addProperty in interface org.apache.commons.configuration.ConfigurationaddProperty in class ConcurrentMapConfigurationpublic void clearProperty(java.lang.String key)
getProperty(String) on this key may still return some value
if there is any other configuration that contain the same property and is in front of the
container configuration in the configurations list.clearProperty in interface org.apache.commons.configuration.ConfigurationclearProperty in class org.apache.commons.configuration.AbstractConfigurationpublic java.lang.Object getProperty(java.lang.String key)
setOverrideProperty(String, Object) and if so return the overriding value.
Otherwise, it iterates through the list of sub configurations until it finds one that contains the
property and return the value from that sub configuration. It returns null of the property does
not exist.getProperty in interface org.apache.commons.configuration.ConfigurationgetProperty in class ConcurrentMapConfigurationkey - key to use for mappingpublic java.util.Iterator<java.lang.String> getKeys()
throws java.util.ConcurrentModificationException
getKeys in interface org.apache.commons.configuration.ConfigurationgetKeys in class ConcurrentMapConfigurationjava.util.ConcurrentModificationException - if concurrent modification happens on any sub configuration
when it is iterated to get all the keyspublic java.util.Iterator<java.lang.String> getKeys(java.lang.String prefix)
getKeys in interface org.apache.commons.configuration.ConfigurationgetKeys in class org.apache.commons.configuration.AbstractConfigurationpublic java.util.Set<java.lang.String> getConfigurationNames()
getConfigurationNames in interface AggregatedConfigurationpublic boolean isEmpty()
isEmpty in interface org.apache.commons.configuration.ConfigurationisEmpty in class ConcurrentMapConfigurationpublic boolean containsKey(java.lang.String key)
containsKey in interface org.apache.commons.configuration.ConfigurationcontainsKey in class ConcurrentMapConfigurationkey - the key whose presence in this configuration is to be testedtrue if the configuration contains a value for this
key, false otherwisepublic java.util.List getList(java.lang.String key,
java.util.List defaultValue)
getList in interface org.apache.commons.configuration.ConfigurationgetList in class org.apache.commons.configuration.AbstractConfigurationkey - The configuration key.defaultValue - The default value.public java.lang.String[] getStringArray(java.lang.String key)
getStringArray in interface org.apache.commons.configuration.ConfigurationgetStringArray in class org.apache.commons.configuration.AbstractConfigurationkey - The configuration key.public org.apache.commons.configuration.Configuration getConfiguration(int index)
getConfiguration in interface AggregatedConfigurationindex - The index of the configuration to retrievepublic org.apache.commons.configuration.Configuration getConfiguration(java.lang.String name)
getConfiguration in interface AggregatedConfigurationname - the name of the configurationpublic org.apache.commons.configuration.Configuration getContainerConfiguration()
public java.lang.Object clone()
clone in class org.apache.commons.configuration.event.EventSourcepublic void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
setDelimiterParsingDisabled in class org.apache.commons.configuration.AbstractConfigurationdelimiterParsingDisabled - the new value of the flagpublic void setListDelimiter(char listDelimiter)
setListDelimiter in class org.apache.commons.configuration.AbstractConfigurationlistDelimiter - the new list delimiter characterpublic org.apache.commons.configuration.Configuration getSource(java.lang.String key)
key - the key to be checkedpublic final boolean isPropagateEventFromSubConfigurations()
public final void setPropagateEventFromSubConfigurations(boolean propagateEventToParent)
DynamicPropertyFactory.propagateEventToParent - value to set