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, 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.
Modifier and Type | Method and Description |
---|---|
void |
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.
|
ConfigurationInterpolator |
getInterpolator()
Returns the
ConfigurationInterpolator object used by this
Configuration . |
void |
installInterpolator(Map<String,? extends Lookup> prefixLookups,
Collection<? extends Lookup> defLookups)
Creates and installs a new
ConfigurationInterpolator for this
Configuration based on the passed in arguments. |
void |
setInterpolator(ConfigurationInterpolator ci)
Sets the
ConfigurationInterpolator object to be used by this
Configuration . |
void |
setProperty(String key,
Object value)
Set a property, this will replace any previously set values.
|
Configuration |
subset(String prefix)
Return a decorator Configuration containing every key from the current
Configuration that starts with the specified prefix.
|
containsKey, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, size
getSynchronizer, lock, setSynchronizer, unlock
Configuration subset(String prefix)
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.
prefix
- The prefix used to select the properties.SubsetConfiguration
void addProperty(String key, Object value)
resource.loader = fileis already present in the configuration and you call
addProperty("resource.loader", "classpath")Then you will end up with a List like the following:
["file", "classpath"]
key
- The key to add the property to.value
- The value to add.void setProperty(String key, Object value)
key
- The key of the property to changevalue
- The new valuevoid clearProperty(String key)
key
- the key to remove along with corresponding value.void clear()
ConfigurationInterpolator getInterpolator()
ConfigurationInterpolator
object used by this
Configuration
. This object is responsible for variable
substitution.ConfigurationInterpolator
(can be null)void setInterpolator(ConfigurationInterpolator ci)
ConfigurationInterpolator
object to be used by this
Configuration
. 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.ci
- the new ConfigurationInterpolator
void installInterpolator(Map<String,? extends Lookup> prefixLookups, Collection<? extends Lookup> defLookups)
ConfigurationInterpolator
for this
Configuration
based on the passed in arguments. This method
creates a default ConfigurationInterpolator
instance and
initializes it with the passed in Lookup
objects. It also adds a
special default Lookup
object that tries to resolve variables by
matching them with properties contained in this Configuration
.
This is also the main difference to the
setInterpolator(ConfigurationInterpolator)
method
which sets the passed in object as is without adding this special lookup.prefixLookups
- the map with Lookup
objects associated with
specific prefixes (can be null)defLookups
- a collection with default Lookup
objects (can
be null)ConfigurationInterpolator
Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.