Interface Configuration
- All Superinterfaces:
ImmutableConfiguration
,SynchronizerSupport
- All Known Subinterfaces:
FileBasedConfiguration
,HierarchicalConfiguration<T>
- All Known Implementing Classes:
AbstractConfiguration
,AbstractHierarchicalConfiguration
,AbstractYAMLBasedConfiguration
,AppletConfiguration
,BaseConfiguration
,BaseHierarchicalConfiguration
,CombinedConfiguration
,CompositeConfiguration
,DatabaseConfiguration
,DataConfiguration
,DynamicCombinedConfiguration
,EnvironmentConfiguration
,INIConfiguration
,JNDIConfiguration
,JSONConfiguration
,MapConfiguration
,PatternSubtreeConfigurationWrapper
,PropertiesConfiguration
,PropertyListConfiguration
,ServletConfiguration
,ServletContextConfiguration
,ServletFilterConfiguration
,ServletRequestConfiguration
,SubnodeConfiguration
,SubsetConfiguration
,SystemConfiguration
,XMLConfiguration
,XMLPropertiesConfiguration
,XMLPropertyListConfiguration
,YAMLConfiguration
The main Configuration interface.
This interface allows accessing and manipulating a configuration object. The major part of the methods defined in
this interface deals with accessing properties of various data types. There is a generic getProperty()
method, which returns the value of the queried property in its raw data type. Other getter methods try to convert
this raw data type into a specific data type. If this fails, a ConversionException
will be thrown.
For most of the property getter methods an overloaded version exists that allows to specify a default value, which
will be returned if the queried property cannot be found in the configuration. The behavior of the methods that do
not take a default value in case of a missing property is not defined by this interface and depends on a concrete
implementation. E.g. the AbstractConfiguration
class, which is the base class of most configuration
implementations provided by this package, per default returns null if a property is not found, but provides
the setThrowExceptionOnMissing()
method, with which
it can be configured to throw a NoSuchElementException
exception in that case. (Note that getter methods for
primitive types in AbstractConfiguration
always throw an exception for missing properties because there is no
way of overloading the return value.)
With the addProperty()
and setProperty()
methods new properties can be added to a configuration or
the values of properties can be changed. With clearProperty()
a property can be removed. Other methods allow
to iterate over the contained properties or to create a subset configuration.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addProperty
(String key, Object value) Add a property to the configuration.void
clear()
Remove all properties from the configuration.void
clearProperty
(String key) Remove a property from the configuration.Gets theConfigurationInterpolator
object used by thisConfiguration
.void
installInterpolator
(Map<String, ? extends Lookup> prefixLookups, Collection<? extends Lookup> defLookups) Creates and installs a newConfigurationInterpolator
for thisConfiguration
based on the passed in arguments.void
Sets theConfigurationInterpolator
object to be used by thisConfiguration
.void
setProperty
(String key, Object value) Sets a property, this will replace any previously set values.Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix.Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
containsKey, containsValue, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getEnum, getEnum, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getKeys, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, size
Methods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport
getSynchronizer, lock, setSynchronizer, unlock
-
Method Details
-
addProperty
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"]
- Parameters:
key
- The key to add the property to.value
- The value to add.
-
clear
void clear()Remove all properties from the configuration. -
clearProperty
Remove a property from the configuration.- Parameters:
key
- the key to remove along with corresponding value.
-
getInterpolator
Gets theConfigurationInterpolator
object used by thisConfiguration
. This object is responsible for variable substitution.- Returns:
- the
ConfigurationInterpolator
(can be null)
-
installInterpolator
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 thesetInterpolator(ConfigurationInterpolator)
method which sets the passed in object as is without adding this special lookup.- Parameters:
prefixLookups
- the map withLookup
objects associated with specific prefixes (can be null)defLookups
- a collection with defaultLookup
objects (can be null)- See Also:
-
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.- Parameters:
ci
- the newConfigurationInterpolator
-
setProperty
Sets a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key, value).- Parameters:
key
- The key of the property to changevalue
- The new value
-
subset
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.
- Parameters:
prefix
- The prefix used to select the properties.- Returns:
- a subset configuration
- See Also:
-