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.
Modifier and Type | Field and 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.
|
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN
Constructor and 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 and 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.
|
boolean |
containsKey(java.lang.String key)
Check if the configuration contains the specified key.
|
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.
|
java.util.Iterator<java.lang.String> |
getKeys()
Get the list of the keys contained in the configuration.
|
java.util.Iterator<java.lang.String> |
getKeys(java.lang.String prefix)
Get the list of the keys contained in the configuration that match the
specified prefix.
|
char |
getListDelimiter()
Returns the list delimiter.
|
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.
|
java.lang.Object |
getProperty(java.lang.String key)
Gets a property from the configuration.
|
protected java.lang.Object |
interpolate(java.lang.Object base)
Returns the interpolated value.
|
protected java.lang.String |
interpolate(java.lang.String base)
interpolate key names to handle ${key} stuff
|
boolean |
isDelimiterParsingDisabled()
Returns a flag whether string properties should be checked for list
delimiter characters.
|
boolean |
isEmpty()
Check if the configuration is empty.
|
boolean |
isThrowExceptionOnMissing()
Returns true if missing values throw Exceptions.
|
void |
setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Sets a flag whether list parsing is disabled.
|
void |
setListDelimiter(char delim)
Sets the list delimiter.
|
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, append, clear, clearProperty, copy, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getList, getList, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, getSubstitutor, interpolatedConfiguration, interpolateHelper, isScalarValue, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setLogger, setProperty
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, clone, createErrorEvent, createEvent, fireError, fireEvent, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEvents
protected Configuration parent
protected java.lang.String prefix
protected java.lang.String delimiter
public SubsetConfiguration(Configuration parent, java.lang.String prefix)
parent
- The parent configurationprefix
- The prefix used to select the propertiespublic SubsetConfiguration(Configuration parent, java.lang.String prefix, java.lang.String delimiter)
parent
- The parent configurationprefix
- The prefix used to select the propertiesdelimiter
- The prefix delimiterprotected 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 = 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
prefix
- The prefix used to select the properties.SubsetConfiguration
public boolean isEmpty()
Configuration
true
if the configuration contains no property,
false
otherwise.public boolean containsKey(java.lang.String key)
Configuration
key
- the key whose presence in this configuration is to be testedtrue
if the configuration contains a value for this
key, false
otherwisepublic void addPropertyDirect(java.lang.String key, java.lang.Object value)
AbstractConfiguration
addPropertyDirect
in class AbstractConfiguration
key
- key to use for mappingvalue
- object to storeprotected void clearPropertyDirect(java.lang.String key)
AbstractConfiguration
clearProperty()
after it has done some
preparations. It should be overridden in sub classes. This base
implementation is just left empty.clearPropertyDirect
in class AbstractConfiguration
key
- the key to be removedpublic java.lang.Object getProperty(java.lang.String key)
Configuration
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 retrievepublic java.util.Iterator<java.lang.String> getKeys(java.lang.String prefix)
AbstractConfiguration
db.user, db.pwd, db.url, window.xpos, window.ypos
,getKeys("db");
db.user, db.pwd, db.url
.getKeys("db");
will find the keys db
,
db.user
, or db.password
, but not the key
dbdriver
.getKeys
in interface Configuration
getKeys
in class AbstractConfiguration
prefix
- The prefix to test against.Configuration.getKeys()
public java.util.Iterator<java.lang.String> getKeys()
Configuration
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.protected java.lang.Object interpolate(java.lang.Object base)
AbstractConfiguration
interpolate
in class AbstractConfiguration
base
- the value to interpolateprotected java.lang.String interpolate(java.lang.String base)
AbstractConfiguration
interpolate
in class AbstractConfiguration
base
- string to interpolatepublic 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 AbstractConfiguration
throwExceptionOnMissing
- The new value for the propertypublic boolean isThrowExceptionOnMissing()
isThrowExceptionOnMissing
in class AbstractConfiguration
public char getListDelimiter()
getListDelimiter
in class AbstractConfiguration
public void setListDelimiter(char delim)
setListDelimiter
in class AbstractConfiguration
delim
- the new list delimiterpublic boolean isDelimiterParsingDisabled()
isDelimiterParsingDisabled
in class AbstractConfiguration
public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
setDelimiterParsingDisabled
in class AbstractConfiguration
delimiterParsingDisabled
- the delimiter parsing disabled flagCopyright © 2001-2013. All Rights Reserved.