org.apache.commons.configuration
Class CompositeConfiguration

java.lang.Object
  |
  +--org.apache.commons.configuration.AbstractConfiguration
        |
        +--org.apache.commons.configuration.CompositeConfiguration
All Implemented Interfaces:
Configuration

public class CompositeConfiguration
extends AbstractConfiguration

This Configuration class allows you to add multiple different types of Configuration to this CompositeConfiguration. If you add Configuration1, and then Configuration2, any properties shared will mean that Configuration1 will be returned. You can add multiple different types or the same type of properties file. If Configuration1 doesn't have the property, then Configuration2 will be checked.

Version:
$Id: CompositeConfiguration.java 332561 2005-11-11 14:17:23Z oheger $
Author:
Eric Pugh, Henning P. Schmiedehausen

Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
END_TOKEN, START_TOKEN
 
Constructor Summary
CompositeConfiguration()
          Creates an empty CompositeConfiguration object which can then be added some other Configuration files
CompositeConfiguration(Configuration inMemoryConfiguration)
          Creates an CompositeConfiguration object with a specified InMemory configuration.
 
Method Summary
 void addConfiguration(Configuration config)
          Add a configuration.
protected  void addPropertyDirect(String key, Object token)
          Add this property to the inmemory Configuration.
 void clear()
          Remove all configuration reinitialize the in memory configuration.
 void clearProperty(String key)
          {@inheritDoc}
 boolean containsKey(String key)
          {@inheritDoc}
 Configuration getConfiguration(int index)
          Return the configuration at the specified index.
 Configuration getInMemoryConfiguration()
          Returns the "in memory configuration".
 Iterator getKeys()
          {@inheritDoc}
 Iterator getKeys(String key)
          {@inheritDoc}
 List getList(String key, List defaultValue)
          {@inheritDoc}
 int getNumberOfConfigurations()
          Return the number of configurations.
 Object getProperty(String key)
          Read property from underlying composite
 String[] getStringArray(String key)
          {@inheritDoc}
 boolean isEmpty()
          {@inheritDoc}
 void removeConfiguration(Configuration config)
          Remove a configuration.
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addProperty, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, interpolate, interpolate, interpolateHelper, isThrowExceptionOnMissing, resolveContainerStore, setDelimiter, setProperty, setThrowExceptionOnMissing, subset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeConfiguration

public CompositeConfiguration()
Creates an empty CompositeConfiguration object which can then be added some other Configuration files

CompositeConfiguration

public CompositeConfiguration(Configuration inMemoryConfiguration)
Creates an CompositeConfiguration object with a specified InMemory configuration. This configuration will store any changes made to the CompositeConfiguration.
Parameters:
inMemoryConfiguration - the in memory configuration to use
Method Detail

addConfiguration

public void addConfiguration(Configuration config)
Add a configuration.
Parameters:
config - the configuration to add

removeConfiguration

public void removeConfiguration(Configuration config)
Remove a configuration. The in memory configuration cannot be removed.
Parameters:
config - The configuration to remove

getNumberOfConfigurations

public int getNumberOfConfigurations()
Return the number of configurations.
Returns:
the number of configuration

clear

public void clear()
Remove all configuration reinitialize the in memory configuration.
Overrides:
clear in class AbstractConfiguration

addPropertyDirect

protected void addPropertyDirect(String key,
                                 Object token)
Add this property to the inmemory Configuration.
Overrides:
addPropertyDirect in class AbstractConfiguration
Parameters:
key - The Key to add the property to.
token - The Value to add.

getProperty

public Object getProperty(String key)
Read property from underlying composite
Parameters:
key - key to use for mapping
Returns:
object associated with the given configuration key.

getKeys

public Iterator getKeys()
{@inheritDoc}
Overrides:
getKeys in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Returns:
An Iterator.

getKeys

public Iterator getKeys(String key)
{@inheritDoc}
Overrides:
getKeys in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
prefix - The prefix to test against.
Returns:
An Iterator of keys that match the prefix.
See Also:
Configuration.getKeys()

isEmpty

public boolean isEmpty()
{@inheritDoc}
Overrides:
isEmpty in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Returns:
true if the configuration contains no property, false otherwise.

clearProperty

public void clearProperty(String key)
{@inheritDoc}
Overrides:
clearProperty in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
key - the key to remove along with corresponding value.

containsKey

public boolean containsKey(String key)
{@inheritDoc}
Overrides:
containsKey in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
key - the key whose presence in this configuration is to be tested
Returns:
true if the configuration contains a value for this key, false otherwise

getList

public List getList(String key,
                    List defaultValue)
{@inheritDoc}
Overrides:
getList in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
key - The configuration key.
defaultValue - The default value.
Returns:
The associated List of strings.
Throws:
ConversionException - is thrown if the key maps to an object that is not a List.

getStringArray

public String[] getStringArray(String key)
{@inheritDoc}
Overrides:
getStringArray in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
key - The configuration key.
Returns:
The associated string array if key is found.
Throws:
ConversionException - is thrown if the key maps to an object that is not a String/List of Strings.

getConfiguration

public Configuration getConfiguration(int index)
Return the configuration at the specified index.
Parameters:
index - The index of the configuration to retrieve
Returns:
the configuration at this index

getInMemoryConfiguration

public Configuration getInMemoryConfiguration()
Returns the "in memory configuration". In this configuration changes are stored.
Returns:
the in memory configuration


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