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
public interface Configuration extends ImmutableConfiguration, SynchronizerSupport
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, aConversionException
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 thesetThrowExceptionOnMissing()
method, with which it can be configured to throw aNoSuchElementException
exception in that case. (Note that getter methods for primitive types inAbstractConfiguration
always throw an exception for missing properties because there is no way of overloading the return value.)With the
addProperty()
andsetProperty()
methods new properties can be added to a configuration or the values of properties can be changed. WithclearProperty()
a property can be removed. Other methods allow to iterate over the contained properties or to create a subset configuration.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addProperty(java.lang.String key, java.lang.Object value)
Add a property to the configuration.void
clear()
Remove all properties from the configuration.void
clearProperty(java.lang.String key)
Remove a property from the configuration.ConfigurationInterpolator
getInterpolator()
Gets theConfigurationInterpolator
object used by thisConfiguration
.void
installInterpolator(java.util.Map<java.lang.String,? extends Lookup> prefixLookups, java.util.Collection<? extends Lookup> defLookups)
Creates and installs a newConfigurationInterpolator
for thisConfiguration
based on the passed in arguments.void
setInterpolator(ConfigurationInterpolator ci)
Sets theConfigurationInterpolator
object to be used by thisConfiguration
.void
setProperty(java.lang.String key, java.lang.Object value)
Sets a property, this will replace any previously set values.Configuration
subset(java.lang.String prefix)
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, 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 Detail
-
addProperty
void addProperty(java.lang.String key, java.lang.Object value)
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
void clearProperty(java.lang.String key)
Remove a property from the configuration.- Parameters:
key
- the key to remove along with corresponding value.
-
getInterpolator
ConfigurationInterpolator getInterpolator()
Gets theConfigurationInterpolator
object used by thisConfiguration
. This object is responsible for variable substitution.- Returns:
- the
ConfigurationInterpolator
(can be null)
-
installInterpolator
void installInterpolator(java.util.Map<java.lang.String,? extends Lookup> prefixLookups, java.util.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:
ConfigurationInterpolator
-
setInterpolator
void setInterpolator(ConfigurationInterpolator ci)
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
void setProperty(java.lang.String key, java.lang.Object value)
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
Configuration subset(java.lang.String prefix)
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:
SubsetConfiguration
-
-