Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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.

Version:
  $Revision: 1.6 $, $Date: 2004/10/05 21:17:25 $
Author:
  Emmanuel Bourg
See Also:
  `Configuration.subset(String)`

Nested Class Summary

Nested classes inherited from class org.apache.commons.configuration.AbstractConfiguration
`AbstractConfiguration.PropertiesTokenizer`

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)` Adds a key/value pair to the Configuration. Override this method to provide write acces to underlying Configuration store.
`void` | `clearProperty(String key)` Remove a property from the configuration.
`boolean` | `containsKey(String key)` Check if the configuration contains the specified key.
`protected String` | `getChildKey(String key)` Return the key in the subset configuration associated to the specified key in the parent configuration.
`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.
`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` | `getPropertyDirect(String key)` Read property. Should return `null` if the key doesn't map to an existing object.
`protected String` | `interpolate(String base)` interpolate key names to handle ${key} stuff
`boolean` | `isEmpty()` Check if the configuration is empty.
`boolean` | `isThrowExceptionOnMissing()` Returns true if missing values throw Exceptions. 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)` Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key, value).
`void` | `setThrowExceptionOnMissing(boolean throwExceptionOnMissing)` If set to false, missing elements return null if possible (for objects). Change the behaviour of the parent configuration if it supports this feature.
`Configuration` | `subset(String prefix)` 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.

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, getList, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getVector, getVector, interpolateHelper, setDelimiter, split`

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.

### 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.

### getParent

    public Configuration getParent()

  Return the parent configuation for this subset.

### getPrefix

    public String getPrefix()

  Return the prefix used to select the properties in the parent configuration.

### setPrefix

    public void setPrefix(String prefix)

  Set the prefix used to select the properties in the parent configuration.

### subset

    public Configuration subset(String prefix)

  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 `AbstractConfiguration`

### isEmpty

    public boolean isEmpty()

  Check if the configuration is empty.

  Specified by:
    `isEmpty` in interface `Configuration`
  Specified by:
    `isEmpty` in class `AbstractConfiguration`

### containsKey

    public boolean containsKey(String key)

  Check if the configuration contains the specified key.

  Specified by:
    `containsKey` in interface `Configuration`
  Specified by:
    `containsKey` in class `AbstractConfiguration`

### addPropertyDirect

    public void addPropertyDirect(String key,
                                  Object value)

  Adds a key/value pair to the Configuration. Override this method to provide write acces to underlying Configuration store.

  Specified by:
    `addPropertyDirect` in class `AbstractConfiguration`
  Parameters:
    `key` - key to use for mapping
    `value` - object to store

### setProperty

    public void setProperty(String key,
                            Object value)

  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 `AbstractConfiguration`

### clearProperty

    public void clearProperty(String key)

  Remove a property from the configuration.

  Specified by:
    `clearProperty` in interface `Configuration`
  Specified by:
    `clearProperty` in class `AbstractConfiguration`

### getPropertyDirect

    public Object getPropertyDirect(String key)

  Read property. Should return `null` if the key doesn't map to an existing object.

  Specified by:
    `getPropertyDirect` in class `AbstractConfiguration`
  Parameters:
    `key` - key to use for mapping
  Returns:
    object associated with the given configuration key.

### getKeys

    public Iterator getKeys(String prefix)

  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 `AbstractConfiguration`

### getKeys

    public Iterator getKeys()

  Get the list of the keys contained in the configuration.

  Specified by:
    `getKeys` in interface `Configuration`
  Specified by:
    `getKeys` in class `AbstractConfiguration`

### interpolate

    protected String interpolate(String base)

  interpolate key names to handle ${key} stuff

  Overrides:
    `interpolate` in class `AbstractConfiguration`
  Parameters:
    `base` - string to interpolate
  Returns:
    returns the key name with the ${key} substituted

### setThrowExceptionOnMissing

    public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)

  If set to false, missing elements return null if possible (for objects). Change the behaviour of the parent configuration if it supports this feature.

  Overrides:
    `setThrowExceptionOnMissing` in class `AbstractConfiguration`
  Parameters:
    `throwExceptionOnMissing` - The new value for the property

### isThrowExceptionOnMissing

    public boolean isThrowExceptionOnMissing()

  Returns true if missing values throw Exceptions. The subset inherits this feature from its parent if it supports this feature.

  Overrides:
    `isThrowExceptionOnMissing` in class `AbstractConfiguration`
  Returns:
    true if missing values throw Exceptions

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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