public class DynamicCombinedConfiguration extends CombinedConfiguration
DynamicCombinedConfiguration allows a set of CombinedConfigurations to be used.
Each CombinedConfiguration is referenced by a key that is dynamically constructed from a key pattern on each call. The key pattern will be resolved using the configured ConfigurationInterpolator.
This Configuration implementation uses the configured Synchronizer
to
guard itself against concurrent access. If there are multiple threads
accessing an instance concurrently, a fully functional Synchronizer
implementation (e.g. ReadWriteSynchronizer
) has to be used to ensure
consistency and to avoid exceptions. The Synchronizer
assigned to an
instance is also passed to child configuration objects when they are created.
BaseHierarchicalConfiguration.BuilderVisitor
COMBINED_INVALIDATE
Constructor and Description |
---|
DynamicCombinedConfiguration()
Creates a new instance of
DynamicCombinedConfiguration that uses
a union combiner. |
DynamicCombinedConfiguration(NodeCombiner comb)
Creates a new instance of
DynamicCombinedConfiguration and
initializes the combiner to be used. |
Modifier and Type | Method and Description |
---|---|
void |
addConfiguration(Configuration config,
String name,
String at)
Adds a new configuration to this combined configuration.
|
<T extends Event> |
addEventListener(EventType<T> eventType,
EventListener<? super T> listener)
Adds an event listener for the specified event type.
|
protected void |
addNodesInternal(String key,
Collection<? extends ImmutableNode> nodes)
Actually adds a collection of new nodes to this configuration.
|
protected void |
addPropertyInternal(String key,
Object value)
Adds the property with the specified key.
|
protected void |
beginRead(boolean optimize)
Notifies this configuration's
Synchronizer that a read operation
is about to start. |
protected void |
beginWrite(boolean optimize)
Notifies this configuration's
Synchronizer that an update
operation is about to start. |
void |
clearErrorListeners()
Removes all registered error listeners.
|
void |
clearEventListeners()
Removes all registered event listeners.
|
protected void |
clearInternal()
Clears this configuration.
|
protected void |
clearPropertyDirect(String key)
Removes the property with the given key.
|
protected Object |
clearTreeInternal(String key)
Actually clears the tree of elements referenced by the given key.
|
Object |
clone()
Returns a copy of this object.
|
HierarchicalConfiguration<ImmutableNode> |
configurationAt(String key)
Returns a hierarchical subnode configuration for the node specified by
the given key.
|
HierarchicalConfiguration<ImmutableNode> |
configurationAt(String key,
boolean supportUpdates)
Returns a hierarchical sub configuration object that wraps the
configuration node specified by the given key.
|
List<HierarchicalConfiguration<ImmutableNode>> |
configurationsAt(String key)
Returns a list of sub configurations for all configuration nodes selected
by the given key.
|
protected boolean |
containsKeyInternal(String key)
Checks if the specified key is contained in this configuration.
|
protected void |
endRead()
Notifies this configuration's
Synchronizer that a read operation
has finished. |
protected void |
endWrite()
Notifies this configuration's
Synchronizer that an update
operation has finished. |
BigDecimal |
getBigDecimal(String key)
Get a
BigDecimal associated with the given configuration key. |
BigDecimal |
getBigDecimal(String key,
BigDecimal defaultValue)
Get a
BigDecimal associated with the given configuration key. |
BigInteger |
getBigInteger(String key)
Get a
BigInteger associated with the given configuration key. |
BigInteger |
getBigInteger(String key,
BigInteger defaultValue)
Get a
BigInteger associated with the given configuration key. |
boolean |
getBoolean(String key)
Get a boolean associated with the given configuration key.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Get a boolean associated with the given configuration key.
|
Boolean |
getBoolean(String key,
Boolean defaultValue)
Obtains the value of the specified key and tries to convert it into a
Boolean object. |
byte |
getByte(String key)
Get a byte associated with the given configuration key.
|
byte |
getByte(String key,
byte defaultValue)
Get a byte associated with the given configuration key.
|
Byte |
getByte(String key,
Byte defaultValue)
Get a
Byte associated with the given configuration key. |
Configuration |
getConfiguration(int index)
Returns the configuration at the specified index.
|
Configuration |
getConfiguration(String name)
Returns the configuration with the given name.
|
Set<String> |
getConfigurationNames()
Returns a set with the names of all configurations contained in this
combined configuration.
|
double |
getDouble(String key)
Get a double associated with the given configuration key.
|
double |
getDouble(String key,
double defaultValue)
Get a double associated with the given configuration key.
|
Double |
getDouble(String key,
Double defaultValue)
Get a
Double associated with the given configuration key. |
ExpressionEngine |
getExpressionEngine()
Returns the expression engine used by this configuration.
|
float |
getFloat(String key)
Get a float associated with the given configuration key.
|
float |
getFloat(String key,
float defaultValue)
Get a float associated with the given configuration key.
|
Float |
getFloat(String key,
Float defaultValue)
Get a
Float associated with the given configuration key. |
int |
getInt(String key)
Get a int associated with the given configuration key.
|
int |
getInt(String key,
int defaultValue)
Get a int associated with the given configuration key.
|
Integer |
getInteger(String key,
Integer defaultValue)
Get an
Integer associated with the given configuration key. |
String |
getKeyPattern() |
protected Iterator<String> |
getKeysInternal()
Returns an iterator with all keys defined in this configuration.
|
protected Iterator<String> |
getKeysInternal(String prefix)
Returns an iterator with all keys defined in this configuration that
start with the given prefix.
|
List<Object> |
getList(String key)
Get a List of the values associated with the given configuration key.
|
List<Object> |
getList(String key,
List<?> defaultValue)
Get a List of strings associated with the given configuration key.
|
long |
getLong(String key)
Get a long associated with the given configuration key.
|
long |
getLong(String key,
long defaultValue)
Get a long associated with the given configuration key.
|
Long |
getLong(String key,
Long defaultValue)
Get a
Long associated with the given configuration key. |
protected int |
getMaxIndexInternal(String key)
Actually retrieves the maximum defined index for the given key.
|
NodeCombiner |
getNodeCombiner()
Returns the node combiner that is used for creating the combined node
structure.
|
int |
getNumberOfConfigurations()
Returns the number of configurations that are contained in this combined
configuration.
|
Properties |
getProperties(String key)
Get a list of properties associated with the given configuration key.
|
protected Object |
getPropertyInternal(String key)
Fetches the specified property.
|
short |
getShort(String key)
Get a short associated with the given configuration key.
|
short |
getShort(String key,
short defaultValue)
Get a short associated with the given configuration key.
|
Short |
getShort(String key,
Short defaultValue)
Get a
Short associated with the given configuration key. |
Configuration |
getSource(String key)
Returns the configuration source, in which the specified key is defined.
|
String |
getString(String key)
Get a string associated with the given configuration key.
|
String |
getString(String key,
String defaultValue)
Get a string associated with the given configuration key.
|
String[] |
getStringArray(String key)
Get an array of strings associated with the given configuration key.
|
Configuration |
interpolatedConfiguration()
Returns a configuration with the same content as this configuration, but
with all variables replaced by their actual values.
|
void |
invalidate()
Invalidates the current combined configuration.
|
void |
invalidateAll() |
protected boolean |
isEmptyInternal()
Checks if this configuration is empty.
|
boolean |
removeConfiguration(Configuration config)
Removes the specified configuration from this combined configuration.
|
Configuration |
removeConfiguration(String name)
Removes the configuration with the specified name.
|
Configuration |
removeConfigurationAt(int index)
Removes the configuration at the specified index.
|
<T extends Event> |
removeEventListener(EventType<T> eventType,
EventListener<? super T> listener)
Removes the event listener registration for the given event type and
listener.
|
void |
setExpressionEngine(ExpressionEngine expressionEngine)
Sets the expression engine to be used by this configuration.
|
void |
setKeyPattern(String pattern) |
void |
setLoggerName(String name)
Set the name of the Logger to use on each CombinedConfiguration.
|
void |
setNodeCombiner(NodeCombiner nodeCombiner)
Sets the node combiner.
|
protected void |
setPropertyInternal(String key,
Object value)
Sets the value of the specified property.
|
protected int |
sizeInternal()
Actually calculates the size of this configuration.
|
Configuration |
subset(String prefix)
Creates a new
Configuration object containing all keys
that start with the specified prefix. |
addConfiguration, addConfiguration, getConfigurationNameList, getConfigurations, getConversionExpressionEngine, getSources, onEvent, setConversionExpressionEngine
childConfigurationsAt, childConfigurationsAt, cloneNodeModel, configurationsAt, createSubConfigurationForTrackedNode, getNodeModel, getSubConfigurationNodeSelector, getSubConfigurationParentModel, immutableChildConfigurationsAt, immutableConfigurationAt, immutableConfigurationAt, immutableConfigurationsAt, initSubConfigurationForThisParent, subnodeConfigurationChanged
addNodes, addPropertyDirect, clearTree, fetchNodeList, getMaxIndex, getModel, getRootElementName, getRootElementNameInternal, nodeDefined, nodeKey, resolveAddKey, resolveKey, resolveNodeKey, resolveUpdateKey, toString
addErrorLogListener, addProperty, append, clear, clearProperty, cloneInterpolator, containsKey, copy, get, get, getArray, getArray, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getEncodedString, getEncodedString, getInterpolator, getKeys, getKeys, getList, getList, getListDelimiterHandler, getLogger, getProperties, getProperty, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setSynchronizer, setThrowExceptionOnMissing, size, unlock
copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, setDetailEvents
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty
getSynchronizer, lock, setSynchronizer, unlock
containsKey, get, get, getArray, getArray, getCollection, getCollection, getEncodedString, getEncodedString, getKeys, getKeys, getList, getList, getProperty, immutableSubset, isEmpty, size
public DynamicCombinedConfiguration(NodeCombiner comb)
DynamicCombinedConfiguration
and
initializes the combiner to be used.comb
- the node combiner (can be null, then a union combiner
is used as default)public DynamicCombinedConfiguration()
DynamicCombinedConfiguration
that uses
a union combiner.UnionCombiner
public void setKeyPattern(String pattern)
public String getKeyPattern()
public void setLoggerName(String name)
name
- The Logger name.public NodeCombiner getNodeCombiner()
getNodeCombiner
in class CombinedConfiguration
public void setNodeCombiner(NodeCombiner nodeCombiner)
IllegalArgumentException
exception is thrown. Changing the
node combiner causes an invalidation of this combined configuration, so
that the new combiner immediately takes effect.setNodeCombiner
in class CombinedConfiguration
nodeCombiner
- the node combinerpublic void addConfiguration(Configuration config, String name, String at)
ConfigurationRuntimeException
will
be thrown. With the optional at
argument you can specify
where in the resulting node structure the content of the added
configuration should appear. This is a string that uses dots as property
delimiters (independent on the current expression engine). For instance
if you pass in the string "database.tables"
,
all properties of the added configuration will occur in this branch.addConfiguration
in class CombinedConfiguration
config
- the configuration to add (must not be null)name
- the name of this configuration (can be null)at
- the position of this configuration in the combined tree (can be
null)public int getNumberOfConfigurations()
getNumberOfConfigurations
in class CombinedConfiguration
public Configuration getConfiguration(int index)
getConfiguration
in class CombinedConfiguration
index
- the indexpublic Configuration getConfiguration(String name)
getConfiguration
in class CombinedConfiguration
name
- the name of the configurationpublic Set<String> getConfigurationNames()
getConfigurationNames
in class CombinedConfiguration
public Configuration removeConfiguration(String name)
removeConfiguration
in class CombinedConfiguration
name
- the name of the configuration to be removedpublic boolean removeConfiguration(Configuration config)
removeConfiguration
in class CombinedConfiguration
config
- the configuration to be removedpublic Configuration removeConfigurationAt(int index)
removeConfigurationAt
in class CombinedConfiguration
index
- the indexprotected void addPropertyInternal(String key, Object value)
AbstractHierarchicalConfiguration
ExpressionEngine
, so the passed in key
must match the requirements of this implementation.addPropertyInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key of the new propertyvalue
- the value of the new propertyprotected void clearInternal()
CombinedConfiguration
clearInternal
in class CombinedConfiguration
protected void clearPropertyDirect(String key)
AbstractHierarchicalConfiguration
clearPropertyDirect
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key of the property to be removedprotected boolean containsKeyInternal(String key)
AbstractHierarchicalConfiguration
containsKeyInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key to be checkedpublic BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
ImmutableConfiguration
BigDecimal
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.getBigDecimal
in interface ImmutableConfiguration
getBigDecimal
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public BigDecimal getBigDecimal(String key)
AbstractConfiguration
BigDecimal
associated with the given configuration key.getBigDecimal
in interface ImmutableConfiguration
getBigDecimal
in class AbstractConfiguration
key
- The configuration key.AbstractConfiguration.setThrowExceptionOnMissing(boolean)
public BigInteger getBigInteger(String key, BigInteger defaultValue)
ImmutableConfiguration
BigInteger
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.getBigInteger
in interface ImmutableConfiguration
getBigInteger
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public BigInteger getBigInteger(String key)
AbstractConfiguration
BigInteger
associated with the given configuration key.getBigInteger
in interface ImmutableConfiguration
getBigInteger
in class AbstractConfiguration
key
- The configuration key.AbstractConfiguration.setThrowExceptionOnMissing(boolean)
public boolean getBoolean(String key, boolean defaultValue)
ImmutableConfiguration
getBoolean
in interface ImmutableConfiguration
getBoolean
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public Boolean getBoolean(String key, Boolean defaultValue)
AbstractConfiguration
Boolean
object. If the property has no value, the passed
in default value will be used.getBoolean
in interface ImmutableConfiguration
getBoolean
in class AbstractConfiguration
key
- the key of the propertydefaultValue
- the default valueBoolean
public boolean getBoolean(String key)
ImmutableConfiguration
getBoolean
in interface ImmutableConfiguration
getBoolean
in class AbstractConfiguration
key
- The configuration key.public byte getByte(String key, byte defaultValue)
ImmutableConfiguration
getByte
in interface ImmutableConfiguration
getByte
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public Byte getByte(String key, Byte defaultValue)
ImmutableConfiguration
Byte
associated with the given configuration key.getByte
in interface ImmutableConfiguration
getByte
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public byte getByte(String key)
ImmutableConfiguration
getByte
in interface ImmutableConfiguration
getByte
in class AbstractConfiguration
key
- The configuration key.public double getDouble(String key, double defaultValue)
ImmutableConfiguration
getDouble
in interface ImmutableConfiguration
getDouble
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public Double getDouble(String key, Double defaultValue)
ImmutableConfiguration
Double
associated with the given configuration key.getDouble
in interface ImmutableConfiguration
getDouble
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public double getDouble(String key)
ImmutableConfiguration
getDouble
in interface ImmutableConfiguration
getDouble
in class AbstractConfiguration
key
- The configuration key.public float getFloat(String key, float defaultValue)
ImmutableConfiguration
getFloat
in interface ImmutableConfiguration
getFloat
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public Float getFloat(String key, Float defaultValue)
ImmutableConfiguration
Float
associated with the given configuration key. If the key doesn't
map to an existing object, the default value is returned.getFloat
in interface ImmutableConfiguration
getFloat
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public float getFloat(String key)
ImmutableConfiguration
getFloat
in interface ImmutableConfiguration
getFloat
in class AbstractConfiguration
key
- The configuration key.public int getInt(String key, int defaultValue)
ImmutableConfiguration
getInt
in interface ImmutableConfiguration
getInt
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public int getInt(String key)
ImmutableConfiguration
getInt
in interface ImmutableConfiguration
getInt
in class AbstractConfiguration
key
- The configuration key.public Integer getInteger(String key, Integer defaultValue)
ImmutableConfiguration
Integer
associated with the given configuration key. If the key
doesn't map to an existing object, the default value is returned.getInteger
in interface ImmutableConfiguration
getInteger
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.protected Iterator<String> getKeysInternal()
AbstractHierarchicalConfiguration
getKeysInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
protected Iterator<String> getKeysInternal(String prefix)
AbstractHierarchicalConfiguration
getKeysInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
prefix
- the prefix of the keys to start withpublic List<Object> getList(String key, List<?> defaultValue)
ImmutableConfiguration
getList
in interface ImmutableConfiguration
getList
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.ImmutableConfiguration.getList(Class, String, List)
public List<Object> getList(String key)
AbstractConfiguration
getList()
method in
that it does not recursively obtain all values stored for the specified
property key. Rather, only the first level of the hierarchy is processed.
So the resulting list may contain complex objects like arrays or
collections - depending on the storage structure used by a concrete
subclass. If the key doesn't map to an existing object, an empty List is
returned.getList
in interface ImmutableConfiguration
getList
in class AbstractConfiguration
key
- The configuration key.AbstractConfiguration.getStringArray(String)
public long getLong(String key, long defaultValue)
ImmutableConfiguration
getLong
in interface ImmutableConfiguration
getLong
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public Long getLong(String key, Long defaultValue)
ImmutableConfiguration
Long
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.getLong
in interface ImmutableConfiguration
getLong
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public long getLong(String key)
ImmutableConfiguration
getLong
in interface ImmutableConfiguration
getLong
in class AbstractConfiguration
key
- The configuration key.public Properties getProperties(String key)
ImmutableConfiguration
key=value
. These strings are split at the equals sign, and
the key parts will become keys of the returned Properties
object, the value
parts become values.getProperties
in interface ImmutableConfiguration
getProperties
in class AbstractConfiguration
key
- The configuration key.protected Object getPropertyInternal(String key)
AbstractHierarchicalConfiguration
getPropertyInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key to be looked uppublic short getShort(String key, short defaultValue)
ImmutableConfiguration
getShort
in interface ImmutableConfiguration
getShort
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public Short getShort(String key, Short defaultValue)
ImmutableConfiguration
Short
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.getShort
in interface ImmutableConfiguration
getShort
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public short getShort(String key)
ImmutableConfiguration
getShort
in interface ImmutableConfiguration
getShort
in class AbstractConfiguration
key
- The configuration key.public String getString(String key, String defaultValue)
ImmutableConfiguration
getString
in interface ImmutableConfiguration
getString
in class AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public String getString(String key)
AbstractConfiguration
getString
in interface ImmutableConfiguration
getString
in class AbstractConfiguration
key
- The configuration key.AbstractConfiguration.setThrowExceptionOnMissing(boolean)
public String[] getStringArray(String key)
AbstractConfiguration
ListDelimiterHandler
is
consulted to find out whether the string can be split into multiple
values.getStringArray
in interface ImmutableConfiguration
getStringArray
in class AbstractConfiguration
key
- The configuration key.AbstractConfiguration.setListDelimiterHandler(ListDelimiterHandler)
protected boolean isEmptyInternal()
AbstractHierarchicalConfiguration
isEmptyInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
protected int sizeInternal()
AbstractHierarchicalConfiguration
size()
with a read lock held. The base implementation provided
here calculates the size based on the iterator returned by
getKeys()
. Sub classes which can determine the size in a more
efficient way should override this method. This implementation is slightly more efficient than the
default implementation. It does not iterate over the key set, but
directly queries its size after it has been constructed. Note that
constructing the key set is still an O(n) operation.sizeInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
protected void setPropertyInternal(String key, Object value)
AbstractHierarchicalConfiguration
setPropertyInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key of the property to setvalue
- the new value of this propertypublic Configuration subset(String prefix)
BaseHierarchicalConfiguration
Configuration
object containing all keys
that start with the specified prefix. This implementation will return a
BaseHierarchicalConfiguration
object so that the structure of
the keys will be saved. The nodes selected by the prefix (it is possible
that multiple nodes are selected) are mapped to the root node of the
returned configuration, i.e. their children and attributes will become
children and attributes of the new root node. However, a value of the root
node is only set if exactly one of the selected nodes contain a value (if
multiple nodes have a value, there is simply no way to decide how these
values are merged together). Note that the returned
Configuration
object is not connected to its source
configuration: updates on the source configuration are not reflected in
the subset and vice versa. The returned configuration uses the same
Synchronizer
as this configuration.subset
in interface Configuration
subset
in class BaseHierarchicalConfiguration
prefix
- the prefix of the keys for the subsetSubsetConfiguration
public ExpressionEngine getExpressionEngine()
AbstractHierarchicalConfiguration
getExpressionEngine
in interface ImmutableHierarchicalConfiguration
getExpressionEngine
in class AbstractHierarchicalConfiguration<ImmutableNode>
public void setExpressionEngine(ExpressionEngine expressionEngine)
AbstractHierarchicalConfiguration
setExpressionEngine
in interface HierarchicalConfiguration<ImmutableNode>
setExpressionEngine
in class AbstractHierarchicalConfiguration<ImmutableNode>
expressionEngine
- the new expression engine; can be null,
then the default expression engine will be usedprotected void addNodesInternal(String key, Collection<? extends ImmutableNode> nodes)
AbstractHierarchicalConfiguration
addNodes()
. It can be overridden by
subclasses that need to adapt this operation.addNodesInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key where the nodes are to be added; can be null,
then they are added to the root nodenodes
- a collection with the Node
objects to be addedpublic HierarchicalConfiguration<ImmutableNode> configurationAt(String key, boolean supportUpdates)
BaseHierarchicalConfiguration
Returns a hierarchical sub configuration object that wraps the
configuration node specified by the given key. This method provides an
easy means of accessing sub trees of a hierarchical configuration. In the
returned configuration the sub tree can directly be accessed, it becomes
the root node of this configuration. Because of this the passed in key
must select exactly one configuration node; otherwise an
IllegalArgumentException
will be thrown.
The difference between this method and the
Configuration.subset(String)
method is that
subset()
supports arbitrary subsets of configuration nodes
while configurationAt()
only returns a single sub tree.
Please refer to the documentation of the
SubnodeConfiguration
class to obtain further information
about sub configurations and when they should be used.
With the supportUpdate
flag the behavior of the returned
sub configuration regarding updates of its parent
configuration can be determined. If set to false, the configurations
return on independent nodes structures. So changes made on one configuration
cannot be seen by the other one. A value of true in contrast creates
a direct connection between both configurations - they are then using the
same underlying data structures as much as possible. There are however changes
which break this connection; for instance, if the sub tree the sub configuration
belongs to is completely removed from the parent configuration. If such a
change happens, the sub configuration becomes detached from its parent.
It can still be used in a normal way, but changes on it are not reflected
by the parent and vice verse. Also, it is not possible to reattach a once
detached sub configuration.
supportUpdates
flag: If it is false, a plain
BaseHierarchicalConfiguration
is returned using the selected node
as root node. This is suitable for read-only access to properties.
Because the configuration returned in this case is not connected to the
parent configuration, updates on properties made by one configuration are
not reflected by the other one. A value of true for this parameter
causes a tracked node to be created, and result is a
SubnodeConfiguration
based on this tracked node. This
configuration is really connected to its parent, so that updated
properties are visible on both.configurationAt
in interface HierarchicalConfiguration<ImmutableNode>
configurationAt
in class BaseHierarchicalConfiguration
key
- the key that selects the sub treesupportUpdates
- a flag whether the returned sub configuration
should be directly connected to its parentSubnodeConfiguration
public HierarchicalConfiguration<ImmutableNode> configurationAt(String key)
BaseHierarchicalConfiguration
configurationAt(key,
<b>false</b>)
. This is a short form for configurationAt(key,
<b>false</b>)
.configurationAt
in interface HierarchicalConfiguration<ImmutableNode>
configurationAt
in class BaseHierarchicalConfiguration
key
- the key that selects the sub treeSubnodeConfiguration
public List<HierarchicalConfiguration<ImmutableNode>> configurationsAt(String key)
BaseHierarchicalConfiguration
ExpressionEngine
) and then create a sub configuration for
each returned node (like HierarchicalConfiguration.configurationAt(String)
). This is
especially useful when dealing with list-like structures. As an example
consider the configuration that contains data about database tables and
their fields. If you need access to all fields of a certain table, you
can simply do
List fields = config.configurationsAt("tables.table(0).fields.field"); for(Iterator it = fields.iterator(); it.hasNext();) { BaseHierarchicalConfiguration sub = (BaseHierarchicalConfiguration) it.next(); // now the children and attributes of the field node can be // directly accessed String fieldName = sub.getString("name"); String fieldType = sub.getString("type"); ...The configuration objects returned are not connected to the parent configuration. This implementation creates sub configurations in the same way as described for
BaseHierarchicalConfiguration.configurationAt(String)
.configurationsAt
in interface HierarchicalConfiguration<ImmutableNode>
configurationsAt
in class BaseHierarchicalConfiguration
key
- the key for selecting the desired nodesprotected Object clearTreeInternal(String key)
AbstractHierarchicalConfiguration
clearTree()
. Subclasses that need to adapt
this operation can override this method. This base implementation
delegates to the node model.clearTreeInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key of the property to be removedprotected int getMaxIndexInternal(String key)
AbstractHierarchicalConfiguration
getMaxIndex()
. Subclasses that need to adapt
this operation have to override this method.getMaxIndexInternal
in class AbstractHierarchicalConfiguration<ImmutableNode>
key
- the key to be checkedpublic Configuration interpolatedConfiguration()
BaseHierarchicalConfiguration
interpolatedConfiguration
in class BaseHierarchicalConfiguration
public Configuration getSource(String key)
IllegalArgumentException
is
thrown (in this case no unique source can be determined).getSource
in class CombinedConfiguration
key
- the key of a configuration propertyIllegalArgumentException
- if the key maps to multiple properties
and the source cannot be determined, or if the key is nullpublic void clearEventListeners()
BaseEventSource
clearEventListeners
in class BaseEventSource
public <T extends Event> void addEventListener(EventType<T> eventType, EventListener<? super T> listener)
EventSource
addEventListener
in interface EventSource
addEventListener
in class BaseEventSource
T
- the type of events processed by this listenereventType
- the event type (must not be null)listener
- the listener to be registered (must not be null)public <T extends Event> boolean removeEventListener(EventType<T> eventType, EventListener<? super T> listener)
EventSource
removeEventListener
in interface EventSource
removeEventListener
in class BaseEventSource
T
- the type of events processed by this listenereventType
- the event typelistener
- the event listener to be removedpublic void clearErrorListeners()
BaseEventSource
clearErrorListeners
in class BaseEventSource
public Object clone()
clone
in class CombinedConfiguration
public void invalidate()
EVENT_COMBINED_INVALIDATE
is fired. Note that while other
events most times appear twice (once before and once after an update),
this event is only fired once (after update).invalidate
in class CombinedConfiguration
public void invalidateAll()
protected void beginRead(boolean optimize)
Synchronizer
that a read operation
is about to start. This method is called by all methods which access this
configuration in a read-only mode. Subclasses may override it to perform
additional actions before this read operation. The boolean
optimize argument can be evaluated by overridden methods in
derived classes. Some operations which require a lock do not need a fully
initialized configuration object. By setting this flag to
true, such operations can give a corresponding hint. An
overridden implementation of beginRead()
can then decide to skip
some initialization steps. All basic operations in this class (and most
of the basic Configuration
implementations) call this method with
a parameter value of false. In any case the
inherited method must be called! Otherwise, proper synchronization is not
guaranteed. This implementation checks whether a combined root node
is available. If not, it is constructed by requesting a write lock. This implementation ensures that the current configuration
is initialized. The lock counter is increased.beginRead
in class CombinedConfiguration
optimize
- a flag whether optimization can be performedprotected void beginWrite(boolean optimize)
Synchronizer
that an update
operation is about to start. This method is called by all methods which
modify this configuration. Subclasses may override it to perform
additional operations before an update. For a description of the boolean
optimize argument refer to the documentation of
beginRead()
. In any case the inherited method must be
called! Otherwise, proper synchronization is not guaranteed. This implementation checks whether a combined root node
is available. If not, it is constructed now. This implementation ensures that the current configuration
is initialized. If necessary, a new child configuration instance is
created.beginWrite
in class CombinedConfiguration
optimize
- a flag whether optimization can be performedAbstractConfiguration.beginRead(boolean)
protected void endRead()
Synchronizer
that a read operation
has finished. This method is called by all methods which access this
configuration in a read-only manner at the end of their execution.
Subclasses may override it to perform additional actions after this read
operation. In any case the inherited method must be called!
Otherwise, the read lock will not be released. This implementation clears the current configuration if
necessary.endRead
in class AbstractConfiguration
protected void endWrite()
Synchronizer
that an update
operation has finished. This method is called by all methods which modify
this configuration at the end of their execution. Subclasses may override
it to perform additional operations after an update. In any case
the inherited method must be called! Otherwise, the write lock will not
be released. This implementation clears the current configuration if
necessary.endWrite
in class AbstractConfiguration
Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.