org.apache.commons.configuration

Class SubsetConfiguration

public class SubsetConfiguration extends AbstractConfiguration

A subset of another configuration. The new Configuration object contains every key from the parent Configuration that starts with prefix. The prefix is removed from the keys in the subset.

It is usually not necessary to use this class directly. Instead the subset method should be used, which will return a correctly initialized instance.

Version: $Revision: 501987 $, $Date: 2007-01-31 21:57:04 +0100 (Mi, 31 Jan 2007) $

Author: Emmanuel Bourg

Field Summary
protected Stringdelimiter
The prefix delimiter
protected Configurationparent
The parent configuration.
protected Stringprefix
The prefix used to select the properties.
Constructor Summary
SubsetConfiguration(Configuration parent, String prefix)
Create a subset of the specified configuration
SubsetConfiguration(Configuration parent, String prefix, String delimiter)
Create a subset of the specified configuration
Method Summary
voidaddPropertyDirect(String key, Object value)
voidclearProperty(String key)
booleancontainsKey(String key)
protected StringgetChildKey(String key)
Return the key in the subset configuration associated to the specified key in the parent configuration.
IteratorgetKeys(String prefix)
IteratorgetKeys()
chargetListDelimiter()
Returns the list delimiter.
ConfigurationgetParent()
Return the parent configuation for this subset.
protected StringgetParentKey(String key)
Return the key in the parent configuration associated to the specified key in this subset.
StringgetPrefix()
Return the prefix used to select the properties in the parent configuration.
ObjectgetProperty(String key)
protected Objectinterpolate(Object base)
protected Stringinterpolate(String base)
booleanisDelimiterParsingDisabled()
Returns a flag whether string properties should be checked for list delimiter characters.
booleanisEmpty()
booleanisThrowExceptionOnMissing()
{@inheritDoc } The subset inherits this feature from its parent if it supports this feature.
voidsetDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Sets a flag whether list parsing is disabled.
voidsetListDelimiter(char delim)
Sets the list delimiter.
voidsetPrefix(String prefix)
Set the prefix used to select the properties in the parent configuration.
voidsetProperty(String key, Object value)
voidsetThrowExceptionOnMissing(boolean throwExceptionOnMissing)
{@inheritDoc } Change the behaviour of the parent configuration if it supports this feature.
Configurationsubset(String prefix)

Field Detail

delimiter

protected String delimiter
The prefix delimiter

parent

protected Configuration parent
The parent configuration.

prefix

protected String prefix
The prefix used to select the properties.

Constructor Detail

SubsetConfiguration

public SubsetConfiguration(Configuration parent, String prefix)
Create a subset of the specified configuration

Parameters: parent The parent configuration prefix The prefix used to select the properties

SubsetConfiguration

public SubsetConfiguration(Configuration parent, String prefix, String delimiter)
Create a subset of the specified configuration

Parameters: parent The parent configuration prefix The prefix used to select the properties delimiter The prefix delimiter

Method Detail

addPropertyDirect

public void addPropertyDirect(String key, Object value)
{@inheritDoc }

clearProperty

public void clearProperty(String key)
{@inheritDoc }

containsKey

public boolean containsKey(String key)
{@inheritDoc }

getChildKey

protected String getChildKey(String key)
Return the key in the subset configuration associated to the specified key in the parent configuration.

Parameters: key The key in the parent configuration.

Returns: the key in the context of this subset configuration

getKeys

public Iterator getKeys(String prefix)
{@inheritDoc }

getKeys

public Iterator getKeys()
{@inheritDoc }

getListDelimiter

public char getListDelimiter()
Returns the list delimiter. This property will be fetched from the parent configuration if supported.

Returns: the list delimiter

Since: 1.4

getParent

public Configuration getParent()
Return the parent configuation for this subset.

Returns: the parent configuration

getParentKey

protected String getParentKey(String key)
Return the key in the parent configuration associated to the specified key in this subset.

Parameters: key The key in the subset.

Returns: the key as to be used by the parent

getPrefix

public String getPrefix()
Return the prefix used to select the properties in the parent configuration.

Returns: the prefix used by this subset

getProperty

public Object getProperty(String key)
{@inheritDoc }

interpolate

protected Object interpolate(Object base)
{@inheritDoc }

interpolate

protected String interpolate(String base)
{@inheritDoc }

isDelimiterParsingDisabled

public boolean isDelimiterParsingDisabled()
Returns a flag whether string properties should be checked for list delimiter characters. This implementation ensures that this flag is kept in sync with the parent configuration if this object supports this feature.

Returns: the delimiter parsing disabled flag

Since: 1.4

isEmpty

public boolean isEmpty()
{@inheritDoc }

isThrowExceptionOnMissing

public boolean isThrowExceptionOnMissing()
{@inheritDoc } The subset inherits this feature from its parent if it supports this feature.

setDelimiterParsingDisabled

public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Sets a flag whether list parsing is disabled. This implementation will also set the flag at the parent configuration if this object supports this feature.

Parameters: delimiterParsingDisabled the delimiter parsing disabled flag

Since: 1.4

setListDelimiter

public void setListDelimiter(char delim)
Sets the list delimiter. If the parent configuration supports this feature, the delimiter will be set at the parent.

Parameters: delim the new list delimiter

Since: 1.4

setPrefix

public void setPrefix(String prefix)
Set the prefix used to select the properties in the parent configuration.

Parameters: prefix the prefix

setProperty

public void setProperty(String key, Object value)
{@inheritDoc }

setThrowExceptionOnMissing

public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
{@inheritDoc } Change the behaviour of the parent configuration if it supports this feature.

subset

public Configuration subset(String prefix)
{@inheritDoc }