|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.configuration.event.EventSource org.apache.commons.configuration.AbstractConfiguration org.apache.commons.configuration.SubsetConfiguration
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
method should be used,
which will return a correctly initialized instance.Configuration.subset(String)
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, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_SET_PROPERTY, 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)
Removes the specified property from this configuration. This implementation performs some preparations and then delegates to clearPropertyDirect() , which will do the real work. |
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. The returned iterator can be used to obtain all defined keys. Note that the exact behavior of the iterator's remove() method is specific to
a concrete implementation. It may remove the corresponding
property from the configuration, but this is not guaranteed. In any case
it is no replacement for calling
for this property. So it is
highly recommended to avoid using the iterator's remove()
method. |
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 |
getProperty(String key)
Gets a property from the configuration. This is the most basic get method for retrieving values of properties. In a typical implementation of the Configuration interface the other get methods (that
return specific data types) will internally make use of this method. On
this level variable substitution is not yet performed. The returned
object is an internal representation of the property value for the passed
in key. It is owned by the Configuration object. So a caller
should not modify this object. It cannot be guaranteed that this object
will stay constant over time (i.e. further update operations on the
configuration may change its internal state). |
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)
Allows to set the throwExceptionOnMissing flag. This
flag controls the behavior of property getter methods that return
objects if the requested property is missing. If the flag is set to
false (which is the default value), these methods will return
null. If set to true, they will throw a
NoSuchElementException exception. Note that getter methods
for primitive data types are not affected by this flag.
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 = Jakartathe 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, clear, clearPropertyDirect, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getList, getListDelimiter, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, isDelimiterParsingDisabled, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter |
Methods inherited from class org.apache.commons.configuration.event.EventSource |
addConfigurationListener, clearConfigurationListeners, createEvent, fireEvent, getConfigurationListeners, isDetailEvents, removeConfigurationListener, setDetailEvents |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Configuration parent
protected String prefix
protected String delimiter
Constructor Detail |
public SubsetConfiguration(Configuration parent, String prefix)
parent
- The parent configurationprefix
- The prefix used to select the propertiespublic SubsetConfiguration(Configuration parent, String prefix, String delimiter)
parent
- The parent configurationprefix
- The prefix used to select the propertiesdelimiter
- The prefix delimiterMethod Detail |
protected String getParentKey(String key)
key
- The key in the subset.
protected String getChildKey(String key)
key
- The key in the parent configuration.
public Configuration getParent()
public String getPrefix()
public void setPrefix(String prefix)
prefix
- the prefixpublic Configuration subset(String prefix)
prefix.number = 1 prefix.string = Apache prefixed.foo = bar prefix = Jakartathe 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.
subset
in interface Configuration
subset
in class AbstractConfiguration
public boolean isEmpty()
isEmpty
in interface Configuration
isEmpty
in class AbstractConfiguration
public boolean containsKey(String key)
containsKey
in interface Configuration
containsKey
in class AbstractConfiguration
public void addPropertyDirect(String key, Object value)
addPropertyDirect
in class AbstractConfiguration
key
- key to use for mappingvalue
- object to storepublic void setProperty(String key, Object value)
setProperty
in interface Configuration
setProperty
in class AbstractConfiguration
public void clearProperty(String key)
clearPropertyDirect()
, which will do the real work.
clearProperty
in interface Configuration
clearProperty
in class AbstractConfiguration
key
- the key to be removedpublic Object getProperty(String key)
Configuration
interface the other get methods (that
return specific data types) will internally make use of this method. On
this level variable substitution is not yet performed. The returned
object is an internal representation of the property value for the passed
in key. It is owned by the Configuration
object. So a caller
should not modify this object. It cannot be guaranteed that this object
will stay constant over time (i.e. further update operations on the
configuration may change its internal state).
key
- property to retrieve
public Iterator getKeys(String prefix)
getKeys
in interface Configuration
getKeys
in class AbstractConfiguration
public Iterator getKeys()
remove()
method is specific to
a concrete implementation. It may remove the corresponding
property from the configuration, but this is not guaranteed. In any case
it is no replacement for calling
Configuration.clearProperty(String)
for this property. So it is
highly recommended to avoid using the iterator's remove()
method.
getKeys
in interface Configuration
getKeys
in class AbstractConfiguration
protected String interpolate(String base)
interpolate
in class AbstractConfiguration
base
- string to interpolate
public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
throwExceptionOnMissing
flag. This
flag controls the behavior of property getter methods that return
objects if the requested property is missing. If the flag is set to
false (which is the default value), these methods will return
null. If set to true, they will throw a
NoSuchElementException
exception. Note that getter methods
for primitive data types are not affected by this flag.
Change the behaviour of the parent configuration if it supports this feature.
setThrowExceptionOnMissing
in class AbstractConfiguration
throwExceptionOnMissing
- The new value for the propertypublic boolean isThrowExceptionOnMissing()
isThrowExceptionOnMissing
in class AbstractConfiguration
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |