org.apache.commons.configuration
Class MultiFileHierarchicalConfiguration

java.lang.Object
  extended byorg.apache.commons.configuration.event.EventSource
      extended byorg.apache.commons.configuration.AbstractConfiguration
          extended byorg.apache.commons.configuration.HierarchicalConfiguration
              extended byorg.apache.commons.configuration.AbstractHierarchicalFileConfiguration
                  extended byorg.apache.commons.configuration.MultiFileHierarchicalConfiguration
All Implemented Interfaces:
Cloneable, Configuration, ConfigurationErrorListener, ConfigurationListener, FileConfiguration, Serializable

public class MultiFileHierarchicalConfiguration
extends AbstractHierarchicalFileConfiguration
implements ConfigurationListener, ConfigurationErrorListener

This class provides access to multiple configuration files that reside in a location that can be specified by a pattern allowing applications to be multi-tenant. For example, providing a pattern of "file:///opt/config/${product}/${client}/config.xml" will result in "product" and "client" being resolved on every call. The configuration resulting from the resolved pattern will be saved for future access.

Since:
1.6
Version:
$Id: MultiFileHierarchicalConfiguration.java 727958 2008-12-19 07:19:24Z oheger $
Author:
Commons Configuration team
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
AbstractHierarchicalFileConfiguration.FileConfigurationDelegate
 
Nested classes inherited from class org.apache.commons.configuration.HierarchicalConfiguration
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor
 
Field Summary
 
Fields inherited from class org.apache.commons.configuration.HierarchicalConfiguration
EVENT_ADD_NODES, EVENT_CLEAR_TREE, EVENT_SUBNODE_CHANGED
 
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN
 
Constructor Summary
MultiFileHierarchicalConfiguration()
          Default Constructor.
MultiFileHierarchicalConfiguration(String pathPattern)
          Construct the configuration with the specified pattern.
 
Method Summary
 void addConfigurationListener(ConfigurationListener l)
          Adds a configuration listener to this object.
 void addErrorListener(ConfigurationErrorListener l)
          Adds a new configuration error listener to this object.
 void addNodes(String key, Collection nodes)
          Directly adds sub nodes to this configuration.
 void addProperty(String key, Object value)
          Add a property to the configuration.
 void clear()
          Remove all properties from the configuration.
 void clearConfigurationListeners()
          Removes all registered configuration listeners.
 void clearErrorListeners()
          Removes all registered error listeners.
 void clearProperty(String key)
          Remove a property from the configuration.
 void clearTree(String key)
          Removes all values of the property with the given name and of keys that start with this name.
 SubnodeConfiguration configurationAt(String key)
          Returns a hierarchical subnode configuration for the node specified by the given key.
 SubnodeConfiguration configurationAt(String key, boolean supportUpdates)
           Returns a hierarchical subnode configuration object that wraps the configuration node specified by the given key.
 void configurationChanged(ConfigurationEvent event)
          Notifies this listener about a manipulation on a monitored configuration object.
 void configurationError(ConfigurationErrorEvent event)
          Notifies this listener that in an observed configuration an error occurred.
 List configurationsAt(String key)
          Returns a list of sub configurations for all configuration nodes selected by the given key.
 boolean containsKey(String key)
          Check if the configuration contains the specified key.
