Class AbstractConfiguration
- All Implemented Interfaces:
Configuration
,EventSource
,ImmutableConfiguration
,SynchronizerSupport
- Direct Known Subclasses:
AbstractHierarchicalConfiguration
,AppletConfiguration
,BaseConfiguration
,CompositeConfiguration
,DatabaseConfiguration
,DataConfiguration
,JNDIConfiguration
,MapConfiguration
,ServletConfiguration
,ServletContextConfiguration
,ServletFilterConfiguration
,ServletRequestConfiguration
,SubsetConfiguration
Abstract configuration class. Provides basic functionality but does not store any data.
If you want to write your own Configuration class then you should implement only abstract methods from this class. A
lot of functionality needed by typical implementations of the Configuration
interface is already provided by
this base class. Following is a list of features implemented here:
- Data conversion support. The various data types required by the
Configuration
interface are already handled by this base class. A concrete sub class only needs to provide a genericgetProperty()
method. - Support for variable interpolation. Property values containing special variable tokens (like
${var}
) will be replaced by their corresponding values. - Optional support for string lists. The values of properties to be added to this configuration are checked whether
they contain a list delimiter character. If this is the case and if list splitting is enabled, the string is split
and multiple values are added for this property. List splitting is controlled by a
ListDelimiterHandler
object which can be set using thesetListDelimiterHandler(ListDelimiterHandler)
method. It is disabled per default. To enable this feature, set a suitableListDelimiterHandler
, e.g. an instance ofDefaultListDelimiterHandler
configured with the desired list delimiter character. - Allows specifying how missing properties are treated. Per default the get methods returning an object will return
null if the searched property key is not found (and no default value is provided). With the
setThrowExceptionOnMissing()
method this behavior can be changed to throw an exception when a requested property cannot be found. - Basic event support. Whenever this configuration is modified registered event listeners are notified. Refer to
the various
EVENT_XXX
constants to get an impression about which event types are supported. - Support for proper synchronization based on the
Synchronizer
interface.
Most methods defined by the Configuration
interface are already implemented in this class. Many method
implementations perform basic book-keeping tasks (e.g. firing events, handling synchronization), and then delegate to
other (protected) methods executing the actual work. Subclasses override these protected methods to define or adapt
behavior. The public entry point methods are final to prevent subclasses from breaking basic functionality.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds a specialEventListener
object to this configuration that will log all internal errors.final void
addProperty
(String key, Object value) Add a property to the configuration.protected abstract void
addPropertyDirect
(String key, Object value) Adds a key/value pair to the Configuration.protected void
addPropertyInternal
(String key, Object value) Actually adds a property to this configuration.void
Appends the content of the specified configuration to this configuration.protected void
beginRead
(boolean optimize) Notifies this configuration'sSynchronizer
that a read operation is about to start.protected void
beginWrite
(boolean optimize) Notifies this configuration'sSynchronizer
that an update operation is about to start.final void
clear()
Remove all properties from the configuration.protected void
Clears the whole configuration.final void
clearProperty
(String key) Removes the specified property from this configuration.protected abstract void
Removes the specified property from this configuration.protected void
cloneInterpolator
(AbstractConfiguration orgConfig) Creates a clone of theConfigurationInterpolator
used by this instance.protected boolean
Checks if the specified value exists in the properties structure mapped by the provided keys.final boolean
containsKey
(String key) Checks if the configuration contains the specified key.protected abstract boolean
Actually checks whether the specified key is contained in this configuration.final boolean
containsValue
(Object value) Tests whether this configuration contains one or more matches to this value.protected abstract boolean
containsValueInternal
(Object value) Tests whether this configuration contains one or more matches to this value.void
Copies the content of the specified configuration into this configuration.protected void
endRead()
Notifies this configuration'sSynchronizer
that a read operation has finished.protected void
endWrite()
Notifies this configuration'sSynchronizer
that an update operation has finished.<T> T
Gets an object of the specified type associated with the given configuration key.<T> T
Gets an object of the specified type associated with the given configuration key using a default value.Gets an array of typed objects associated with the given configuration key.Gets an array of typed objects associated with the given configuration key.getBigDecimal
(String key) Gets aBigDecimal
associated with the given configuration key.getBigDecimal
(String key, BigDecimal defaultValue) Gets aBigDecimal
associated with the given configuration key.getBigInteger
(String key) Gets aBigInteger
associated with the given configuration key.getBigInteger
(String key, BigInteger defaultValue) Gets aBigInteger
associated with the given configuration key.boolean
getBoolean
(String key) Gets a boolean associated with the given configuration key.boolean
getBoolean
(String key, boolean defaultValue) Gets a boolean associated with the given configuration key.getBoolean
(String key, Boolean defaultValue) Obtains the value of the specified key and tries to convert it into aBoolean
object.byte
Gets a byte associated with the given configuration key.byte
Gets a byte associated with the given configuration key.Gets aByte
associated with the given configuration key.<T> Collection<T>
getCollection
(Class<T> cls, String key, Collection<T> target) Gets a collection of typed objects associated with the given configuration key.<T> Collection<T>
getCollection
(Class<T> cls, String key, Collection<T> target, Collection<T> defaultValue) Gets a collection of typed objects associated with the given configuration key using the values in the specified default collection if the key does not map to an existing object.Gets theConfigurationDecoder
used by this instance.Gets theConversionHandler
used by this instance.double
Gets a double associated with the given configuration key.double
Gets a double associated with the given configuration key.Gets aDouble
associated with the given configuration key.getDuration
(String key) Gets aDuration
associated with the given configuration key.getDuration
(String key, Duration defaultValue) Gets aDuration
associated with the given configuration key.getEncodedString
(String key) Gets the value of a string property that is stored in encoded form in this configuration using a defaultConfigurationDecoder
.getEncodedString
(String key, ConfigurationDecoder decoder) Gets the value of a string property that is stored in encoded form in this configuration.float
Gets a float associated with the given configuration key.float
Gets a float associated with the given configuration key.Gets aFloat
associated with the given configuration key.int
Gets a int associated with the given configuration key.int
Gets a int associated with the given configuration key.getInteger
(String key, Integer defaultValue) Gets anInteger
associated with the given configuration key.Gets theConfigurationInterpolator
object that manages the lookup objects for resolving variables.getKeys()
Gets the list of the keys contained in the configuration.Gets the list of the keys contained in the configuration that match the specified prefix.Gets the list of the keys contained in the configuration that match the specified prefix.Actually creates an iterator for iterating over the keys in this configuration.getKeysInternal
(String prefix) Gets anIterator
with all property keys starting with the specified prefix.getKeysInternal
(String prefix, String delimiter) Gets anIterator
with all property keys starting with the specified prefix and specified delimiter.<T> List<T>
Gets a list of typed objects associated with the given configuration key returning a null if the key doesn't map to an existing object.<T> List<T>
Gets a list of typed objects associated with the given configuration key returning the specified default value if the key doesn't map to an existing object.Gets a List of the values associated with the given configuration key.Gets a List of strings associated with the given configuration key.Gets theListDelimiterHandler
used by this instance.Gets the logger used by this configuration object.long
Gets a long associated with the given configuration key.long
Gets a long associated with the given configuration key.Gets aLong
associated with the given configuration key.getProperties
(String key) Gets a list of properties associated with the given configuration key.getProperties
(String key, Properties defaults) Gets a list of properties associated with the given configuration key.final Object
getProperty
(String key) Gets a property from the configuration.protected abstract Object
Actually obtains the value of the specified property.short
Gets a short associated with the given configuration key.short
Gets a short associated with the given configuration key.Gets aShort
associated with the given configuration key.Gets a string associated with the given configuration key.Gets a string associated with the given configuration key.String[]
getStringArray
(String key) Gets an array of strings associated with the given configuration key.final Synchronizer
Gets the object responsible for synchronizing this configuration.immutableSubset
(String prefix) Return a decorator immutable Configuration containing every key from the current Configuration that starts with the specified prefix.protected final void
Initializes the logger.final void
installInterpolator
(Map<String, ? extends Lookup> prefixLookups, Collection<? extends Lookup> defLookups) Creates and installs a newConfigurationInterpolator
for thisConfiguration
based on the passed in arguments.protected Object
interpolate
(Object value) Returns the interpolated value.protected String
interpolate
(String base) interpolate key names to handle ${key} stuffReturns a configuration with the same content as this configuration, but with all variables replaced by their actual values.final boolean
isEmpty()
Checks if the configuration is empty.protected abstract boolean
Actually checks whether this configuration contains data.protected boolean
isScalarValue
(Object value) Checks whether the specified object is a scalar value.boolean
Returns true if missing values throw Exceptions.final void
Locks this object for the specified mode.void
setConfigurationDecoder
(ConfigurationDecoder configurationDecoder) Sets theConfigurationDecoder
for this configuration.void
setConversionHandler
(ConversionHandler conversionHandler) Sets theConversionHandler
to be used by this instance.void
setDefaultLookups
(Collection<? extends Lookup> lookups) Adds allLookup
objects in the given collection as default lookups (i.e.final void
Sets theConfigurationInterpolator
object to be used by thisConfiguration
.void
setListDelimiterHandler
(ListDelimiterHandler listDelimiterHandler) Sets theListDelimiterHandler
to be used by this instance.void
Allows setting the logger to be used by this configuration object.void
Sets the specifiedConfigurationInterpolator
as the parent of this configuration'sConfigurationInterpolator
.void
setPrefixLookups
(Map<String, ? extends Lookup> lookups) Registers allLookup
objects in the given map at the currentConfigurationInterpolator
of this configuration.final void
setProperty
(String key, Object value) Sets a property, this will replace any previously set values.protected void
setPropertyInternal
(String key, Object value) Actually sets the value of a property.final void
setSynchronizer
(Synchronizer synchronizer) Sets the object responsible for synchronizing this configuration.void
setThrowExceptionOnMissing
(boolean throwExceptionOnMissing) Allows to set thethrowExceptionOnMissing
flag.final int
size()
Returns the number of keys stored in this configuration.protected int
Actually calculates the size of this configuration.Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix.final void
Releases a lock of this object that was obtained using theSynchronizerSupport.lock(LockMode)
method.Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, clone, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
getEnum, getEnum
-
Constructor Details
-
AbstractConfiguration
public AbstractConfiguration()Creates a new instance ofAbstractConfiguration
.
-
-
Method Details
-
addErrorLogListener
Adds a specialEventListener
object to this configuration that will log all internal errors. This method is intended to be used by certain derived classes, for which it is known that they can fail on property access (e.g.DatabaseConfiguration
).- Since:
- 1.4
-
addProperty
Description copied from interface:Configuration
Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if the property:resource.loader = file
is already present in the configuration and you calladdProperty("resource.loader", "classpath")
Then you will end up with a List like the following:["file", "classpath"]
- Specified by:
addProperty
in interfaceConfiguration
- Parameters:
key
- The key to add the property to.value
- The value to add.
-
addPropertyDirect
Adds a key/value pair to the Configuration. Override this method to provide write access to underlying Configuration store.- Parameters:
key
- key to use for mappingvalue
- object to store
-
addPropertyInternal
Actually adds a property to this configuration. This method is called byaddProperty()
. It performs list splitting if necessary and delegates toaddPropertyDirect(String, Object)
for every single property value.- Parameters:
key
- the key of the property to be addedvalue
- the new property value- Since:
- 2.0
-
append
Appends the content of the specified configuration to this configuration. The values of all properties contained in the specified configuration will be appended to this configuration. So if a property is already present in this configuration, its new value will be a union of the values in both configurations. Note: This method won't work well when appending hierarchical configurations because it is not able to copy information about the properties' structure (i.e. the parent-child-relationships will get lost). So when dealing with hierarchical configuration objects theirclone()
methods should be used.- Parameters:
c
- the configuration to be appended (can be null, then this operation will have no effect)- Since:
- 1.5
-
beginRead
Notifies this configuration'sSynchronizer
that a read operation is about to start. This method is called by all methods which access this configuration in a read-only mode. Subclasses may override it to perform additional actions before this read operation. The boolean optimize argument can be evaluated by overridden methods in derived classes. Some operations which require a lock do not need a fully initialized configuration object. By setting this flag to true, such operations can give a corresponding hint. An overridden implementation ofbeginRead()
can then decide to skip some initialization steps. All basic operations in this class (and most of the basicConfiguration
implementations) call this method with a parameter value of false. In any case the inherited method must be called! Otherwise, proper synchronization is not guaranteed.- Parameters:
optimize
- a flag whether optimization can be performed- Since:
- 2.0
-
beginWrite
Notifies this configuration'sSynchronizer
that an update operation is about to start. This method is called by all methods which modify this configuration. Subclasses may override it to perform additional operations before an update. For a description of the boolean optimize argument refer to the documentation ofbeginRead()
. In any case the inherited method must be called! Otherwise, proper synchronization is not guaranteed.- Parameters:
optimize
- a flag whether optimization can be performed- Since:
- 2.0
- See Also:
-
clear
Description copied from interface:Configuration
Remove all properties from the configuration.- Specified by:
clear
in interfaceConfiguration
-
clearInternal
Clears the whole configuration. This method is called byclear()
after some preparations have been made. This base implementation uses the iterator provided bygetKeys()
to remove every single property. Subclasses should override this method if there is a more efficient way of clearing the configuration. -
clearProperty
Removes the specified property from this configuration. This implementation performs some preparations and then delegates toclearPropertyDirect()
, which will do the real work.- Specified by:
clearProperty
in interfaceConfiguration
- Parameters:
key
- the key to be removed
-
clearPropertyDirect
Removes the specified property from this configuration. This method is called byclearProperty()
after it has done some preparations. It must be overridden in sub classes.- Parameters:
key
- the key to be removed
-
cloneInterpolator
Creates a clone of theConfigurationInterpolator
used by this instance. This method can be called byclone()
implementations of derived classes. Normally, theConfigurationInterpolator
of a configuration instance must not be shared with other instances because it contains a specificLookup
object pointing to the owning configuration. This has to be taken into account when cloning a configuration. This method creates a newConfigurationInterpolator
for this configuration instance which contains all lookup objects from the originalConfigurationInterpolator
except for the configuration specific lookup pointing to the passed in original configuration. This one is replaced by a correspondingLookup
referring to this configuration.- Parameters:
orgConfig
- the original configuration from which this one was cloned- Since:
- 2.0
-
contains
Checks if the specified value exists in the properties structure mapped by the provided keys.- Parameters:
keys
- an Iterator of String keys to search for the valuevalue
- the String value to search for in the properties- Returns:
- true if the value is found in the properties, false otherwise
- Since:
- 2.11.0
-
containsKey
Checks if the configuration contains the specified key. This implementation handles synchronization and delegates tocontainsKeyInternal()
.- Specified by:
containsKey
in interfaceImmutableConfiguration
- Parameters:
key
- the key whose presence in this configuration is to be tested- Returns:
true
if the configuration contains a value for this key,false
otherwise
-
containsKeyInternal
Actually checks whether the specified key is contained in this configuration. This method is called bycontainsKey()
. It has to be defined by concrete subclasses.- Parameters:
key
- the key in question- Returns:
- true if this key is contained in this configuration, false otherwise
- Since:
- 2.0
-
containsValue
Tests whether this configuration contains one or more matches to this value. This operation stops at first match but may be more expensive than thecontainsKey
method. This implementation handles synchronization and delegates tocontainsKeyInternal()
.- Specified by:
containsValue
in interfaceImmutableConfiguration
- Parameters:
value
- value whose presence in this configuration is to be tested- Returns:
true
if this configuration maps one or more keys to the specified value, false otherwise.- Since:
- 2.11.0
-
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 thecontainsKey
method.The implementation of this method will be different depending on the type of Configuration used.
Note that this method is identical in functionality to
containsValue
, (which is part of theImmutableConfiguration
interface).- Parameters:
value
- the value in question- Returns:
true
if and only if some key maps to thevalue
argument in this configuration as determined by theequals
method;false
otherwise.- Since:
- 2.11.0
-
copy
Copies the content of the specified configuration into this configuration. If the specified configuration contains a key that is also present in this configuration, the value of this key will be replaced by the new value. Note: This method won't work well when copying hierarchical configurations because it is not able to copy information about the properties' structure (i.e. the parent-child-relationships will get lost). So when dealing with hierarchical configuration objects theirclone()
methods should be used.- Parameters:
c
- the configuration to copy (can be null, then this operation will have no effect)- Since:
- 1.5
-
endRead
Notifies this configuration'sSynchronizer
that a read operation has finished. This method is called by all methods which access this configuration in a read-only manner at the end of their execution. Subclasses may override it to perform additional actions after this read operation. In any case the inherited method must be called! Otherwise, the read lock will not be released.- Since:
- 2.0
-
endWrite
Notifies this configuration'sSynchronizer
that an update operation has finished. This method is called by all methods which modify this configuration at the end of their execution. Subclasses may override it to perform additional operations after an update. In any case the inherited method must be called! Otherwise, the write lock will not be released.- Since:
- 2.0
-
get
Description copied from interface:ImmutableConfiguration
Gets an object of the specified type associated with the given configuration key. If the key doesn't map to an existing object, the method returns null unlessisThrowExceptionOnMissing()
is set totrue
.- Specified by:
get
in interfaceImmutableConfiguration
- Type Parameters:
T
- the target type of the value- Parameters:
cls
- the target class of the valuekey
- the key of the value- Returns:
- the value of the requested type for the key
-
get
Gets an object of the specified type associated with the given configuration key using a default value. If the key doesn't map to an existing object, the default value is returned. This implementation delegates to theConversionHandler
to perform the actual type conversion.- Specified by:
get
in interfaceImmutableConfiguration
- Type Parameters:
T
- the target type of the value- Parameters:
cls
- the target class of the valuekey
- the key of the valuedefaultValue
- the default value- Returns:
- the value of the requested type for the key
-
getArray
Description copied from interface:ImmutableConfiguration
Gets an array of typed objects associated with the given configuration key. If the key doesn't map to an existing object, an empty list is returned.- Specified by:
getArray
in interfaceImmutableConfiguration
- Parameters:
cls
- the type expected for the elements of the arraykey
- The configuration key.- Returns:
- The associated array if the key is found, and the value compatible with the type specified.
-
getArray
Gets an array of typed objects associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. This implementation delegates to theConversionHandler
to perform the actual type conversion. If this results in a null result (because the property is undefined), the default value is returned. It is checked whether the default value is an array with the correct component type. If not, an exception is thrown.- Specified by:
getArray
in interfaceImmutableConfiguration
- Parameters:
cls
- the type expected for the elements of the arraykey
- the configuration key.defaultValue
- the default value- Returns:
- The associated array if the key is found, and the value compatible with the type specified.
- Throws:
IllegalArgumentException
- if the default value is not a compatible array
-
getBigDecimal
Gets aBigDecimal
associated with the given configuration key.- Specified by:
getBigDecimal
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated BigDecimal if key is found and has valid format
- See Also:
-
getBigDecimal
Description copied from interface:ImmutableConfiguration
Gets aBigDecimal
associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getBigDecimal
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated BigDecimal if key is found and has valid format, default value otherwise.
-
getBigInteger
Gets aBigInteger
associated with the given configuration key.- Specified by:
getBigInteger
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated BigInteger if key is found and has valid format
- See Also:
-
getBigInteger
Description copied from interface:ImmutableConfiguration
Gets aBigInteger
associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getBigInteger
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated BigInteger if key is found and has valid format, default value otherwise.
-
getBoolean
Description copied from interface:ImmutableConfiguration
Gets a boolean associated with the given configuration key.- Specified by:
getBoolean
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated boolean.
-
getBoolean
Description copied from interface:ImmutableConfiguration
Gets a boolean associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getBoolean
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated boolean.
-
getBoolean
Obtains the value of the specified key and tries to convert it into aBoolean
object. If the property has no value, the passed in default value will be used.- Specified by:
getBoolean
in interfaceImmutableConfiguration
- Parameters:
key
- the key of the propertydefaultValue
- the default value- Returns:
- the value of this key converted to a
Boolean
- Throws:
ConversionException
- if the value cannot be converted to aBoolean
-
getByte
Description copied from interface:ImmutableConfiguration
Gets a byte associated with the given configuration key.- Specified by:
getByte
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated byte.
-
getByte
Description copied from interface:ImmutableConfiguration
Gets a byte associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getByte
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated byte.
-
getByte
Description copied from interface:ImmutableConfiguration
Gets aByte
associated with the given configuration key.- Specified by:
getByte
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated byte if key is found and has valid format, default value otherwise.
-
getCollection
Description copied from interface:ImmutableConfiguration
Gets a collection of typed objects associated with the given configuration key. This method works likeImmutableConfiguration.getCollection(Class, String, Collection, Collection)
passing in null as default value.- Specified by:
getCollection
in interfaceImmutableConfiguration
- Type Parameters:
T
- the element type of the result list- Parameters:
cls
- the element class of the result listkey
- the configuration keytarget
- the target collection (may be null)- Returns:
- the collection to which data was added
-
getCollection
public <T> Collection<T> getCollection(Class<T> cls, String key, Collection<T> target, Collection<T> defaultValue) Gets a collection of typed objects associated with the given configuration key using the values in the specified default collection if the key does not map to an existing object. This method is similar togetList()
, however, it allows specifying a target collection. Results are added to this collection. This is useful if the data retrieved should be added to a specific kind of collection, e.g. a set to remove duplicates. The return value is as follows:- If the key does not map to an existing object and the default value is null, the method returns null.
- If the target collection is not null and data has been added (either from the resolved property value or from the default collection), the target collection is returned.
- If the target collection is null and data has been added (either from the resolved property value or from the default collection), return value is the target collection created by this method.
ConversionHandler
to perform the actual conversion. If no target collection is provided, anArrayList
is created.- Specified by:
getCollection
in interfaceImmutableConfiguration
- Type Parameters:
T
- the element type of the result list- Parameters:
cls
- the element class of the result listkey
- the configuration keytarget
- the target collection (may be null)defaultValue
- the default value (may be null)- Returns:
- the collection to which data was added
-
getConfigurationDecoder
Gets theConfigurationDecoder
used by this instance.- Returns:
- the
ConfigurationDecoder
- Since:
- 2.0
-
getConversionHandler
Gets theConversionHandler
used by this instance.- Returns:
- the
ConversionHandler
- Since:
- 2.0
-
getDouble
Description copied from interface:ImmutableConfiguration
Gets a double associated with the given configuration key.- Specified by:
getDouble
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated double.
-
getDouble
Description copied from interface:ImmutableConfiguration
Gets a double associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getDouble
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated double.
-
getDouble
Description copied from interface:ImmutableConfiguration
Gets aDouble
associated with the given configuration key.- Specified by:
getDouble
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated double if key is found and has valid format, default value otherwise.
-
getDuration
Description copied from interface:ImmutableConfiguration
Gets aDuration
associated with the given configuration key.- Specified by:
getDuration
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated Duration if key is found and has valid format, default value otherwise.
-
getDuration
Description copied from interface:ImmutableConfiguration
Gets aDuration
associated with the given configuration key.- Specified by:
getDuration
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated Duration if key is found and has valid format, default value otherwise.
-
getEncodedString
Gets the value of a string property that is stored in encoded form in this configuration using a defaultConfigurationDecoder
. This method works like the method with the same name, but it uses a defaultConfigurationDecoder
associated with this configuration. It depends on a specific implementation how this default decoder is obtained. This implementation makes use of theConfigurationDecoder
set for this configuration. If no such object has been set, anIllegalStateException
exception is thrown.- Specified by:
getEncodedString
in interfaceImmutableConfiguration
- Parameters:
key
- the configuration key- Returns:
- the plain string value of the specified encoded property
- Throws:
IllegalStateException
- if noConfigurationDecoder
is set- See Also:
-
getEncodedString
Gets the value of a string property that is stored in encoded form in this configuration. This method obtains the value of the string property identified by the given key. This value is then passed to the providedConfigurationDecoder
. The value returned by theConfigurationDecoder
is passed to the caller. If the key is not associated with a value, the decoder is not invoked; depending on this configuration's settings either null is returned or an exception is thrown. This implementation delegates togetString(String)
in order to obtain the value of the passed in key. This value is passed to the decoder. BecausegetString()
is used behind the scenes all standard features like handling of missing keys and interpolation work as expected.- Specified by:
getEncodedString
in interfaceImmutableConfiguration
- Parameters:
key
- the configuration keydecoder
- theConfigurationDecoder
(must not be null)- Returns:
- the plain string value of the specified encoded property
-
getFloat
Description copied from interface:ImmutableConfiguration
Gets a float associated with the given configuration key.- Specified by:
getFloat
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated float.
-
getFloat
Description copied from interface:ImmutableConfiguration
Gets a float associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getFloat
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated float.
-
getFloat
Description copied from interface:ImmutableConfiguration
Gets aFloat
associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getFloat
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated float if key is found and has valid format, default value otherwise.
-
getInt
Description copied from interface:ImmutableConfiguration
Gets a int associated with the given configuration key.- Specified by:
getInt
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated int.
-
getInt
Description copied from interface:ImmutableConfiguration
Gets a int associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getInt
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated int.
-
getInteger
Description copied from interface:ImmutableConfiguration
Gets anInteger
associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getInteger
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated int if key is found and has valid format, default value otherwise.
-
getInterpolator
Gets theConfigurationInterpolator
object that manages the lookup objects for resolving variables. Unless a custom interpolator has been set or the instance has been modified, the returned interpolator will resolve values from this configuration instance and support thedefault prefix lookups
.- Specified by:
getInterpolator
in interfaceConfiguration
- Returns:
- the
ConfigurationInterpolator
associated with this configuration - Since:
- 1.4
- See Also:
-
getKeys
Gets the list of the keys contained in the configuration. The returned iterator can be used to obtain all defined keys. It does not allow removing elements from this configuration via itsremove()
method. Note that the keys of this configuration are returned in a form, so that they can be directly evaluated; escaping of special characters (if necessary) has already been performed. This implementation takes care of synchronization and then delegates togetKeysInternal()
for obtaining the actual iterator. Note that depending on a concrete implementation, an iteration may fail if the configuration is updated concurrently.- Specified by:
getKeys
in interfaceImmutableConfiguration
- Returns:
- An Iterator.
-
getKeys
Gets the list of the keys contained in the configuration that match the specified prefix. For instance, if the configuration contains the following keys:
db.user, db.pwd, db.url, window.xpos, window.ypos
,
an invocation ofgetKeys("db");
will return the keys below:
db.user, db.pwd, db.url
.
Note that the prefix itself is included in the result set if there is a matching key. The exact behavior - how the prefix is actually interpreted - depends on a concrete implementation. This implementation returns keys that either match the prefix or start with the prefix followed by a dot ('.'). So the callgetKeys("db");
will find the keysdb
,db.user
, ordb.password
, but not the keydbdriver
.- Specified by:
getKeys
in interfaceImmutableConfiguration
- Parameters:
prefix
- The prefix to test against.- Returns:
- An Iterator of keys that match the prefix.
- See Also:
-
getKeys
Gets the list of the keys contained in the configuration that match the specified prefix. For instance, if the configuration contains the following keys:
db@user, db@pwd, db@url, window.xpos, window.ypos
,
an invocation ofgetKeys("db","@");
will return the keys below:
db@user, db@pwd, db@url
.
Note that the prefix itself is included in the result set if there is a matching key. The exact behavior - how the prefix is actually interpreted - depends on a concrete implementation. This implementation returns keys that either match the prefix or start with the prefix followed by the delimiter. So the callgetKeys("db");
will find the keysdb
,db@user
, ordb@password
, but not the keydbdriver
.- Specified by:
getKeys
in interfaceImmutableConfiguration
- Parameters:
prefix
- The prefix to test against.delimiter
- The prefix delimiter.- Returns:
- An Iterator of keys that match the prefix.
- See Also:
-
getKeysInternal
Actually creates an iterator for iterating over the keys in this configuration. This method is called bygetKeys()
, it has to be defined by concrete subclasses.- Returns:
- an
Iterator
with all property keys in this configuration - Since:
- 2.0
-
getKeysInternal
Gets anIterator
with all property keys starting with the specified prefix. This method is called bygetKeys(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.- Parameters:
prefix
- the prefix for the keys to be taken into account- Returns:
- an
Iterator
returning the filtered keys - Since:
- 2.0
-
getKeysInternal
Gets anIterator
with all property keys starting with the specified prefix and specified delimiter. This method is called bygetKeys(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.- Parameters:
prefix
- the prefix for the keys to be taken into accountdelimiter
- the prefix delimiter- Returns:
- an
Iterator
returning the filtered keys - Since:
- 2.10.0
-
getList
Description copied from interface:ImmutableConfiguration
Gets a list of typed objects associated with the given configuration key returning a null if the key doesn't map to an existing object.- Specified by:
getList
in interfaceImmutableConfiguration
- Type Parameters:
T
- the type expected for the elements of the list- Parameters:
cls
- the class expected for the elements of the listkey
- The configuration key.- Returns:
- The associated list if the key is found.
-
getList
Gets a list of typed objects associated with the given configuration key returning the specified default value if the key doesn't map to an existing object. This method recursively retrieves all values stored for the passed in key, i.e. if one of these values is again a complex object like an array or a collection (which may be the case for some concrete subclasses), all values are extracted and added to the resulting list - performing a type conversion if necessary. This implementation delegates to the genericgetCollection()
. As target collection a newly createdArrayList
is passed in.- Specified by:
getList
in interfaceImmutableConfiguration
- Type Parameters:
T
- the type expected for the elements of the list- Parameters:
cls
- the class expected for the elements of the listkey
- the configuration key.defaultValue
- the default value.- Returns:
- The associated List.
-
getList
Gets a List of the values associated with the given configuration key. This method is different from the genericgetList()
method in that it does not recursively obtain all values stored for the specified property key. Rather, only the first level of the hierarchy is processed. So the resulting list may contain complex objects like arrays or collections - depending on the storage structure used by a concrete subclass. If the key doesn't map to an existing object, an empty List is returned.- Specified by:
getList
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated List.
- See Also:
-
getList
Description copied from interface:ImmutableConfiguration
Gets a List of strings associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getList
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated List of strings.
- See Also:
-
getListDelimiterHandler
Gets theListDelimiterHandler
used by this instance.- Returns:
- the
ListDelimiterHandler
- Since:
- 2.0
-
getLogger
Gets the logger used by this configuration object.- Returns:
- the logger
- Since:
- 2.0
-
getLong
Description copied from interface:ImmutableConfiguration
Gets a long associated with the given configuration key.- Specified by:
getLong
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated long.
-
getLong
Description copied from interface:ImmutableConfiguration
Gets a long associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getLong
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated long.
-
getLong
Description copied from interface:ImmutableConfiguration
Gets aLong
associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getLong
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated long if key is found and has valid format, default value otherwise.
-
getProperties
Description copied from interface:ImmutableConfiguration
Gets a list of properties associated with the given configuration key. This method expects the given key to have an arbitrary number of String values, each of which is of the formkey=value
. These strings are split at the equals sign, and the key parts will become keys of the returnedProperties
object, the value parts become values.- Specified by:
getProperties
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated properties if key is found.
-
getProperties
Gets a list of properties associated with the given configuration key.- Parameters:
key
- The configuration key.defaults
- Any default values for the returnedProperties
object. Ignored ifnull
.- Returns:
- The associated properties if key is found.
- Throws:
ConversionException
- is thrown if the key maps to an object that is not a String/List of Strings.IllegalArgumentException
- if one of the tokens is malformed (does not contain an equals sign).
-
getProperty
Gets a property from the configuration. This is the most basic get method for retrieving values of properties. In a typical implementation of theConfiguration
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 theConfiguration
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). This implementation ensures proper synchronization. Subclasses have to define the abstractgetPropertyInternal()
method which is called from here.- Specified by:
getProperty
in interfaceImmutableConfiguration
- Parameters:
key
- property to retrieve- Returns:
- the value to which this configuration maps the specified key, or null if the configuration contains no mapping for this key.
-
getPropertyInternal
Actually 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.- Parameters:
key
- the key of the property in question- Returns:
- the (raw) value of this property
- Since:
- 2.0
-
getShort
Description copied from interface:ImmutableConfiguration
Gets a short associated with the given configuration key.- Specified by:
getShort
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated short.
-
getShort
Description copied from interface:ImmutableConfiguration
Gets a short associated with the given configuration key.- Specified by:
getShort
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated short.
-
getShort
Description copied from interface:ImmutableConfiguration
Gets aShort
associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getShort
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated short if key is found and has valid format, default value otherwise.
-
getString
Gets a string associated with the given configuration key.- Specified by:
getString
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated string.
- See Also:
-
getString
Description copied from interface:ImmutableConfiguration
Gets a string associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned.- Specified by:
getString
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.defaultValue
- The default value.- Returns:
- The associated string if key is found and has valid format, default value otherwise.
-
getStringArray
Gets an array of strings associated with the given configuration key. If the key doesn't map to an existing object, an empty array is returned. When a property is added to a configuration, it is checked whether it contains multiple values. This is obvious if the added object is a list or an array. For strings the associationListDelimiterHandler
is consulted to find out whether the string can be split into multiple values.- Specified by:
getStringArray
in interfaceImmutableConfiguration
- Parameters:
key
- The configuration key.- Returns:
- The associated string array if key is found.
- Throws:
ConversionException
- is thrown if the key maps to an object that is not a String/List of Strings.- See Also:
-
getSynchronizer
Gets the object responsible for synchronizing this configuration. All access to this configuration - both read and write access - is controlled by this object. This implementation never returns null. If noSynchronizer
has been set, aNoOpSynchronizer
is returned. So, per default, instances ofAbstractConfiguration
are not thread-safe unless a suitableSynchronizer
is set!- Specified by:
getSynchronizer
in interfaceSynchronizerSupport
- Returns:
- the
Synchronizer
used by this instance - Since:
- 2.0
-
immutableSubset
Description copied from interface:ImmutableConfiguration
Return a decorator immutable 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 immutable Configuration returned bysubset("prefix")
will contain the properties:number = 1 string = Apache = Jakarta
(The key for the value "Jakarta" is an empty string)- Specified by:
immutableSubset
in interfaceImmutableConfiguration
- Parameters:
prefix
- The prefix used to select the properties.- Returns:
- a subset immutable configuration
-
initLogger
Initializes the logger. Supports null input. This method can be called by derived classes in order to enable logging.- Parameters:
log
- the logger- Since:
- 2.0
-
installInterpolator
public final void installInterpolator(Map<String, ? extends Lookup> prefixLookups, Collection<? extends Lookup> defLookups) Creates and installs a newConfigurationInterpolator
for thisConfiguration
based on the passed in arguments. This method creates a defaultConfigurationInterpolator
instance and initializes it with the passed inLookup
objects. It also adds a special defaultLookup
object that tries to resolve variables by matching them with properties contained in thisConfiguration
. This is also the main difference to theConfiguration.setInterpolator(ConfigurationInterpolator)
method which sets the passed in object as is without adding this special lookup. This implementation creates a newConfigurationInterpolator
instance and initializes it with the givenLookup
objects. In addition, it adds a specialized defaultLookup
object which queries thisConfiguration
.- Specified by:
installInterpolator
in interfaceConfiguration
- Parameters:
prefixLookups
- the map withLookup
objects associated with specific prefixes (can be null)defLookups
- a collection with defaultLookup
objects (can be null)- Since:
- 2.0
- See Also:
-
interpolate
Returns the interpolated value. This implementation delegates to the currentConfigurationInterpolator
. If noConfigurationInterpolator
is set, the passed in value is returned without changes.- Parameters:
value
- the value to interpolate- Returns:
- the value with variables substituted
-
interpolate
interpolate key names to handle ${key} stuff- Parameters:
base
- string to interpolate- Returns:
- returns the key name with the ${key} substituted
-
interpolatedConfiguration
Returns a configuration with the same content as this configuration, but with all variables replaced by their actual values. This method tries to clone the configuration and then perform interpolation on all properties. So property values of the form${var}
will be resolved as far as possible (if a variable cannot be resolved, it remains unchanged). This operation is useful if the content of a configuration is to be exported or processed by an external component that does not support variable interpolation.- Returns:
- a configuration with all variables interpolated
- Throws:
ConfigurationRuntimeException
- if this configuration cannot be cloned- Since:
- 1.5
-
isEmpty
Checks if the configuration is empty. This implementation handles synchronization and delegates toisEmptyInternal()
.- Specified by:
isEmpty
in interfaceImmutableConfiguration
- Returns:
true
if the configuration contains no property,false
otherwise.
-
isEmptyInternal
Actually checks whether this configuration contains data. This method is called byisEmpty()
. It has to be defined by concrete subclasses.- Returns:
- true if this configuration contains no data, false otherwise
- Since:
- 2.0
-
isScalarValue
Checks whether the specified object is a scalar value. This method is called bygetList()
andgetStringArray()
if the property requested is not a string, a list, or an array. If it returns true, the calling method transforms the value to a string and returns a list or an array with this single element. This implementation returns true if the value is of a wrapper type for a primitive type.- Parameters:
value
- the value to be checked- Returns:
- a flag whether the value is a scalar
- Since:
- 1.7
-
isThrowExceptionOnMissing
Returns true if missing values throw Exceptions.- Returns:
- true if missing values throw Exceptions
-
lock
Locks this object for the specified mode. This call may block until this object is released from other lock operations. When it returns the caller can access the object in a way compatible to the specifiedLockMode
. When done theunlock()
must be called with the sameLockMode
argument. In practice, a try-finally construct should be used as in the following example:SynchronizerSupport syncSupport = ...; syncSupport.lock(LockMode.READ); try { // read access to syncSupport } finally { syncSupport.unlock(LockMode.READ); }
Note: Always use this method for obtaining a lock rather than accessing the object'sSynchronizer
directly. An implementation may perform additional actions which are not executed when only interacting with theSynchronizer
. This implementation delegates tobeginRead()
orbeginWrite()
, depending on theLockMode
argument. Subclasses can override these protected methods to perform additional steps when a configuration is locked.- Specified by:
lock
in interfaceSynchronizerSupport
- Parameters:
mode
- theLockMode
- Throws:
NullPointerException
- if the argument is null- Since:
- 2.0
-
setConfigurationDecoder
Sets theConfigurationDecoder
for this configuration. This object is used bygetEncodedString(String)
.- Parameters:
configurationDecoder
- theConfigurationDecoder
- Since:
- 2.0
-
setConversionHandler
Sets theConversionHandler
to be used by this instance. TheConversionHandler
is responsible for every kind of data type conversion. It is consulted by all get methods returning results in specific data types. A newly created configuration uses a defaultConversionHandler
implementation. This can be changed while initializing the configuration (e.g. via a builder). Note that access to this property is not synchronized.- Parameters:
conversionHandler
- theConversionHandler
to be used (must not be null)- Throws:
IllegalArgumentException
- if theConversionHandler
is null- Since:
- 2.0
-
setDefaultLookups
Adds allLookup
objects in the given collection as default lookups (i.e. lookups without a variable prefix) to theConfigurationInterpolator
object of this configuration. In addition, it adds a specialized defaultLookup
object which queries thisConfiguration
. The set ofLookup
objects with prefixes is not modified by this method. If this configuration does not have aConfigurationInterpolator
, a new instance is created. Note: This method is mainly intended to be used for initializing a configuration when it is created by a builder. Normal client code should better callinstallInterpolator(Map, Collection)
to define theConfigurationInterpolator
in a single step.- Parameters:
lookups
- the collection with defaultLookup
objects to be added- Since:
- 2.0
-
setInterpolator
Sets theConfigurationInterpolator
object to be used by thisConfiguration
. This object is invoked for each access of a string property in order to substitute variables which may be contained. The argument can be null to disable interpolation at all. This implementation sets the passed in object without further modifications. A null argument is allowed; this disables interpolation.- Specified by:
setInterpolator
in interfaceConfiguration
- Parameters:
ci
- the newConfigurationInterpolator
- Since:
- 2.0
-
setListDelimiterHandler
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, aListDelimiterHandler
implementation is set which does not support list splitting. This can be changed for instance by setting aDefaultListDelimiterHandler
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.
- Parameters:
listDelimiterHandler
- theListDelimiterHandler
to be used (must not be null)- Throws:
IllegalArgumentException
- if theListDelimiterHandler
is null- Since:
- 2.0
-
setLogger
Allows setting the logger to be used by this configuration object. This method makes it possible for clients to exactly control logging behavior. Per default a logger is set that will ignore all log messages. Derived classes that want to enable logging should call this method during their initialization with the logger to be used. It is legal to pass a null logger; in this case, logging will be disabled.- Parameters:
log
- the new logger- Since:
- 2.0
-
setParentInterpolator
Sets the specifiedConfigurationInterpolator
as the parent of this configuration'sConfigurationInterpolator
. If this configuration does not have aConfigurationInterpolator
, a new instance is created. Note: This method is mainly intended to be used for initializing a configuration when it is created by a builder. Normal client code can directly update theConfigurationInterpolator
.- Parameters:
parent
- the parentConfigurationInterpolator
to be set- Since:
- 2.0
-
setPrefixLookups
Registers allLookup
objects in the given map at the currentConfigurationInterpolator
of this configuration. The set of default lookup objects (for variables without a prefix) is not modified by this method. If this configuration does not have aConfigurationInterpolator
, a new instance is created. Note: This method is mainly intended to be used for initializing a configuration when it is created by a builder. Normal client code should better callinstallInterpolator(Map, Collection)
to define theConfigurationInterpolator
in a single step.- Parameters:
lookups
- a map with newLookup
objects and their prefixes (may be null)- Since:
- 2.0
-
setProperty
Description copied from interface:Configuration
Sets 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 interfaceConfiguration
- Parameters:
key
- The key of the property to changevalue
- The new value
-
setPropertyInternal
Actually sets the value of a property. This method is called bysetProperty()
. It provides a default implementation of this functionality by clearing the specified key and delegating toaddProperty()
. Subclasses should override this method if they can provide a more efficient algorithm for setting a property value.- Parameters:
key
- the property keyvalue
- the new property value- Since:
- 2.0
-
setSynchronizer
Sets the object responsible for synchronizing this configuration. This method has to be called with a suitableSynchronizer
object when initializing this configuration instance in order to make it thread-safe.- Specified by:
setSynchronizer
in interfaceSynchronizerSupport
- Parameters:
synchronizer
- the newSynchronizer
; can be null, then this instance uses aNoOpSynchronizer
- Since:
- 2.0
-
setThrowExceptionOnMissing
Allows to set thethrowExceptionOnMissing
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 aNoSuchElementException
exception. Note that getter methods for primitive data types are not affected by this flag.- Parameters:
throwExceptionOnMissing
- The new value for the property
-
size
Returns the number of keys stored in this configuration. Note that a concrete implementation is not guaranteed to be efficient; for some implementations it may be expensive to determine the size. Especially, if you just want to check whether a configuration is empty, it is preferable to use theImmutableConfiguration.isEmpty()
method. This implementation handles synchronization and delegates tosizeInternal()
.- Specified by:
size
in interfaceImmutableConfiguration
- Returns:
- the number of keys stored in this configuration
-
sizeInternal
Actually calculates the size of this configuration. This method is called bysize()
with a read lock held. The base implementation provided here calculates the size based on the iterator returned bygetKeys()
. Sub classes which can determine the size in a more efficient way should override this method.- Returns:
- the size of this configuration (i.e. the number of keys)
-
subset
Description copied from interface:Configuration
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 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:
subset
in interfaceConfiguration
- Parameters:
prefix
- The prefix used to select the properties.- Returns:
- a subset configuration
- See Also:
-
unlock
Releases a lock of this object that was obtained using theSynchronizerSupport.lock(LockMode)
method. This method must always be called pair-wise withlock()
. The argument must match to the one passed to the correspondinglock()
call; otherwise, the behavior of theSynchronizer
is unspecified. This implementation delegates toendRead()
orendWrite()
, depending on theLockMode
argument. Subclasses can override these protected methods to perform additional steps when a configuration's lock is released.- Specified by:
unlock
in interfaceSynchronizerSupport
- Parameters:
mode
- theLockMode
- Throws:
NullPointerException
- if the argument is null
-