public class BaseHierarchicalConfiguration extends AbstractHierarchicalConfiguration<ImmutableNode> implements InMemoryNodeModelSupport
A specialized hierarchical configuration implementation that is based on a
structure of ImmutableNode
objects.
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseHierarchicalConfiguration.BuilderVisitor
A specialized visitor base class that can be used for storing the tree of
configuration nodes.
|
Modifier | Constructor and Description |
---|---|
|
BaseHierarchicalConfiguration()
Creates a new instance of
BaseHierarchicalConfiguration . |
|
BaseHierarchicalConfiguration(HierarchicalConfiguration<ImmutableNode> c)
Creates a new instance of
BaseHierarchicalConfiguration and
copies all data contained in the specified configuration into the new
one. |
protected |
BaseHierarchicalConfiguration(NodeModel<ImmutableNode> model)
Creates a new instance of
BaseHierarchicalConfiguration and
initializes it with the given NodeModel . |
Modifier and Type | Method and Description |
---|---|
List<HierarchicalConfiguration<ImmutableNode>> |
childConfigurationsAt(String key)
Returns a list with sub configurations for all child nodes of the node
selected by the given key.
|
List<HierarchicalConfiguration<ImmutableNode>> |
childConfigurationsAt(String key,
boolean supportUpdates)
Returns a list with sub configurations for all child nodes of the node
selected by the given key allowing the caller to specify the
supportUpdates flag. |
protected NodeModel<ImmutableNode> |
cloneNodeModel()
Creates a clone of the node model.
|
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.
|
List<HierarchicalConfiguration<ImmutableNode>> |
configurationsAt(String key,
boolean supportUpdates)
Returns a list of sub configurations for all configuration nodes selected
by the given key allowing the caller to specify the
supportUpdates flag. |
protected SubnodeConfiguration |
createSubConfigurationForTrackedNode(NodeSelector selector,
InMemoryNodeModelSupport parentModelSupport)
Creates a connected sub configuration based on a selector for a tracked
node.
|
InMemoryNodeModel |
getNodeModel()
Returns the
NodeModel supported by this object. |
protected NodeSelector |
getSubConfigurationNodeSelector(String key)
Returns the
NodeSelector to be used for a sub configuration based
on the passed in key. |
protected InMemoryNodeModel |
getSubConfigurationParentModel()
Returns the
InMemoryNodeModel to be used as parent model for a
new sub configuration. |
List<ImmutableHierarchicalConfiguration> |
immutableChildConfigurationsAt(String key)
Returns a list of immutable configurations for all direct child elements
of the node selected by the given key.
|
ImmutableHierarchicalConfiguration |
immutableConfigurationAt(String key)
Returns an immutable hierarchical configuration for the node specified by
the given key.
|
ImmutableHierarchicalConfiguration |
immutableConfigurationAt(String key,
boolean supportUpdates)
Returns an immutable hierarchical configuration object that wraps the
configuration node specified by the given key.
|
List<ImmutableHierarchicalConfiguration> |
immutableConfigurationsAt(String key)
Returns a list of immutable configurations for all configuration nodes selected
by the given key.
|
protected void |
initSubConfigurationForThisParent(SubnodeConfiguration subConfig)
Initializes a
SubnodeConfiguration object. |
Configuration |
interpolatedConfiguration()
Returns a configuration with the same content as this configuration, but
with all variables replaced by their actual values.
|
protected void |
subnodeConfigurationChanged(ConfigurationEvent event)
This method is always called when a subnode configuration created from
this configuration has been modified.
|
Configuration |
subset(String prefix)
Creates a new
Configuration object containing all keys
that start with the specified prefix. |
addNodes, addNodesInternal, addPropertyDirect, addPropertyInternal, clearInternal, clearPropertyDirect, clearTree, clearTreeInternal, clone, containsKeyInternal, fetchNodeList, getExpressionEngine, getKeysInternal, getKeysInternal, getMaxIndex, getMaxIndexInternal, getModel, getPropertyInternal, getRootElementName, getRootElementNameInternal, isEmptyInternal, nodeDefined, nodeKey, resolveAddKey, resolveKey, resolveNodeKey, resolveUpdateKey, setExpressionEngine, setPropertyInternal, sizeInternal, toString
addErrorLogListener, addProperty, 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, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setSynchronizer, setThrowExceptionOnMissing, size, unlock
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, 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, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, size
public BaseHierarchicalConfiguration()
BaseHierarchicalConfiguration
.public BaseHierarchicalConfiguration(HierarchicalConfiguration<ImmutableNode> c)
BaseHierarchicalConfiguration
and
copies all data contained in the specified configuration into the new
one.c
- the configuration that is to be copied (if null, this
constructor will behave like the standard constructor)protected BaseHierarchicalConfiguration(NodeModel<ImmutableNode> model)
BaseHierarchicalConfiguration
and
initializes it with the given NodeModel
.model
- the NodeModel
public InMemoryNodeModel getNodeModel()
NodeModel
supported by this object. This implementation returns the configuration's
NodeModel
. It is guarded by the current Synchronizer
. This implementation returns the InMemoryNodeModel
used by this configuration.getNodeModel
in interface InMemoryNodeModelSupport
getNodeModel
in interface NodeModelSupport<ImmutableNode>
getNodeModel
in class AbstractHierarchicalConfiguration<ImmutableNode>
NodeModel
public Configuration subset(String prefix)
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 AbstractConfiguration
prefix
- the prefix of the keys for the subsetSubsetConfiguration
public HierarchicalConfiguration<ImmutableNode> configurationAt(String key, boolean supportUpdates)
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>
key
- the key that selects the sub treesupportUpdates
- a flag whether the returned sub configuration
should be directly connected to its parentConfigurationRuntimeException
- if the key does not select a single
nodeSubnodeConfiguration
protected InMemoryNodeModel getSubConfigurationParentModel()
InMemoryNodeModel
to be used as parent model for a
new sub configuration. This method is called whenever a sub configuration
is to be created. This base implementation returns the model of this
configuration. Sub classes with different requirements for the parent
models of sub configurations have to override it.protected NodeSelector getSubConfigurationNodeSelector(String key)
NodeSelector
to be used for a sub configuration based
on the passed in key. This method is called whenever a sub configuration
is to be created. This base implementation returns a new
NodeSelector
initialized with the passed in key. Sub classes may
override this method if they have a different strategy for creating a
selector.key
- the key of the sub configurationNodeSelector
for initializing a sub configurationprotected SubnodeConfiguration createSubConfigurationForTrackedNode(NodeSelector selector, InMemoryNodeModelSupport parentModelSupport)
selector
- the NodeSelector
parentModelSupport
- the InMemoryNodeModelSupport
object for
the parent node modelprotected void initSubConfigurationForThisParent(SubnodeConfiguration subConfig)
SubnodeConfiguration
object. This method should be
called for each sub configuration created for this configuration. It
ensures that the sub configuration is correctly connected to its parent
instance and that update events are correctly propagated.subConfig
- the sub configuration to be initializedpublic ImmutableHierarchicalConfiguration immutableConfigurationAt(String key, boolean supportUpdates)
Returns an immutable hierarchical 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
ImmutableConfiguration.immutableSubset(String)
method is that
immutableSubset()
supports arbitrary subsets of configuration nodes
while immutableConfigurationAt()
only returns a single sub tree.
Please refer to the documentation of the
SubnodeConfiguration
class to obtain further information
about subnode configurations and when they should be used.
SubnodeConfiguration
by delegating to configurationAt()
. Then an immutable wrapper
is created and returned.immutableConfigurationAt
in interface ImmutableHierarchicalConfiguration
key
- the key that selects the sub treesupportUpdates
- a flag whether the returned subnode configuration
should be able to handle updates of its parentpublic HierarchicalConfiguration<ImmutableNode> configurationAt(String key)
configurationAt(key,
<b>false</b>)
. This is a short form for configurationAt(key,
<b>false</b>)
.configurationAt
in interface HierarchicalConfiguration<ImmutableNode>
key
- the key that selects the sub treeConfigurationRuntimeException
- if the key does not select a single nodeSubnodeConfiguration
public ImmutableHierarchicalConfiguration immutableConfigurationAt(String key)
immutableConfigurationAt(key,
<b>false</b>)
. This implementation creates a SubnodeConfiguration
by delegating to configurationAt()
. Then an immutable wrapper
is created and returned.immutableConfigurationAt
in interface ImmutableHierarchicalConfiguration
key
- the key that selects the sub treeConfigurationRuntimeException
- if the key does not select a single nodepublic List<HierarchicalConfiguration<ImmutableNode>> configurationsAt(String key)
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
configurationAt(String)
.configurationsAt
in interface HierarchicalConfiguration<ImmutableNode>
key
- the key for selecting the desired nodespublic List<HierarchicalConfiguration<ImmutableNode>> configurationsAt(String key, boolean supportUpdates)
supportUpdates
flag. This method works like
HierarchicalConfiguration.configurationsAt(String)
, but with the additional boolean
parameter it can be specified whether the returned configurations react
on updates of the parent configuration. This implementation creates tracked nodes for the specified
key. Then sub configurations for these nodes are created and returned.configurationsAt
in interface HierarchicalConfiguration<ImmutableNode>
key
- the key for selecting the desired nodessupportUpdates
- a flag whether the returned sub configuration
should be directly connected to its parentHierarchicalConfiguration.configurationsAt(String, boolean)
public List<ImmutableHierarchicalConfiguration> immutableConfigurationsAt(String key)
ExpressionEngine
) and then create an immutable subnode
configuration for each returned node (like
ImmutableHierarchicalConfiguration.immutableConfigurationAt(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<ImmutableHierarchicalConfiguration> fields = config.immutableConfigurationsAt("tables.table(0).fields.field"); for(Iterator<ImmutableHierarchicalConfiguration> it = fields.iterator(); it.hasNext();) { ImmutableHierarchicalConfiguration sub = 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"); ...This implementation first delegates to
configurationsAt()
to create a list of
SubnodeConfiguration
objects. Then for each element of this list
an unmodifiable wrapper is created.immutableConfigurationsAt
in interface ImmutableHierarchicalConfiguration
key
- the key for selecting the desired nodespublic List<HierarchicalConfiguration<ImmutableNode>> childConfigurationsAt(String key)
ImmutableHierarchicalConfiguration.immutableChildConfigurationsAt(String)
, but returns a list with
mutable configuration objects. The configuration objects returned are
not connected to the parent configuration. This implementation resolves the node(s) selected by the
given key. If not a single node is selected, an empty list is returned.
Otherwise, sub configurations for each child of the node are created.childConfigurationsAt
in interface HierarchicalConfiguration<ImmutableNode>
key
- the key for selecting the desired parent nodeHierarchicalConfiguration
objects for all
child nodes of the selected parent nodepublic List<HierarchicalConfiguration<ImmutableNode>> childConfigurationsAt(String key, boolean supportUpdates)
supportUpdates
flag. This method works like
childConfigurationsAt(String)
; however, depending on the value
of the supportUpdates
flag, connected sub configurations may be
created.childConfigurationsAt
in interface HierarchicalConfiguration<ImmutableNode>
key
- the key for selecting the desired parent nodesupportUpdates
- a flag whether the returned sub configuration
should be directly connected to its parentHierarchicalConfiguration
objects for
all child nodes of the selected parent nodepublic List<ImmutableHierarchicalConfiguration> immutableChildConfigurationsAt(String key)
childConfigurationsAt()
to create a list of mutable child
configurations. Then a list with immutable wrapper configurations is
created.immutableChildConfigurationsAt
in interface ImmutableHierarchicalConfiguration
key
- the key for selecting the desired parent nodeprotected void subnodeConfigurationChanged(ConfigurationEvent event)
SUBNODE_CHANGED
and notifies the registered listeners.event
- the event describing the changepublic Configuration interpolatedConfiguration()
interpolatedConfiguration
in class AbstractConfiguration
protected NodeModel<ImmutableNode> cloneNodeModel()
clone()
. This implementation creates a new instance of
InMemoryNodeModel
, initialized with this configuration's root
node. This has the effect that although the same nodes are used, the
original and copied configurations are independent on each other.cloneNodeModel
in class AbstractHierarchicalConfiguration<ImmutableNode>
NodeModel
Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.