protected  AbstractHierarchicalFileConfiguration.FileConfigurationDelegate createDelegate()
          Creates the file configuration delegate, i.e. the object that implements functionality required by the FileConfiguration interface.
 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)
          Get a Boolean associated with the given configuration key.
 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.
 Collection getConfigurationListeners()
          Returns a collection with all configuration event listeners that are currently registered at this object.
 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.
 Collection getErrorListeners()
          Returns a collection with all configuration error listeners that are currently registered at this object.
 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.
 Iterator getKeys()
          Get the list of the keys contained in the configuration.
 Iterator getKeys(String prefix)
          Get the list of the keys contained in the configuration that match the specified prefix.
 List getList(String key)
          Get a List of strings associated with the given configuration key.
 List 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.
 int getMaxIndex(String key)
          Returns the maximum defined index for the given key.
 Properties getProperties(String key)
          Get a list of properties associated with the given configuration key.
 Object getProperty(String key)
          Gets a property from the configuration.
 HierarchicalConfiguration.Node getRoot()
          Returns the root node of this hierarchical configuration.
 ConfigurationNode getRootNode()
          Returns the root node of this hierarchical configuration.
 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.
 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.
 boolean isEmpty()
          Check if the configuration is empty.
 void load()
          Load the configuration from the underlying URL.
 void load(File file)
          Load the configuration from the specified file.
 void load(InputStream in)
          Load the configuration from the specified stream, using the encoding returned by AbstractHierarchicalFileConfiguration.getEncoding().
 void load(InputStream in, String encoding)
          Load the configuration from the specified stream, using the specified encoding.
 void load(Reader reader)
          Load the configuration from the specified reader.
 void load(String fileName)
          Locate the specified file and load the configuration.
 void load(URL url)
          Load the configuration from the specified URL.
 void removeConfiguration()
          Remove the current Configuration.
 boolean removeConfigurationListener(ConfigurationListener l)
          Removes the specified event listener so that it does not receive any further events caused by this object.
 boolean removeErrorListener(ConfigurationErrorListener l)
          Removes the specified error listener so that it does not receive any further events caused by this object.
protected  Object resolveContainerStore(String key)
          Returns an object from the store described by the key.
 void save()
          Save the configuration.
 void save(File file)
          Save the configuration to the specified file.
 void save(OutputStream out)
          Save the configuration to the specified stream, using the encoding returned by AbstractHierarchicalFileConfiguration.getEncoding().
 void save(OutputStream out, String encoding)
          Save the configuration to the specified stream, using the specified encoding.
 void save(String fileName)
          Save the configuration to the specified file.
 void save(URL url)
          Save the configuration to the specified URL.
 void save(Writer writer)
          Save the configuration to the specified writer.
 void setExpressionEngine(ExpressionEngine expressionEngine)
          Sets the expression engine to be used by this configuration.
 void setFilePattern(String pathPattern)
          Set the File pattern
 void setProperty(String key, Object value)
          Set a property, this will replace any previously set values.
 void setRoot(HierarchicalConfiguration.Node node)
          Sets the root node of this hierarchical configuration.
 void setRootNode(ConfigurationNode rootNode)
          Sets the root node of this hierarchical configuration.
 Configuration subset(String prefix)
          Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix.
 
Methods inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
addPropertyDirect, fetchNodeList, getBasePath, getDelegate, getEncoding, getFile, getFileName, getReloadingStrategy, getURL, isAutoSave, reload, setAutoSave, setBasePath, setDelegate, setEncoding, setFile, setFileName, setReloadingStrategy, setURL, subnodeConfigurationChanged
 
Methods inherited from class org.apache.commons.configuration.HierarchicalConfiguration
clearNode, clearNode, clearReferences, clone, createAddPath, createNode, createSubnodeConfiguration, createSubnodeConfiguration, fetchAddNode, findLastPathNode, findPropertyNodes, getDefaultExpressionEngine, nodeDefined, nodeDefined, removeNode, removeNode, setDefaultExpressionEngine
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addErrorLogListener, append, clearPropertyDirect, copy, createInterpolator, getDefaultListDelimiter, getDelimiter, getInterpolator, getListDelimiter, getLogger, getProperties, getSubstitutor, interpolate, interpolate, interpolateHelper, isDelimiterParsingDisabled, isThrowExceptionOnMissing, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setThrowExceptionOnMissing
 
Methods inherited from class org.apache.commons.configuration.event.EventSource
createErrorEvent, createEvent, fireError, fireEvent, isDetailEvents, setDetailEvents
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiFileHierarchicalConfiguration

public MultiFileHierarchicalConfiguration()
Default Constructor.


MultiFileHierarchicalConfiguration

public MultiFileHierarchicalConfiguration(String pathPattern)
Construct the configuration with the specified pattern.

Parameters:
pathPattern - The pattern to use to locate configuration files.
Method Detail

setFilePattern

public void setFilePattern(String pathPattern)
Set the File pattern

Parameters:
pathPattern - The pattern for the path to the configuration.

createDelegate

protected AbstractHierarchicalFileConfiguration.FileConfigurationDelegate createDelegate()
Creates the file configuration delegate, i.e. the object that implements functionality required by the FileConfiguration interface. This base implementation will return an instance of the FileConfigurationDelegate class. Derived classes may override it to create a different delegate object.

Overrides:
createDelegate in class AbstractHierarchicalFileConfiguration
Returns:
the file configuration delegate

addProperty

public void addProperty(String key,
                        Object value)
Description copied from interface: Configuration
Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if the property:
resource.loader = file
is already present in the configuration and you call
addProperty("resource.loader", "classpath")
Then you will end up with a List like the following:
["file", "classpath"]

Specified by:
addProperty in interface Configuration
Overrides:
addProperty in class AbstractConfiguration

clear

public void clear()
Description copied from interface: Configuration
Remove all properties from the configuration.

Specified by:
clear in interface Configuration
Overrides:
clear in class AbstractConfiguration

clearProperty

public void clearProperty(String key)
Description copied from interface: Configuration
Remove a property from the configuration.

Specified by:
clearProperty in interface Configuration
Overrides:
clearProperty in class AbstractHierarchicalFileConfiguration

containsKey

public boolean containsKey(String key)
Description copied from interface: Configuration
Check if the configuration contains the specified key.

Specified by:
containsKey in interface Configuration
Overrides:
containsKey in class AbstractHierarchicalFileConfiguration

getBigDecimal

public BigDecimal getBigDecimal(String key,
                                BigDecimal defaultValue)
Description copied from interface: Configuration
Get a BigDecimal associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.

Specified by:
getBigDecimal in interface Configuration
Overrides:
getBigDecimal in class AbstractConfiguration

getBigDecimal

public BigDecimal getBigDecimal(String key)
Description copied from interface: Configuration
Get a BigDecimal associated with the given configuration key.

Specified by:
getBigDecimal in interface Configuration
Overrides:
getBigDecimal in class AbstractConfiguration
See Also:
AbstractConfiguration.setThrowExceptionOnMissing(boolean)

getBigInteger

public BigInteger getBigInteger(String key,
                                BigInteger defaultValue)
Description copied from interface: Configuration
Get a BigInteger associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.

Specified by:
getBigInteger in interface Configuration
Overrides:
getBigInteger in class AbstractConfiguration

getBigInteger

public BigInteger getBigInteger(String key)
Description copied from interface: Configuration
Get a BigInteger associated with the given configuration key.

Specified by:
getBigInteger in interface Configuration
Overrides:
getBigInteger in class AbstractConfiguration
See Also:
AbstractConfiguration.setThrowExceptionOnMissing(boolean)

getBoolean

public boolean getBoolean(String key,
                          boolean defaultValue)
Description copied from interface: Configuration
Get 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:
getBoolean in interface Configuration
Overrides:
getBoolean in class AbstractConfiguration
See Also:
PropertyConverter.toBoolean(Object)

getBoolean

public Boolean getBoolean(String key,
                          Boolean defaultValue)
Description copied from interface: Configuration
Get a Boolean associated with the given configuration key.

Specified by:
getBoolean in interface Configuration
Overrides:
getBoolean in class AbstractConfiguration
Parameters:
key - the key of the property
defaultValue - the default value
Returns:
the value of this key converted to a Boolean
See Also:
PropertyConverter.toBoolean(Object)

getBoolean

public boolean getBoolean(String key)
Description copied from interface: Configuration
Get a boolean associated with the given configuration key.

