Class PatternSubtreeConfigurationWrapper
- java.lang.Object
-
- org.apache.commons.configuration2.event.BaseEventSource
-
- org.apache.commons.configuration2.AbstractConfiguration
-
- org.apache.commons.configuration2.AbstractHierarchicalConfiguration<ImmutableNode>
-
- org.apache.commons.configuration2.BaseHierarchicalConfiguration
-
- org.apache.commons.configuration2.PatternSubtreeConfigurationWrapper
-
- All Implemented Interfaces:
Cloneable,Configuration,EventSource,FileBasedConfiguration,HierarchicalConfiguration<ImmutableNode>,ImmutableConfiguration,ImmutableHierarchicalConfiguration,FileBased,SynchronizerSupport,InMemoryNodeModelSupport,NodeKeyResolver<ImmutableNode>,NodeModelSupport<ImmutableNode>
public class PatternSubtreeConfigurationWrapper extends BaseHierarchicalConfiguration implements FileBasedConfiguration
Wraps a BaseHierarchicalConfiguration and allows subtrees to be accessed via a configured path with replaceable tokens derived from the ConfigurationInterpolator. When used with injection frameworks such as Spring it allows components to be injected with subtrees of the configuration.- Since:
- 1.6
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration
BaseHierarchicalConfiguration.BuilderVisitor
-
-
Constructor Summary
Constructors Constructor Description PatternSubtreeConfigurationWrapper(HierarchicalConfiguration<ImmutableNode> config, String path)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Event>
voidaddEventListener(EventType<T> eventType, EventListener<? super T> listener)Adds an event listener for the specified event type.protected voidaddNodesInternal(String key, Collection<? extends ImmutableNode> nodes)Actually adds a collection of new nodes to this configuration.protected voidaddPropertyInternal(String key, Object value)Adds the property with the specified key.voidclearErrorListeners()Removes all registered error listeners.voidclearEventListeners()Removes all registered event listeners.protected voidclearInternal()Clears this configuration.protected voidclearPropertyDirect(String key)Removes the property with the given key.protected ObjectclearTreeInternal(String key)Actually clears the tree of elements referenced by the given key.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 booleancontainsKeyInternal(String key)Checks if the specified key is contained in this configuration.BigDecimalgetBigDecimal(String key)Gets aBigDecimalassociated with the given configuration key.BigDecimalgetBigDecimal(String key, BigDecimal defaultValue)Gets aBigDecimalassociated with the given configuration key.BigIntegergetBigInteger(String key)Gets aBigIntegerassociated with the given configuration key.BigIntegergetBigInteger(String key, BigInteger defaultValue)Gets aBigIntegerassociated with the given configuration key.booleangetBoolean(String key)Gets a boolean associated with the given configuration key.booleangetBoolean(String key, boolean defaultValue)Gets a boolean associated with the given configuration key.BooleangetBoolean(String key, Boolean defaultValue)Obtains the value of the specified key and tries to convert it into aBooleanobject.bytegetByte(String key)Gets a byte associated with the given configuration key.bytegetByte(String key, byte defaultValue)Gets a byte associated with the given configuration key.BytegetByte(String key, Byte defaultValue)Gets aByteassociated with the given configuration key.doublegetDouble(String key)Gets a double associated with the given configuration key.doublegetDouble(String key, double defaultValue)Gets a double associated with the given configuration key.DoublegetDouble(String key, Double defaultValue)Gets aDoubleassociated with the given configuration key.<T extends Event>
Collection<EventListener<? super T>>getEventListeners(EventType<T> eventType)Gets a collection with all event listeners of the specified event type that are currently registered at this object.ExpressionEnginegetExpressionEngine()Gets the expression engine used by this configuration.floatgetFloat(String key)Gets a float associated with the given configuration key.floatgetFloat(String key, float defaultValue)Gets a float associated with the given configuration key.FloatgetFloat(String key, Float defaultValue)Gets aFloatassociated with the given configuration key.intgetInt(String key)Gets a int associated with the given configuration key.intgetInt(String key, int defaultValue)Gets a int associated with the given configuration key.IntegergetInteger(String key, Integer defaultValue)Gets anIntegerassociated with the given configuration key.protected Iterator<String>getKeysInternal()Gets an iterator with all keys defined in this configuration.protected Iterator<String>getKeysInternal(String prefix)Gets an iterator with all keys defined in this configuration that start with the given prefix.List<Object>getList(String key)Gets a List of the values associated with the given configuration key.List<Object>getList(String key, List<?> defaultValue)Gets a List of strings associated with the given configuration key.longgetLong(String key)Gets a long associated with the given configuration key.longgetLong(String key, long defaultValue)Gets a long associated with the given configuration key.LonggetLong(String key, Long defaultValue)Gets aLongassociated with the given configuration key.protected intgetMaxIndexInternal(String key)Actually retrieves the maximum defined index for the given key.PropertiesgetProperties(String key)Gets a list of properties associated with the given configuration key.protected ObjectgetPropertyInternal(String key)Fetches the specified property.shortgetShort(String key)Gets a short associated with the given configuration key.shortgetShort(String key, short defaultValue)Gets a short associated with the given configuration key.ShortgetShort(String key, Short defaultValue)Gets aShortassociated with the given configuration key.StringgetString(String key)Gets a string associated with the given configuration key.StringgetString(String key, String defaultValue)Gets a string associated with the given configuration key.String[]getStringArray(String key)Get an array of strings associated with the given configuration key.ConfigurationinterpolatedConfiguration()Returns a configuration with the same content as this configuration, but with all variables replaced by their actual values.protected booleanisEmptyInternal()Checks if this configuration is empty.voidread(Reader reader)Reads the content of this object from the given reader.<T extends Event>
booleanremoveEventListener(EventType<T> eventType, EventListener<? super T> listener)Removes the event listener registration for the given event type and listener.voidsetExpressionEngine(ExpressionEngine expressionEngine)Sets the expression engine to be used by this configuration.protected voidsetPropertyInternal(String key, Object value)Sets the value of the specified property.Configurationsubset(String prefix)Creates a newConfigurationobject containing all keys that start with the specified prefix.voidwrite(Writer writer)Writes the content of this object to the given writer.-
Methods inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration
childConfigurationsAt, childConfigurationsAt, cloneNodeModel, configurationsAt, createSubConfigurationForTrackedNode, getNodeModel, getSubConfigurationNodeSelector, getSubConfigurationParentModel, immutableChildConfigurationsAt, immutableConfigurationAt, immutableConfigurationAt, immutableConfigurationsAt, initSubConfigurationForThisParent, subnodeConfigurationChanged
-
Methods inherited from class org.apache.commons.configuration2.AbstractHierarchicalConfiguration
addNodes, addPropertyDirect, clearTree, clone, fetchNodeList, getMaxIndex, getModel, getRootElementName, getRootElementNameInternal, nodeDefined, nodeKey, resolveAddKey, resolveKey, resolveNodeKey, resolveUpdateKey, sizeInternal, toString
-
Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, containsKey, copy, endRead, endWrite, get, get, getArray, getArray, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDuration, getDuration, 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
-
Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource
copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, isDetailEvents, setDetailEvents
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.configuration2.Configuration
addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty
-
Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
containsKey, get, get, getArray, getArray, getCollection, getCollection, getDuration, getDuration, getEncodedString, getEncodedString, getEnum, getEnum, getKeys, getKeys, getList, getList, getProperty, immutableSubset, isEmpty, size
-
Methods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport
getSynchronizer, lock, setSynchronizer, unlock
-
-
-
-
Constructor Detail
-
PatternSubtreeConfigurationWrapper
public PatternSubtreeConfigurationWrapper(HierarchicalConfiguration<ImmutableNode> config, String path)
Constructor- Parameters:
config- The Configuration to be wrapped.path- The base path pattern.
-
-
Method Detail
-
addPropertyInternal
protected void addPropertyInternal(String key, Object value)
Description copied from class:AbstractHierarchicalConfigurationAdds the property with the specified key. This task will be delegated to the associatedExpressionEngine, so the passed in key must match the requirements of this implementation.- Overrides:
addPropertyInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key of the new propertyvalue- the value of the new property
-
clearInternal
protected void clearInternal()
Description copied from class:AbstractHierarchicalConfigurationClears this configuration. This is a more efficient implementation than the one inherited from the base class. It delegates to the node model.- Overrides:
clearInternalin classAbstractHierarchicalConfiguration<ImmutableNode>
-
clearPropertyDirect
protected void clearPropertyDirect(String key)
Description copied from class:AbstractHierarchicalConfigurationRemoves the property with the given key. Properties with names that start with the given key (i.e. properties below the specified key in the hierarchy) won't be affected. This implementation delegates to the node+ model.- Overrides:
clearPropertyDirectin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key of the property to be removed
-
containsKeyInternal
protected boolean containsKeyInternal(String key)
Description copied from class:AbstractHierarchicalConfigurationChecks if the specified key is contained in this configuration. Note that for this configuration the term "contained" means that the key has an associated value. If there is a node for this key that has no value but children (either defined or undefined), this method will still return false .- Overrides:
containsKeyInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key to be checked- Returns:
- a flag if this key is contained in this configuration
-
getBigDecimal
public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
Description copied from interface:ImmutableConfigurationGets aBigDecimalassociated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getBigDecimalin interfaceImmutableConfiguration- Overrides:
getBigDecimalin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated BigDecimal if key is found and has valid format, default value otherwise.
-
getBigDecimal
public BigDecimal getBigDecimal(String key)
Description copied from class:AbstractConfigurationGets aBigDecimalassociated with the given configuration key.- Specified by:
getBigDecimalin interfaceImmutableConfiguration- Overrides:
getBigDecimalin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated BigDecimal if key is found and has valid format
- See Also:
AbstractConfiguration.setThrowExceptionOnMissing(boolean)
-
getBigInteger
public BigInteger getBigInteger(String key, BigInteger defaultValue)
Description copied from interface:ImmutableConfigurationGets aBigIntegerassociated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getBigIntegerin interfaceImmutableConfiguration- Overrides:
getBigIntegerin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated BigInteger if key is found and has valid format, default value otherwise.
-
getBigInteger
public BigInteger getBigInteger(String key)
Description copied from class:AbstractConfigurationGets aBigIntegerassociated with the given configuration key.- Specified by:
getBigIntegerin interfaceImmutableConfiguration- Overrides:
getBigIntegerin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated BigInteger if key is found and has valid format
- See Also:
AbstractConfiguration.setThrowExceptionOnMissing(boolean)
-
getBoolean
public boolean getBoolean(String key, boolean defaultValue)
Description copied from interface:ImmutableConfigurationGets a boolean associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getBooleanin interfaceImmutableConfiguration- Overrides:
getBooleanin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated boolean.
-
getBoolean
public Boolean getBoolean(String key, Boolean defaultValue)
Description copied from class:AbstractConfigurationObtains the value of the specified key and tries to convert it into aBooleanobject. If the property has no value, the passed in default value will be used.- Specified by:
getBooleanin interfaceImmutableConfiguration- Overrides:
getBooleanin classAbstractConfiguration- Parameters:
key- the key of the propertydefaultValue- the default value- Returns:
- the value of this key converted to a
Boolean
-
getBoolean
public boolean getBoolean(String key)
Description copied from interface:ImmutableConfigurationGets a boolean associated with the given configuration key.- Specified by:
getBooleanin interfaceImmutableConfiguration- Overrides:
getBooleanin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated boolean.
-
getByte
public byte getByte(String key, byte defaultValue)
Description copied from interface:ImmutableConfigurationGets a byte associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getBytein interfaceImmutableConfiguration- Overrides:
getBytein classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated byte.
-
getByte
public Byte getByte(String key, Byte defaultValue)
Description copied from interface:ImmutableConfigurationGets aByteassociated with the given configuration key.- Specified by:
getBytein interfaceImmutableConfiguration- Overrides:
getBytein classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated byte if key is found and has valid format, default value otherwise.
-
getByte
public byte getByte(String key)
Description copied from interface:ImmutableConfigurationGets a byte associated with the given configuration key.- Specified by:
getBytein interfaceImmutableConfiguration- Overrides:
getBytein classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated byte.
-
getDouble
public double getDouble(String key, double defaultValue)
Description copied from interface:ImmutableConfigurationGets a double associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getDoublein interfaceImmutableConfiguration- Overrides:
getDoublein classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated double.
-
getDouble
public Double getDouble(String key, Double defaultValue)
Description copied from interface:ImmutableConfigurationGets aDoubleassociated with the given configuration key.- Specified by:
getDoublein interfaceImmutableConfiguration- Overrides:
getDoublein classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated double if key is found and has valid format, default value otherwise.
-
getDouble
public double getDouble(String key)
Description copied from interface:ImmutableConfigurationGets a double associated with the given configuration key.- Specified by:
getDoublein interfaceImmutableConfiguration- Overrides:
getDoublein classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated double.
-
getFloat
public float getFloat(String key, float defaultValue)
Description copied from interface:ImmutableConfigurationGets a float associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getFloatin interfaceImmutableConfiguration- Overrides:
getFloatin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated float.
-
getFloat
public Float getFloat(String key, Float defaultValue)
Description copied from interface:ImmutableConfigurationGets aFloatassociated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getFloatin interfaceImmutableConfiguration- Overrides:
getFloatin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated float if key is found and has valid format, default value otherwise.
-
getFloat
public float getFloat(String key)
Description copied from interface:ImmutableConfigurationGets a float associated with the given configuration key.- Specified by:
getFloatin interfaceImmutableConfiguration- Overrides:
getFloatin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated float.
-
getInt
public int getInt(String key, int defaultValue)
Description copied from interface:ImmutableConfigurationGets a int associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getIntin interfaceImmutableConfiguration- Overrides:
getIntin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated int.
-
getInt
public int getInt(String key)
Description copied from interface:ImmutableConfigurationGets a int associated with the given configuration key.- Specified by:
getIntin interfaceImmutableConfiguration- Overrides:
getIntin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated int.
-
getInteger
public Integer getInteger(String key, Integer defaultValue)
Description copied from interface:ImmutableConfigurationGets anIntegerassociated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getIntegerin interfaceImmutableConfiguration- Overrides:
getIntegerin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated int if key is found and has valid format, default value otherwise.
-
getKeysInternal
protected Iterator<String> getKeysInternal()
Description copied from class:AbstractHierarchicalConfigurationGets an iterator with all keys defined in this configuration. Note that the keys returned by this method will not contain any indices. This means that some structure will be lost.- Overrides:
getKeysInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Returns:
- an iterator with the defined keys in this configuration
-
getKeysInternal
protected Iterator<String> getKeysInternal(String prefix)
Description copied from class:AbstractHierarchicalConfigurationGets an iterator with all keys defined in this configuration that start with the given prefix. The returned keys will not contain any indices. This implementation tries to locate a node whose key is the same as the passed in prefix. Then the subtree of this node is traversed, and the keys of all nodes encountered (including attributes) are added to the result set.- Overrides:
getKeysInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
prefix- the prefix of the keys to start with- Returns:
- an iterator with the found keys
-
getList
public List<Object> getList(String key, List<?> defaultValue)
Description copied from interface:ImmutableConfigurationGets a List of strings associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getListin interfaceImmutableConfiguration- Overrides:
getListin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated List of strings.
- See Also:
ImmutableConfiguration.getList(Class, String, List)
-
getList
public List<Object> getList(String key)
Description copied from class:AbstractConfigurationGets a List of the values associated with the given configuration key. This method is different from the genericgetList()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.- Specified by:
getListin interfaceImmutableConfiguration- Overrides:
getListin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated List.
- See Also:
AbstractConfiguration.getStringArray(String)
-
getLong
public long getLong(String key, long defaultValue)
Description copied from interface:ImmutableConfigurationGets a long associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getLongin interfaceImmutableConfiguration- Overrides:
getLongin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated long.
-
getLong
public Long getLong(String key, Long defaultValue)
Description copied from interface:ImmutableConfigurationGets aLongassociated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getLongin interfaceImmutableConfiguration- Overrides:
getLongin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated long if key is found and has valid format, default value otherwise.
-
getLong
public long getLong(String key)
Description copied from interface:ImmutableConfigurationGets a long associated with the given configuration key.- Specified by:
getLongin interfaceImmutableConfiguration- Overrides:
getLongin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated long.
-
getProperties
public Properties getProperties(String key)
Description copied from interface:ImmutableConfigurationGets a list of properties associated with the given configuration key. This method expects the given key to have an arbitrary number of String values, each of which is of the formkey=value. These strings are split at the equals sign, and the key parts will become keys of the returnedPropertiesobject, the value parts become values.- Specified by:
getPropertiesin interfaceImmutableConfiguration- Overrides:
getPropertiesin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated properties if key is found.
-
getPropertyInternal
protected Object getPropertyInternal(String key)
Description copied from class:AbstractHierarchicalConfigurationFetches the specified property. This task is delegated to the associated expression engine.- Overrides:
getPropertyInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key to be looked up- Returns:
- the found value
-
getShort
public short getShort(String key, short defaultValue)
Description copied from interface:ImmutableConfigurationGets a short associated with the given configuration key.- Specified by:
getShortin interfaceImmutableConfiguration- Overrides:
getShortin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated short.
-
getShort
public Short getShort(String key, Short defaultValue)
Description copied from interface:ImmutableConfigurationGets aShortassociated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getShortin interfaceImmutableConfiguration- Overrides:
getShortin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated short if key is found and has valid format, default value otherwise.
-
getShort
public short getShort(String key)
Description copied from interface:ImmutableConfigurationGets a short associated with the given configuration key.- Specified by:
getShortin interfaceImmutableConfiguration- Overrides:
getShortin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated short.
-
getString
public String getString(String key, String defaultValue)
Description copied from interface:ImmutableConfigurationGets a string associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getStringin interfaceImmutableConfiguration- Overrides:
getStringin classAbstractConfiguration- Parameters:
key- The configuration key.defaultValue- The default value.- Returns:
- The associated string if key is found and has valid format, default value otherwise.
-
getString
public String getString(String key)
Description copied from class:AbstractConfigurationGets a string associated with the given configuration key.- Specified by:
getStringin interfaceImmutableConfiguration- Overrides:
getStringin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated string.
- See Also:
AbstractConfiguration.setThrowExceptionOnMissing(boolean)
-
getStringArray
public String[] getStringArray(String key)
Description copied from class:AbstractConfigurationGet an array of strings associated with the given configuration key. If the key doesn't map to an existing object, an empty array is returned. When a property is added to a configuration, it is checked whether it contains multiple values. This is obvious if the added object is a list or an array. For strings the associationListDelimiterHandleris consulted to find out whether the string can be split into multiple values.- Specified by:
getStringArrayin interfaceImmutableConfiguration- Overrides:
getStringArrayin classAbstractConfiguration- Parameters:
key- The configuration key.- Returns:
- The associated string array if key is found.
- See Also:
AbstractConfiguration.setListDelimiterHandler(ListDelimiterHandler)
-
isEmptyInternal
protected boolean isEmptyInternal()
Description copied from class:AbstractHierarchicalConfigurationChecks if this configuration is empty. Empty means that there are no keys with any values, though there can be some (empty) nodes.- Overrides:
isEmptyInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Returns:
- a flag if this configuration is empty
-
setPropertyInternal
protected void setPropertyInternal(String key, Object value)
Description copied from class:AbstractHierarchicalConfigurationSets the value of the specified property.- Overrides:
setPropertyInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key of the property to setvalue- the new value of this property
-
subset
public Configuration subset(String prefix)
Description copied from class:BaseHierarchicalConfigurationCreates a newConfigurationobject containing all keys that start with the specified prefix. This implementation will return aBaseHierarchicalConfigurationobject 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 returnedConfigurationobject 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 sameSynchronizeras this configuration.- Specified by:
subsetin interfaceConfiguration- Overrides:
subsetin classBaseHierarchicalConfiguration- Parameters:
prefix- the prefix of the keys for the subset- Returns:
- a new configuration object representing the selected subset
- See Also:
SubsetConfiguration
-
getExpressionEngine
public ExpressionEngine getExpressionEngine()
Description copied from class:AbstractHierarchicalConfigurationGets the expression engine used by this configuration. This method will never return null; if no specific expression engine was set, the default expression engine will be returned.- Specified by:
getExpressionEnginein interfaceImmutableHierarchicalConfiguration- Overrides:
getExpressionEnginein classAbstractHierarchicalConfiguration<ImmutableNode>- Returns:
- the current expression engine
-
setExpressionEngine
public void setExpressionEngine(ExpressionEngine expressionEngine)
Description copied from class:AbstractHierarchicalConfigurationSets the expression engine to be used by this configuration. All property keys this configuration has to deal with will be interpreted by this engine.- Specified by:
setExpressionEnginein interfaceHierarchicalConfiguration<ImmutableNode>- Overrides:
setExpressionEnginein classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
expressionEngine- the new expression engine; can be null, then the default expression engine will be used
-
addNodesInternal
protected void addNodesInternal(String key, Collection<? extends ImmutableNode> nodes)
Description copied from class:AbstractHierarchicalConfigurationActually adds a collection of new nodes to this configuration. This method is called byaddNodes(). It can be overridden by subclasses that need to adapt this operation.- Overrides:
addNodesInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key where the nodes are to be added; can be null, then they are added to the root nodenodes- a collection with theNodeobjects to be added
-
configurationAt
public HierarchicalConfiguration<ImmutableNode> configurationAt(String key, boolean supportUpdates)
Description copied from class:BaseHierarchicalConfigurationReturns 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
IllegalArgumentExceptionwill be thrown.The difference between this method and the
Configuration.subset(String)method is thatsubset()supports arbitrary subsets of configuration nodes whileconfigurationAt()only returns a single sub tree. Please refer to the documentation of theSubnodeConfigurationclass to obtain further information about sub configurations and when they should be used.With the
The result of this implementation depends on thesupportUpdateflag 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.supportUpdatesflag: If it is false, a plainBaseHierarchicalConfigurationis 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 aSubnodeConfigurationbased on this tracked node. This configuration is really connected to its parent, so that updated properties are visible on both.- Specified by:
configurationAtin interfaceHierarchicalConfiguration<ImmutableNode>- Overrides:
configurationAtin classBaseHierarchicalConfiguration- Parameters:
key- the key that selects the sub treesupportUpdates- a flag whether the returned sub configuration should be directly connected to its parent- Returns:
- a hierarchical configuration that contains this sub tree
- See Also:
SubnodeConfiguration
-
configurationAt
public HierarchicalConfiguration<ImmutableNode> configurationAt(String key)
Description copied from class:BaseHierarchicalConfigurationReturns a hierarchical subnode configuration for the node specified by the given key. This is a short form forconfigurationAt(key, <b>false</b>). This is a short form forconfigurationAt(key, <b>false</b>).- Specified by:
configurationAtin interfaceHierarchicalConfiguration<ImmutableNode>- Overrides:
configurationAtin classBaseHierarchicalConfiguration- Parameters:
key- the key that selects the sub tree- Returns:
- a hierarchical configuration that contains this sub tree
- See Also:
SubnodeConfiguration
-
configurationsAt
public List<HierarchicalConfiguration<ImmutableNode>> configurationsAt(String key)
Description copied from class:BaseHierarchicalConfigurationReturns a list of sub configurations for all configuration nodes selected by the given key. This method will evaluate the passed in key (using the currentExpressionEngine) and then create a sub configuration for each returned node (likeHierarchicalConfiguration.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 doList 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 forBaseHierarchicalConfiguration.configurationAt(String).- Specified by:
configurationsAtin interfaceHierarchicalConfiguration<ImmutableNode>- Overrides:
configurationsAtin classBaseHierarchicalConfiguration- Parameters:
key- the key for selecting the desired nodes- Returns:
- a list with hierarchical configuration objects; each configuration represents one of the nodes selected by the passed in key
-
clearTreeInternal
protected Object clearTreeInternal(String key)
Description copied from class:AbstractHierarchicalConfigurationActually clears the tree of elements referenced by the given key. This method is called byclearTree(). Subclasses that need to adapt this operation can override this method. This base implementation delegates to the node model.- Overrides:
clearTreeInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key of the property to be removed- Returns:
- an object with information about the nodes that have been removed (this is needed for firing a meaningful event of type CLEAR_TREE)
-
getMaxIndexInternal
protected int getMaxIndexInternal(String key)
Description copied from class:AbstractHierarchicalConfigurationActually retrieves the maximum defined index for the given key. This method is called bygetMaxIndex(). Subclasses that need to adapt this operation have to override this method.- Overrides:
getMaxIndexInternalin classAbstractHierarchicalConfiguration<ImmutableNode>- Parameters:
key- the key to be checked- Returns:
- the maximum defined index for this key
-
interpolatedConfiguration
public Configuration interpolatedConfiguration()
Description copied from class:BaseHierarchicalConfigurationReturns a configuration with the same content as this configuration, but with all variables replaced by their actual values. This implementation is specific for hierarchical configurations. It clones the current configuration and runs a specialized visitor on the clone, which performs interpolation on the single configuration nodes.- Overrides:
interpolatedConfigurationin classBaseHierarchicalConfiguration- Returns:
- a configuration with all variables interpolated
-
addEventListener
public <T extends Event> void addEventListener(EventType<T> eventType, EventListener<? super T> listener)
Description copied from interface:EventSourceAdds an event listener for the specified event type. This listener is notified about events of this type and all its sub types.- Specified by:
addEventListenerin interfaceEventSource- Overrides:
addEventListenerin classBaseEventSource- Type Parameters:
T- the type of events processed by this listener- Parameters:
eventType- the event type (must not be null)listener- the listener to be registered (must not be null)
-
removeEventListener
public <T extends Event> boolean removeEventListener(EventType<T> eventType, EventListener<? super T> listener)
Description copied from interface:EventSourceRemoves the event listener registration for the given event type and listener. An event listener instance may be registered multiple times for different event types. Therefore, when removing a listener the event type of the registration in question has to be specified. The return value indicates whether a registration was removed. A value of false means that no such combination of event type and listener was found.- Specified by:
removeEventListenerin interfaceEventSource- Overrides:
removeEventListenerin classBaseEventSource- Type Parameters:
T- the type of events processed by this listener- Parameters:
eventType- the event typelistener- the event listener to be removed- Returns:
- a flag whether a listener registration was removed
-
getEventListeners
public <T extends Event> Collection<EventListener<? super T>> getEventListeners(EventType<T> eventType)
Description copied from class:BaseEventSourceGets a collection with all event listeners of the specified event type that are currently registered at this object.- Overrides:
getEventListenersin classBaseEventSource- Type Parameters:
T- the event type- Parameters:
eventType- the event type object- Returns:
- a collection with the event listeners of the specified event type (this collection is a snapshot of the currently registered listeners; it cannot be manipulated)
-
clearEventListeners
public void clearEventListeners()
Description copied from class:BaseEventSourceRemoves all registered event listeners.- Overrides:
clearEventListenersin classBaseEventSource
-
clearErrorListeners
public void clearErrorListeners()
Description copied from class:BaseEventSourceRemoves all registered error listeners.- Overrides:
clearErrorListenersin classBaseEventSource
-
write
public void write(Writer writer) throws ConfigurationException, IOException
Description copied from interface:FileBasedWrites the content of this object to the given writer. Client code should not call this method directly, but use aFileHandlerfor writing data.- Specified by:
writein interfaceFileBased- Parameters:
writer- the writer- Throws:
ConfigurationException- if a non-I/O related problem occurs, e.g. the data read does not have the expected formatIOException- if an I/O error occurs.
-
read
public void read(Reader reader) throws ConfigurationException, IOException
Description copied from interface:FileBasedReads the content of this object from the given reader. Client code should not call this method directly, but use aFileHandlerfor reading data.- Specified by:
readin interfaceFileBased- Parameters:
reader- the reader- Throws:
ConfigurationException- if a non-I/O related problem occurs, e.g. the data read does not have the expected formatIOException- if an I/O error occurs.
-
-