org.apache.commons.configuration

Class CompositeConfiguration

public class CompositeConfiguration extends AbstractConfiguration implements Cloneable

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 494581 2007-01-09 21:14:20Z oheger $

Author: Eric Pugh Henning P. Schmiedehausen

Field Summary
ListconfigList
List holding all the configuration
ConfigurationinMemoryConfiguration
Configuration that holds in memory stuff.
Constructor Summary
CompositeConfiguration()
Creates an empty CompositeConfiguration object which can then be added some other Configuration files
CompositeConfiguration(Configuration inMemoryConfiguration)
Creates a CompositeConfiguration object with a specified in memory configuration.
CompositeConfiguration(Collection configurations)
Create a CompositeConfiguration with an empty in memory configuration and adds the collection of configurations specified.
CompositeConfiguration(Configuration inMemoryConfiguration, Collection configurations)
Creates a CompositeConfiguration with a specified in memory configuration, and then adds the given collection of configurations.
Method Summary
voidaddConfiguration(Configuration config)
Add a configuration.
protected voidaddPropertyDirect(String key, Object token)
Add this property to the inmemory Configuration.
voidclear()
Remove all configuration reinitialize the in memory configuration.
protected voidclearPropertyDirect(String key)
Objectclone()
Returns a copy of this object.
booleancontainsKey(String key)
ConfigurationgetConfiguration(int index)
Return the configuration at the specified index.
ConfigurationgetInMemoryConfiguration()
Returns the "in memory configuration".
IteratorgetKeys()
IteratorgetKeys(String key)
ListgetList(String key, List defaultValue)
intgetNumberOfConfigurations()
Return the number of configurations.
ObjectgetProperty(String key)
Read property from underlying composite
String[]getStringArray(String key)
booleanisEmpty()
voidremoveConfiguration(Configuration config)
Remove a configuration.
voidsetDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Sets a flag whether added values for string properties should be checked for the list delimiter.
voidsetListDelimiter(char listDelimiter)
Sets the character that is used as list delimiter.

Field Detail

configList

private List configList
List holding all the configuration

inMemoryConfiguration

private Configuration inMemoryConfiguration
Configuration that holds in memory stuff. Inserted as first so any setProperty() override anything else added.

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 a CompositeConfiguration object with a specified in memory configuration. This configuration will store any changes made to the CompositeConfiguration.

Parameters: inMemoryConfiguration the in memory configuration to use

CompositeConfiguration

public CompositeConfiguration(Collection configurations)
Create a CompositeConfiguration with an empty in memory configuration and adds the collection of configurations specified.

Parameters: configurations the collection of configurations to add

CompositeConfiguration

public CompositeConfiguration(Configuration inMemoryConfiguration, Collection configurations)
Creates a CompositeConfiguration with a specified in memory configuration, and then adds the given collection of configurations.

Parameters: inMemoryConfiguration the in memory configuration to use configurations the collection of configurations to add

Method Detail

addConfiguration

public void addConfiguration(Configuration config)
Add a configuration.

Parameters: config the configuration to add

addPropertyDirect

protected void addPropertyDirect(String key, Object token)
Add this property to the inmemory Configuration.

Parameters: key The Key to add the property to. token The Value to add.

clear

public void clear()
Remove all configuration reinitialize the in memory configuration.

clearPropertyDirect

protected void clearPropertyDirect(String key)
{@inheritDoc }

clone

public Object clone()
Returns a copy of this object. This implementation will create a deep clone, i.e. all configurations contained in this composite will also be cloned. This only works if all contained configurations support cloning; otherwise a runtime exception will be thrown. Registered event handlers won't get cloned.

Returns: the copy

Since: 1.3

containsKey

public boolean containsKey(String key)
{@inheritDoc }

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

getKeys

public Iterator getKeys()
{@inheritDoc }

getKeys

public Iterator getKeys(String key)
{@inheritDoc }

getList

public List getList(String key, List defaultValue)
{@inheritDoc }

getNumberOfConfigurations

public int getNumberOfConfigurations()
Return the number of configurations.

Returns: the number of configuration

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.

getStringArray

public String[] getStringArray(String key)
{@inheritDoc }

isEmpty

public boolean isEmpty()
{@inheritDoc }

removeConfiguration

public void removeConfiguration(Configuration config)
Remove a configuration. The in memory configuration cannot be removed.

Parameters: config The configuration to remove

setDelimiterParsingDisabled

public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Sets a flag whether added values for string properties should be checked for the list delimiter. This implementation ensures that the in memory configuration is correctly initialized.

Parameters: delimiterParsingDisabled the new value of the flag

Since: 1.4

setListDelimiter

public void setListDelimiter(char listDelimiter)
Sets the character that is used as list delimiter. This implementation ensures that the in memory configuration is correctly initialized.

Parameters: listDelimiter the new list delimiter character

Since: 1.4