Specified by:
getBoolean in interface Configuration
Overrides:
getBoolean in class AbstractConfiguration
See Also:
PropertyConverter.toBoolean(Object)

getByte

public byte getByte(String key,
                    byte defaultValue)
Description copied from interface: Configuration
Get 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:
getByte in interface Configuration
Overrides:
getByte in class AbstractConfiguration

getByte

public Byte getByte(String key,
                    Byte defaultValue)
Description copied from interface: Configuration
Get a Byte associated with the given configuration key.

Specified by:
getByte in interface Configuration
Overrides:
getByte in class AbstractConfiguration

getByte

public byte getByte(String key)
Description copied from interface: Configuration
Get a byte associated with the given configuration key.

Specified by:
getByte in interface Configuration
Overrides:
getByte in class AbstractConfiguration

getDouble

public double getDouble(String key,
                        double defaultValue)
Description copied from interface: Configuration
Get 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:
getDouble in interface Configuration
Overrides:
getDouble in class AbstractConfiguration

getDouble

public Double getDouble(String key,
                        Double defaultValue)
Description copied from interface: Configuration
Get a Double associated with the given configuration key.

Specified by:
getDouble in interface Configuration
Overrides:
getDouble in class AbstractConfiguration

getDouble

public double getDouble(String key)
Description copied from interface: Configuration
Get a double associated with the given configuration key.

Specified by:
getDouble in interface Configuration
Overrides:
getDouble in class AbstractConfiguration

getFloat

public float getFloat(String key,
                      float defaultValue)
Description copied from interface: Configuration
Get 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:
getFloat in interface Configuration
Overrides:
getFloat in class AbstractConfiguration

getFloat

public Float getFloat(String key,
                      Float defaultValue)
Description copied from interface: Configuration
Get 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:
getFloat in interface Configuration
Overrides:
getFloat in class AbstractConfiguration

getFloat

public float getFloat(String key)
Description copied from interface: Configuration
Get a float associated with the given configuration key.

Specified by:
getFloat in interface Configuration
Overrides:
getFloat in class AbstractConfiguration

getInt

public int getInt(String key,
                  int defaultValue)
Description copied from interface: Configuration
Get 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:
getInt in interface Configuration
Overrides:
getInt in class AbstractConfiguration

getInt

public int getInt(String key)
Description copied from interface: Configuration
Get a int associated with the given configuration key.

Specified by:
getInt in interface Configuration
Overrides:
getInt in class AbstractConfiguration

getInteger

public Integer getInteger(String key,
                          Integer defaultValue)
Description copied from interface: Configuration
Get an Integer associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.

Specified by:
getInteger in interface Configuration
Overrides:
getInteger in class AbstractConfiguration

getKeys

public Iterator getKeys()
Description copied from interface: Configuration
Get the list of the keys contained in the configuration. The returned iterator can be used to obtain all defined keys. Note that the exact behavior of the iterator's remove() method is specific to a concrete implementation. It may remove the corresponding property from the configuration, but this is not guaranteed. In any case it is no replacement for calling Configuration.clearProperty(String) for this property. So it is highly recommended to avoid using the iterator's remove() method.

Specified by:
getKeys in interface Configuration
Overrides:
getKeys in class AbstractHierarchicalFileConfiguration

getKeys

public Iterator getKeys(String prefix)
Description copied from interface: Configuration
Get the list of the keys contained in the configuration that match the specified prefix.

Specified by:
getKeys in interface Configuration
Overrides:
getKeys in class AbstractHierarchicalFileConfiguration

getList

public List getList(String key,
                    List defaultValue)
Description copied from interface: Configuration
Get 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:
getList in interface Configuration
Overrides:
getList in class AbstractConfiguration

getList

public List getList(String key)
Description copied from interface: Configuration
Get a List of strings associated with the given configuration key. If the key doesn't map to an existing object an empty List is returned.

Specified by:
getList in interface Configuration
Overrides:
getList in class AbstractConfiguration
See Also:
AbstractConfiguration.getStringArray(String)

