org.apache.commons.configuration2

## Interface Configuration

- All Superinterfaces:
    ImmutableConfiguration, SynchronizerSupport
  All Known Subinterfaces:
    FileBasedConfiguration, HierarchicalConfiguration<T>
  All Known Implementing Classes:
    AbstractConfiguration, AbstractHierarchicalConfiguration, AppletConfiguration, BaseConfiguration, BaseHierarchicalConfiguration, CombinedConfiguration, CompositeConfiguration, DatabaseConfiguration, DataConfiguration, DynamicCombinedConfiguration, EnvironmentConfiguration, INIConfiguration, JNDIConfiguration, MapConfiguration, PatternSubtreeConfigurationWrapper, PropertiesConfiguration, PropertyListConfiguration, ServletConfiguration, ServletContextConfiguration, ServletFilterConfiguration, ServletRequestConfiguration, SubnodeConfiguration, SubsetConfiguration, SystemConfiguration, XMLConfiguration, XMLPropertiesConfiguration, XMLPropertyListConfiguration

      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.

  Version:
    $Id: Configuration.java 1624601 2014-09-12 18:04:36Z oheger $
  Author:
    Commons Configuration team

- - ### Method Summary

    Methods
    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.

    - ### 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, 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`

    - ### Methods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport

      `getSynchronizer, lock, setSynchronizer, unlock`

- - ### Method Detail

    - #### subset

          Configuration subset(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 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.

      Parameters:
        `prefix` - The prefix used to select the properties.
      Returns:
        a subset configuration
      See Also:
        `SubsetConfiguration`

    - #### addProperty

          void addProperty(String key,
                         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 call

          addProperty("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.

    - #### setProperty

          void setProperty(String key,
                         Object value)

      Set 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 change
        `value` - The new value

    - #### clearProperty

          void clearProperty(String key)

      Remove a property from the configuration.
      Parameters:
        `key` - the key to remove along with corresponding value.

    - #### clear

          void clear()

      Remove all properties from the configuration.

    - #### getInterpolator

          ConfigurationInterpolator getInterpolator()

      Returns the `ConfigurationInterpolator` object used by this `Configuration`. This object is responsible for variable substitution.
      Returns:
        the `ConfigurationInterpolator` (can be null)

    - #### setInterpolator

          void setInterpolator(ConfigurationInterpolator ci)

      Sets the `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.
      Parameters:
        `ci` - the new `ConfigurationInterpolator`

    - #### installInterpolator

          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. 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 `#setConfigurationInterpolator(ConfigurationInterpolator)` method which sets the passed in object as is without adding this special lookup.
      Parameters:
        `prefixLookups` - the map with `Lookup` objects associated with specific prefixes (can be null)
        `defLookups` - a collection with default `Lookup` objects (can be null)
      See Also:
        `ConfigurationInterpolator`

Copyright © 2001–2014 The Apache Software Foundation. All rights reserved.