Class SubsetConfiguration
- All Implemented Interfaces:
Configuration,EventSource,ImmutableConfiguration,SynchronizerSupport
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSubsetConfiguration(Configuration parent, String prefix) Create a subset of the specified configurationSubsetConfiguration(Configuration parent, String prefix, String delimiter) Create a subset of the specified configuration -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertyDirect(String key, Object value) Adds a key/value pair to the Configuration.protected voidRemoves the specified property from this configuration.protected booleanActually checks whether the specified key is contained in this configuration.protected booleancontainsValueInternal(Object value) Tests whether this configuration contains one or more matches to this value.protected StringgetChildKey(String key) Gets the key in the subset configuration associated to the specified key in the parent configuration.Actually creates an iterator for iterating over the keys in this configuration.getKeysInternal(String prefix) Gets anIteratorwith all property keys starting with the specified prefix.Gets theListDelimiterHandlerused by this instance.Gets the parent configuration for this subset.protected StringgetParentKey(String key) Gets the key in the parent configuration associated to the specified key in this subset.Gets the prefix used to select the properties in the parent configuration.protected ObjectActually obtains the value of the specified property.protected booleanActually checks whether this configuration contains data.booleanReturns true if missing values throw Exceptions.voidsetListDelimiterHandler(ListDelimiterHandler listDelimiterHandler) Sets theListDelimiterHandlerto be used by this instance.voidSets the prefix used to select the properties in the parent configuration.voidsetThrowExceptionOnMissing(boolean throwExceptionOnMissing) Allows to set thethrowExceptionOnMissingflag.Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix.Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearInternal, clearProperty, cloneInterpolator, contains, containsKey, containsValue, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeys, getKeysInternal, 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, unlockMethods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, clone, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEventsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
getEnum, getEnum
-
Field Details
-
parent
The parent configuration. -
prefix
The prefix used to select the properties. -
delimiter
The prefix delimiter
-
-
Constructor Details
-
SubsetConfiguration
Create a subset of the specified configuration- Parameters:
parent- The parent configuration (must not be null)prefix- The prefix used to select the properties- Throws:
IllegalArgumentException- if the parent configuration is null
-
SubsetConfiguration
Create a subset of the specified configuration- Parameters:
parent- The parent configuration (must not be null)prefix- The prefix used to select the propertiesdelimiter- The prefix delimiter- Throws:
NullPointerException- if the parent configuration is null
-
-
Method Details
-
addPropertyDirect
Description copied from class:AbstractConfigurationAdds a key/value pair to the Configuration. Override this method to provide write access to underlying Configuration store.- Specified by:
addPropertyDirectin classAbstractConfiguration- Parameters:
key- key to use for mappingvalue- object to store
-
clearPropertyDirect
Description copied from class:AbstractConfigurationRemoves the specified property from this configuration. This method is called byclearProperty()after it has done some preparations. It must be overridden in sub classes.- Specified by:
clearPropertyDirectin classAbstractConfiguration- Parameters:
key- the key to be removed
-
containsKeyInternal
Description copied from class:AbstractConfigurationActually checks whether the specified key is contained in this configuration. This method is called bycontainsKey(). It has to be defined by concrete subclasses.- Specified by:
containsKeyInternalin classAbstractConfiguration- Parameters:
key- the key in question- Returns:
- true if this key is contained in this configuration, false otherwise
-
containsValueInternal
Tests whether this configuration contains one or more matches to this value. This operation stops at first match but may be more expensive than the containsKey method.- Specified by:
containsValueInternalin classAbstractConfiguration- Parameters:
value- the value in question- Returns:
trueif and only if some key maps to thevalueargument in this configuration as determined by theequalsmethod;falseotherwise.- Since:
- 2.11.0
-
getChildKey
Gets 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
-
getKeysInternal
Description copied from class:AbstractConfigurationActually creates an iterator for iterating over the keys in this configuration. This method is called bygetKeys(), it has to be defined by concrete subclasses.- Specified by:
getKeysInternalin classAbstractConfiguration- Returns:
- an
Iteratorwith all property keys in this configuration
-
getKeysInternal
Description copied from class:AbstractConfigurationGets anIteratorwith all property keys starting with the specified prefix. This method is called byAbstractConfiguration.getKeys(String). It is fully implemented by delegating togetKeysInternal()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.- Overrides:
getKeysInternalin classAbstractConfiguration- Parameters:
prefix- the prefix for the keys to be taken into account- Returns:
- an
Iteratorreturning the filtered keys
-
getListDelimiterHandler
Gets theListDelimiterHandlerused by this instance. If the parent configuration extendsAbstractConfiguration, the list delimiter handler is obtained from there.- Overrides:
getListDelimiterHandlerin classAbstractConfiguration- Returns:
- the
ListDelimiterHandler
-
getParent
Gets the parent configuration for this subset.- Returns:
- the parent configuration
-
getParentKey
Gets 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
-
getPrefix
Gets the prefix used to select the properties in the parent configuration.- Returns:
- the prefix used by this subset
-
getPropertyInternal
Description copied from class:AbstractConfigurationActually obtains the value of the specified property. This method is called bygetProperty(). Concrete subclasses must define it to fetch the value of the desired property.- Specified by:
getPropertyInternalin classAbstractConfiguration- Parameters:
key- the key of the property in question- Returns:
- the (raw) value of this property
-
isEmptyInternal
Description copied from class:AbstractConfigurationActually checks whether this configuration contains data. This method is called byisEmpty(). It has to be defined by concrete subclasses.- Specified by:
isEmptyInternalin classAbstractConfiguration- Returns:
- true if this configuration contains no data, false otherwise
-
isThrowExceptionOnMissing
Returns true if missing values throw Exceptions. The subset inherits this feature from its parent if it supports this feature.- Overrides:
isThrowExceptionOnMissingin classAbstractConfiguration- Returns:
- true if missing values throw Exceptions
-
setListDelimiterHandler
Sets the
ListDelimiterHandlerto 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, aListDelimiterHandlerimplementation is set which does not support list splitting. This can be changed for instance by setting aDefaultListDelimiterHandlerobject.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.- Overrides:
setListDelimiterHandlerin classAbstractConfiguration- Parameters:
listDelimiterHandler- theListDelimiterHandlerto be used (must not be null)
-
setPrefix
Sets the prefix used to select the properties in the parent configuration.- Parameters:
prefix- the prefix
-
setThrowExceptionOnMissing
Allows to set thethrowExceptionOnMissingflag. 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 aNoSuchElementExceptionexception. 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.- Overrides:
setThrowExceptionOnMissingin classAbstractConfiguration- Parameters:
throwExceptionOnMissing- The new value for the property
-
subset
Description copied from interface:ConfigurationReturn 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 bysubset("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:
subsetin interfaceConfiguration- Overrides:
subsetin classAbstractConfiguration- Parameters:
prefix- The prefix used to select the properties.- Returns:
- a subset configuration
- See Also:
-