getLong

public long getLong(String key,
                    long defaultValue)
Description copied from interface: Configuration
Get 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:
getLong in interface Configuration
Overrides:
getLong in class AbstractConfiguration

getLong

public Long getLong(String key,
                    Long defaultValue)
Description copied from interface: Configuration
Get 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:
getLong in interface Configuration
Overrides:
getLong in class AbstractConfiguration

getLong

public long getLong(String key)
Description copied from interface: Configuration
Get a long associated with the given configuration key.

Specified by:
getLong in interface Configuration
Overrides:
getLong in class AbstractConfiguration

getProperties

public Properties getProperties(String key)
Description copied from interface: Configuration
Get 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 form key=value. These strings are splitted at the equals sign, and the key parts will become keys of the returned Properties object, the value parts become values.

Specified by:
getProperties in interface Configuration
Overrides:
getProperties in class AbstractConfiguration

getProperty

public Object getProperty(String key)
Description copied from interface: Configuration
Gets a property from the configuration. This is the most basic get method for retrieving values of properties. In a typical implementation of the Configuration interface the other get methods (that return specific data types) will internally make use of this method. On this level variable substitution is not yet performed. The returned object is an internal representation of the property value for the passed in key. It is owned by the Configuration object. So a caller should not modify this object. It cannot be guaranteed that this object will stay constant over time (i.e. further update operations on the configuration may change its internal state).

Specified by:
getProperty in interface Configuration
Overrides:
getProperty in class AbstractHierarchicalFileConfiguration

getShort

public short getShort(String key,
                      short defaultValue)
Description copied from interface: Configuration
Get a short associated with the given configuration key.

Specified by:
getShort in interface Configuration
Overrides:
getShort in class AbstractConfiguration

getShort

public Short getShort(String key,
                      Short defaultValue)
Description copied from interface: Configuration
Get a Short associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.

Specified by:
getShort in interface Configuration
Overrides:
getShort in class AbstractConfiguration

getShort

public short getShort(String key)
Description copied from interface: Configuration
Get a short associated with the given configuration key.

Specified by:
getShort in interface Configuration
Overrides:
getShort in class AbstractConfiguration

getString

public String getString(String key,
                        String defaultValue)
Description copied from interface: Configuration
Get 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:
getString in interface Configuration
Overrides:
getString in class AbstractConfiguration

getString

public String getString(String key)
Description copied from interface: Configuration
Get a string associated with the given configuration key.

Specified by:
getString in interface Configuration
Overrides:
getString in class AbstractConfiguration
See Also:
AbstractConfiguration.setThrowExceptionOnMissing(boolean)

getStringArray

public String[] getStringArray(String key)
Description copied from interface: Configuration
Get 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

Specified by:
getStringArray in interface Configuration
Overrides:
getStringArray in class AbstractConfiguration
Parameters:
key - The configuration key.
Returns:
The associated string array if key is found.
See Also:
AbstractConfiguration.setListDelimiter(char), AbstractConfiguration.setDelimiterParsingDisabled(boolean)

isEmpty

public boolean isEmpty()
Description copied from interface: Configuration
Check if the configuration is empty.

Specified by:
isEmpty in interface Configuration
Overrides:
isEmpty in class AbstractHierarchicalFileConfiguration

setProperty

public void setProperty(String key,
                        Object value)
Description copied from interface: Configuration
Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key, value).

Specified by:
setProperty in interface Configuration
Overrides:
setProperty in class AbstractHierarchicalFileConfiguration

subset

public Configuration subset(String prefix)
Description copied from interface: Configuration
Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix. The prefix is removed from the keys in the subset. For example, if the configuration contains the following properties:
    prefix.number = 1
    prefix.string = Apache
    prefixed.foo = bar
    prefix = Jakarta
the Configuration returned by subset("prefix") will contain the properties:
    number = 1
    string = Apache
    = Jakarta
(The key for the value "Jakarta" is an empty string)

Since the subset is a decorator and not a modified copy of the initial Configuration, any change made to the subset is available to the Configuration, and reciprocally.

Specified by:
subset in interface Configuration
Overrides:
subset in class HierarchicalConfiguration
Parameters:
prefix - the prefix of the keys for the subset
Returns:
a new configuration object representing the selected subset

getRoot

public HierarchicalConfiguration.Node getRoot()
Description copied from class: HierarchicalConfiguration
Returns the root node of this hierarchical configuration. This method exists for backwards compatibility only. New code should use the HierarchicalConfiguration.getRootNode() method instead, which operates on the preferred data type ConfigurationNode.

Overrides:
getRoot in class HierarchicalConfiguration
Returns:
the root node

setRoot

public void setRoot(HierarchicalConfiguration.Node node)
Description copied from class: HierarchicalConfiguration
Sets the root node of this hierarchical configuration. This method exists for backwards compatibility only. New code should use the HierarchicalConfiguration.setRootNode(ConfigurationNode) method instead, which operates on the preferred data type ConfigurationNode.

Overrides:
setRoot in class HierarchicalConfiguration
Parameters:
node - the root node

getRootNode

public ConfigurationNode getRootNode()
Description copied from class: HierarchicalConfiguration
Returns the root node of this hierarchical configuration.

Overrides:
getRootNode in class HierarchicalConfiguration
Returns:
the root node

setRootNode

public void setRootNode(ConfigurationNode rootNode)
Description copied from class: HierarchicalConfiguration
Sets the root node of this hierarchical configuration.

Overrides:
setRootNode in class HierarchicalConfiguration
Parameters:
rootNode - the root node

getExpressionEngine

public ExpressionEngine getExpressionEngine()
Description copied from class: HierarchicalConfiguration
Returns 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.

Overrides:
getExpressionEngine in class HierarchicalConfiguration
Returns:
the current expression engine

setExpressionEngine

public void setExpressionEngine(ExpressionEngine expressionEngine)
Description copied from class: HierarchicalConfiguration
Sets the expression engine to be used by this configuration. All property keys this configuration has to deal with will be interpreted by this engine.

Overrides:
setExpressionEngine in class HierarchicalConfiguration
Parameters:
expressionEngine - the new expression engine; can be null, then the default expression engine will be used

addNodes

public void addNodes(String key,
                     Collection nodes)
Description copied from class: AbstractHierarchicalFileConfiguration
Directly adds sub nodes to this configuration. This implementation checks whether auto save is necessary after executing the operation.

Overrides:
addNodes in class AbstractHierarchicalFileConfiguration
Parameters:
key - the key where the nodes are to be added
nodes - a collection with the nodes to be added

configurationAt

public SubnodeConfiguration configurationAt(String key,
                                            boolean supportUpdates)
Description copied from class: HierarchicalConfiguration

Returns a hierarchical subnode 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 HierarchicalConfiguration.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 subnode configurations and when they should be used.

With the supportUpdate flag the behavior of the returned SubnodeConfiguration regarding updates of its parent configuration can be determined. A subnode configuration operates on the same nodes as its parent, so changes at one configuration are normally directly visible for the other configuration. There are however changes of the parent configuration, which are not recognized by the subnode configuration per default. An example for this is a reload operation (for file-based configurations): Here the complete node set of the parent configuration is replaced, but the subnode configuration still references the old nodes. If such changes should be detected by the subnode configuration, the supportUpdates flag must be set to true. This causes the subnode configuration to reevaluate the key used for its creation each time it is accessed. This guarantees that the subnode configuration always stays in sync with its key, even if the parent configuration's data significantly changes. If such a change makes the key invalid - because it now no longer points to exactly one node -, the subnode configuration is not reconstructed, but keeps its old data. It is then quasi detached from its parent.

Overrides:
configurationAt in class HierarchicalConfiguration
Parameters:
key - the key that selects the sub tree
supportUpdates - a flag whether the returned subnode configuration should be able to handle updates of its parent
Returns:
a hierarchical configuration that contains this sub tree
See Also:
SubnodeConfiguration

configurationAt

public SubnodeConfiguration configurationAt(String key)
Description copied from class: HierarchicalConfiguration
Returns a hierarchical subnode configuration for the node specified by the given key. This is a short form for configurationAt(key, false).

Overrides:
configurationAt in class HierarchicalConfiguration
Parameters:
key - the key that selects the sub tree
Returns:
a hierarchical configuration that contains this sub tree
See Also:
SubnodeConfiguration

configurationsAt

public List configurationsAt(String key)
Description copied from class: HierarchicalConfiguration
Returns a list of sub configurations for all configuration nodes selected by the given key. This method will evaluate the passed in key (using the current ExpressionEngine) and then create a subnode 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();)
 {
     HierarchicalConfiguration sub = (HierarchicalConfiguration) 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");
     ...
 

Overrides:
configurationsAt in class HierarchicalConfiguration
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

clearTree

public void clearTree(String key)
Description copied from class: HierarchicalConfiguration
Removes all values of the property with the given name and of keys that start with this name. So if there is a property with the key "foo" and a property with the key "foo.bar", a call of clearTree("foo") would remove both properties.

Overrides:
clearTree in class AbstractHierarchicalFileConfiguration

getMaxIndex

public int getMaxIndex(String key)
Description copied from class: HierarchicalConfiguration
Returns the maximum defined index for the given key. This is useful if there are multiple values for this key. They can then be addressed separately by specifying indices from 0 to the return value of this method.

Overrides:
getMaxIndex in class HierarchicalConfiguration
Parameters:
key - the key to be checked
Returns:
the maximum defined index for this key

interpolatedConfiguration

public Configuration interpolatedConfiguration()
Description copied from class: HierarchicalConfiguration
Returns 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:
interpolatedConfiguration in class HierarchicalConfiguration
Returns:
a configuration with all variables interpolated

addConfigurationListener

public void addConfigurationListener(ConfigurationListener l)
Description copied from class: EventSource
Adds a configuration listener to this object.

Overrides:
addConfigurationListener in class EventSource
Parameters:
l - the listener to add

removeConfigurationListener

public boolean removeConfigurationListener(ConfigurationListener l)
Description copied from class: EventSource
Removes the specified event listener so that it does not receive any further events caused by this object.

Overrides:
removeConfigurationListener in class EventSource
Parameters:
l - the listener to be removed
Returns:
a flag whether the event listener was found

getConfigurationListeners

public Collection getConfigurationListeners()
Description copied from class: EventSource
Returns a collection with all configuration event listeners that are currently registered at this object.

Overrides:
getConfigurationListeners in class EventSource
Returns:
a collection with the registered ConfigurationListeners (this collection is a snapshot of the currently registered listeners; manipulating it has no effect on this event source object)

clearConfigurationListeners

public void clearConfigurationListeners()
Description copied from class: EventSource
Removes all registered configuration listeners.

Overrides:
clearConfigurationListeners in class EventSource

addErrorListener

public void addErrorListener(ConfigurationErrorListener l)
Description copied from class: EventSource
Adds a new configuration error listener to this object. This listener will then be notified about internal problems.

Overrides:
addErrorListener in class EventSource
Parameters:
l - the listener to register (must not be null)

removeErrorListener

public boolean removeErrorListener(ConfigurationErrorListener l)
Description copied from class: EventSource
Removes the specified error listener so that it does not receive any further events caused by this object.

Overrides:
removeErrorListener in class EventSource
Parameters:
l - the listener to remove
Returns:
a flag whether the listener could be found and removed

clearErrorListeners

public void clearErrorListeners()
Description copied from class: EventSource
Removes all registered error listeners.

Overrides:
clearErrorListeners in class EventSource

getErrorListeners

public Collection getErrorListeners()
Description copied from class: EventSource
Returns a collection with all configuration error listeners that are currently registered at this object.

Overrides:
getErrorListeners in class EventSource
Returns:
a collection with the registered ConfigurationErrorListeners (this collection is a snapshot of the currently registered listeners; it cannot be manipulated)

save

public void save(Writer writer)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration to the specified writer.

Specified by:
save in interface FileConfiguration
Parameters:
writer - the writer
Throws:
ConfigurationException - if an error occurs during the save operation

load

public void load(Reader reader)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Load the configuration from the specified reader.

Specified by:
load in interface FileConfiguration
Parameters:
reader - the reader
Throws:
ConfigurationException - if an error occurs during the load operation

load

public void load()
          throws ConfigurationException
Description copied from interface: FileConfiguration
Load the configuration from the underlying URL. If the URL is not specified, it attempts to locate the specified file name.

Specified by:
load in interface FileConfiguration
Overrides:
load in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

load

public void load(String fileName)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Locate the specified file and load the configuration.

Specified by:
load in interface FileConfiguration
Overrides:
load in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

load

public void load(File file)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Load the configuration from the specified file.

Specified by:
load in interface FileConfiguration
Overrides:
load in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

load

public void load(URL url)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Load the configuration from the specified URL.

Specified by:
load in interface FileConfiguration
Overrides:
load in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

load

public void load(InputStream in)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Load the configuration from the specified stream, using the encoding returned by FileConfiguration.getEncoding().

Specified by:
load in interface FileConfiguration
Overrides:
load in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

load

public void load(InputStream in,
                 String encoding)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Load the configuration from the specified stream, using the specified encoding. If the encoding is null the default encoding is used.

Specified by:
load in interface FileConfiguration
Overrides:
load in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

save

public void save()
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration.

Specified by:
save in interface FileConfiguration
Overrides:
save in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

save

public void save(String fileName)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration to the specified file.

Specified by:
save in interface FileConfiguration
Overrides:
save in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

save

public void save(File file)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration to the specified file.

Specified by:
save in interface FileConfiguration
Overrides:
save in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

save

public void save(URL url)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration to the specified URL.

Specified by:
save in interface FileConfiguration
Overrides:
save in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

save

public void save(OutputStream out)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration to the specified stream, using the encoding returned by FileConfiguration.getEncoding().

Specified by:
save in interface FileConfiguration
Overrides:
save in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

save

public void save(OutputStream out,
                 String encoding)
          throws ConfigurationException
Description copied from interface: FileConfiguration
Save the configuration to the specified stream, using the specified encoding. If the encoding is null the default encoding is used.

Specified by:
save in interface FileConfiguration
Overrides:
save in class AbstractHierarchicalFileConfiguration
Throws:
ConfigurationException

configurationChanged

public void configurationChanged(ConfigurationEvent event)
Description copied from interface: ConfigurationListener
Notifies this listener about a manipulation on a monitored configuration object.

Specified by:
configurationChanged in interface ConfigurationListener
Overrides:
configurationChanged in class AbstractHierarchicalFileConfiguration
Parameters:
event - the triggered event

configurationError

public void configurationError(ConfigurationErrorEvent event)
Description copied from interface: ConfigurationErrorListener
Notifies this listener that in an observed configuration an error occurred. All information available about this error, including the causing Throwable object, can be obtained from the passed in event object.

Specified by:
configurationError in interface ConfigurationErrorListener
Parameters:
event - the event object with information about the error

resolveContainerStore

protected Object resolveContainerStore(String key)
Description copied from class: AbstractConfiguration
Returns an object from the store described by the key. If the value is a Collection object, replace it with the first object in the collection.

Overrides:
resolveContainerStore in class AbstractConfiguration
Parameters:
key - The property key.
Returns:
value Value, transparently resolving a possible collection dependency.

removeConfiguration

public void removeConfiguration()
Remove the current Configuration.



Copyright © 2001-2008 The Apache Software Foundation. All Rights Reserved.