Configuration, EventSource, ImmutableConfiguration, SynchronizerSupportpublic 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.
| Modifier and Type | Field | Description |
|---|---|---|
protected java.lang.String |
delimiter |
The prefix delimiter
|
protected Configuration |
parent |
The parent configuration.
|
protected java.lang.String |
prefix |
The prefix used to select the properties.
|
| Constructor | Description |
|---|---|
SubsetConfiguration(Configuration parent,
java.lang.String prefix) |
Create a subset of the specified configuration
|
SubsetConfiguration(Configuration parent,
java.lang.String prefix,
java.lang.String delimiter) |
Create a subset of the specified configuration
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addPropertyDirect(java.lang.String key,
java.lang.Object value) |
Adds a key/value pair to the Configuration.
|
protected void |
clearPropertyDirect(java.lang.String key) |
Removes the specified property from this configuration.
|
protected boolean |
containsKeyInternal(java.lang.String key) |
Actually checks whether the specified key is contained in this
configuration.
|
protected java.lang.String |
getChildKey(java.lang.String key) |
Return the key in the subset configuration associated to the specified
key in the parent configuration.
|
protected java.util.Iterator<java.lang.String> |
getKeysInternal() |
Actually creates an iterator for iterating over the keys in this
configuration.
|
protected java.util.Iterator<java.lang.String> |
getKeysInternal(java.lang.String prefix) |
Returns an
Iterator with all property keys starting with the
specified prefix. |
ListDelimiterHandler |
getListDelimiterHandler() |
Returns the
ListDelimiterHandler used by this instance. |
Configuration |
getParent() |
Return the parent configuration for this subset.
|
protected java.lang.String |
getParentKey(java.lang.String key) |
Return the key in the parent configuration associated to the specified
key in this subset.
|
java.lang.String |
getPrefix() |
Return the prefix used to select the properties in the parent configuration.
|
protected java.lang.Object |
getPropertyInternal(java.lang.String key) |
Actually obtains the value of the specified property.
|
protected boolean |
isEmptyInternal() |
Actually checks whether this configuration contains data.
|
boolean |
isThrowExceptionOnMissing() |
Returns true if missing values throw Exceptions.
|
void |
setListDelimiterHandler(ListDelimiterHandler listDelimiterHandler) |
Sets the
ListDelimiterHandler to be used by this instance. |
void |
setPrefix(java.lang.String prefix) |
Set the prefix used to select the properties in the parent configuration.
|
void |
setThrowExceptionOnMissing(boolean throwExceptionOnMissing) |
Allows to set the
throwExceptionOnMissing flag. |
Configuration |
subset(java.lang.String prefix) |
Return a decorator Configuration containing every key from the current
Configuration that starts with the specified prefix.
|
addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearInternal, clearProperty, cloneInterpolator, containsKey, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getList, getList, getList, getList, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setPropertyInternal, setSynchronizer, size, sizeInternal, unlockaddEventListener, clearErrorListeners, clearEventListeners, clone, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEventsprotected Configuration parent
protected java.lang.String prefix
protected java.lang.String delimiter
public SubsetConfiguration(Configuration parent, java.lang.String prefix)
parent - The parent configuration (must not be null)prefix - The prefix used to select the propertiesjava.lang.IllegalArgumentException - if the parent configuration is nullpublic SubsetConfiguration(Configuration parent, java.lang.String prefix, java.lang.String delimiter)
parent - The parent configuration (must not be null)prefix - The prefix used to select the propertiesdelimiter - The prefix delimiterjava.lang.IllegalArgumentException - if the parent configuration is nullprotected java.lang.String getParentKey(java.lang.String key)
key - The key in the subset.protected java.lang.String getChildKey(java.lang.String key)
key - The key in the parent configuration.public Configuration getParent()
public java.lang.String getPrefix()
public void setPrefix(java.lang.String prefix)
prefix - the prefixpublic Configuration subset(java.lang.String prefix)
Configuration
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.
subset in interface Configurationsubset in class AbstractConfigurationprefix - The prefix used to select the properties.SubsetConfigurationprotected boolean isEmptyInternal()
AbstractConfigurationisEmpty(). It has to be defined by concrete subclasses.isEmptyInternal in class AbstractConfigurationprotected boolean containsKeyInternal(java.lang.String key)
AbstractConfigurationcontainsKey(). It has to
be defined by concrete subclasses.containsKeyInternal in class AbstractConfigurationkey - the key in questionpublic void addPropertyDirect(java.lang.String key,
java.lang.Object value)
AbstractConfigurationaddPropertyDirect in class AbstractConfigurationkey - key to use for mappingvalue - object to storeprotected void clearPropertyDirect(java.lang.String key)
AbstractConfigurationclearProperty() after it has done some
preparations. It must be overridden in sub classes.clearPropertyDirect in class AbstractConfigurationkey - the key to be removedprotected java.lang.Object getPropertyInternal(java.lang.String key)
AbstractConfigurationgetProperty(). Concrete subclasses must define it to
fetch the value of the desired property.getPropertyInternal in class AbstractConfigurationkey - the key of the property in questionprotected java.util.Iterator<java.lang.String> getKeysInternal(java.lang.String prefix)
AbstractConfigurationIterator with all property keys starting with the
specified prefix. This method is called by AbstractConfiguration.getKeys(String). It
is fully implemented by delegating to getKeysInternal() and
returning a special iterator which filters for the passed in prefix.
Subclasses can override it if they can provide a more efficient way to
iterate over specific keys only.getKeysInternal in class AbstractConfigurationprefix - the prefix for the keys to be taken into accountIterator returning the filtered keysprotected java.util.Iterator<java.lang.String> getKeysInternal()
AbstractConfigurationgetKeys(), it has to be
defined by concrete subclasses.getKeysInternal in class AbstractConfigurationIterator with all property keys in this configurationpublic 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 behavior of the parent configuration if it supports this feature.setThrowExceptionOnMissing in class AbstractConfigurationthrowExceptionOnMissing - The new value for the propertypublic boolean isThrowExceptionOnMissing()
isThrowExceptionOnMissing in class AbstractConfigurationpublic ListDelimiterHandler getListDelimiterHandler()
ListDelimiterHandler used by this instance. If the parent configuration extends
AbstractConfiguration, the list delimiter handler is obtained
from there.getListDelimiterHandler in class AbstractConfigurationListDelimiterHandlerpublic void setListDelimiterHandler(ListDelimiterHandler listDelimiterHandler)
Sets the ListDelimiterHandler to be used by this instance. This
object is invoked every time when dealing with string properties that may
contain a list delimiter and thus have to be split to multiple values.
Per default, a ListDelimiterHandler implementation is set which
does not support list splitting. This can be changed for instance by
setting a DefaultListDelimiterHandler object.
Warning: Be careful when changing the list delimiter handler when the configuration has already been loaded/populated. List handling is typically applied already when properties are added to the configuration. If later another handler is set which processes lists differently, results may be unexpected; some operations may even cause exceptions.
If the parent configuration extendsAbstractConfiguration, the list delimiter handler is passed to
the parent.setListDelimiterHandler in class AbstractConfigurationlistDelimiterHandler - the ListDelimiterHandler to be used
(must not be null)Copyright © 2001–2018. All rights reserved.