org.apache.commons.configuration
Class SubsetConfiguration

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

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 Configuration.subset(String) method should be used, which will return a correctly initialized instance.

Version:
$Revision$, $Date: 2005-10-05 21:36:15 +0200 (Wed, 05 Oct 2005) $
Author:
Emmanuel Bourg

Field Summary
protected  String delimiter
          The prefix delimiter
protected  Configuration parent
          The parent configuration.
protected  String prefix
          The prefix used to select the properties.
 
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
END_TOKEN, START_TOKEN
 
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
 void addPropertyDirect(String key, Object value)
          {@inheritDoc}
 void clearProperty(String key)
          {@inheritDoc}
 boolean containsKey(String key)
          {@inheritDoc}
protected  String getChildKey(String key)
          Return the key in the subset configuration associated to the specified key in the parent configuration.
 Iterator getKeys()
          {@inheritDoc}
 Iterator getKeys(String prefix)
          {@inheritDoc}
 Configuration getParent()
          Return the parent configuation for this subset.
protected  String getParentKey(String key)
          Return the key in the parent configuration associated to the specified key in this subset.
 String getPrefix()
          Return the prefix used to select the properties in the parent configuration.
 Object getProperty(String key)
          {@inheritDoc}
protected  String interpolate(String base)
          {@inheritDoc}
 boolean isEmpty()
          {@inheritDoc}
 boolean isThrowExceptionOnMissing()
          {@inheritDoc} The subset inherits this feature from its parent if it supports this feature.
 void setPrefix(String prefix)
          Set the prefix used to select the properties in the parent configuration.
 void setProperty(String key, Object value)
          {@inheritDoc}
 void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
          {@inheritDoc} Change the behaviour of the parent configuration if it supports this feature.
 Configuration subset(String prefix)
          {@inheritDoc}
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addProperty, clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, resolveContainerStore, setDelimiter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected Configuration parent
The parent configuration.

prefix

protected String prefix
The prefix used to select the properties.

delimiter

protected String delimiter
The prefix delimiter
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

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

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

getParent

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

getPrefix

public String getPrefix()
Return the prefix used to select the properties in the parent configuration.
Returns:
the prefix used by this subset

setPrefix

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

subset

public Configuration subset(String prefix)
{@inheritDoc}
Overrides:
subset in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
prefix - The prefix used to select the properties.
Returns:
a subset configuration
See Also:
SubsetConfiguration

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.

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

addPropertyDirect

public void addPropertyDirect(String key,
                              Object value)
{@inheritDoc}
Overrides:
addPropertyDirect in class AbstractConfiguration
Following copied from class: org.apache.commons.configuration.AbstractConfiguration
Parameters:
key - key to use for mapping
value - object to store

setProperty

public void setProperty(String key,
                        Object value)
{@inheritDoc}
Overrides:
setProperty in class AbstractConfiguration
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
key - The key of the property to change
value - The new value

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.

getProperty

public Object getProperty(String key)
{@inheritDoc}
Following copied from interface: org.apache.commons.configuration.Configuration
Parameters:
key - property to retrieve
Returns:
the value to which this configuration maps the specified key, or null if the configuration contains no mapping for this key.

getKeys

public Iterator getKeys(String prefix)
{@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()

getKeys

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

interpolate

protected String interpolate(String base)
{@inheritDoc}
Overrides:
interpolate in class AbstractConfiguration
Following copied from class: org.apache.commons.configuration.AbstractConfiguration
Parameters:
base - string to interpolate
Returns:
returns the key name with the ${key} substituted

setThrowExceptionOnMissing

public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
{@inheritDoc} Change the behaviour of the parent configuration if it supports this feature.
Overrides:
setThrowExceptionOnMissing in class AbstractConfiguration
Following copied from class: org.apache.commons.configuration.AbstractConfiguration
Parameters:
throwExceptionOnMissing - The new value for the property

isThrowExceptionOnMissing

public boolean isThrowExceptionOnMissing()
{@inheritDoc} The subset inherits this feature from its parent if it supports this feature.
Overrides:
isThrowExceptionOnMissing in class AbstractConfiguration
Following copied from class: org.apache.commons.configuration.AbstractConfiguration
Returns:
true if missing values throw Exceptions


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