org.apache.commons.configuration
public abstract class AbstractConfiguration extends EventSource implements Configuration
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
feauters implemented here:
Configuration
interface are already handled by this base class.
A concrete sub class only needs to provide a generic getProperty()
method.${var}
) will be replaced by their
corresponding values.setListDelimiter()
method the delimiter character can be
specified; per default a comma is used. The
setDelimiterParsingDisabled()
method can be used to disable
list splitting completely.)setThrowExceptionOnMissing()
method this behavior can be
changed to throw an exception when a requested property cannot be found.EVENT_XXX
constants to get an impression about which event types are supported.
Version: $Id: AbstractConfiguration.java,v 1.29 2004/12/02 22:05:52 ebourg Exp $
Field Summary | |
---|---|
static char | defaultListDelimiter The default value for listDelimiter |
boolean | delimiterParsingDisabled
When set to true the given configuration delimiter will not be used
while parsing for this configuration. |
protected static String | END_TOKEN end token |
static int | EVENT_ADD_PROPERTY
Constant for the add property event type. |
static int | EVENT_CLEAR
Constant for the clear configuration event type. |
static int | EVENT_CLEAR_PROPERTY
Constant for the clear property event type. |
static int | EVENT_READ_PROPERTY
Constant for the get property event type. |
static int | EVENT_SET_PROPERTY
Constant for the set property event type. |
char | listDelimiter Delimiter used to convert single values to lists |
Log | log Stores the logger. |
StrSubstitutor | substitutor Stores a reference to the object that handles variable interpolation. |
protected static String | START_TOKEN start token |
boolean | throwExceptionOnMissing
Whether the configuration should throw NoSuchElementExceptions or simply
return null when a property does not exist. |
Constructor Summary | |
---|---|
AbstractConfiguration()
Creates a new instance of AbstractConfiguration . |
Method Summary | |
---|---|
void | addErrorLogListener()
Adds a special
ConfigurationErrorListener
object to this configuration that will log all internal errors. |
void | addProperty(String key, Object value) |
protected abstract void | addPropertyDirect(String key, Object value)
Adds a key/value pair to the Configuration. |
void | clear() |
void | clearProperty(String key)
Removes the specified property from this configuration. |
protected void | clearPropertyDirect(String key)
Removes the specified property from this configuration. |
abstract boolean | containsKey(String key) |
protected ConfigurationInterpolator | createInterpolator()
Creates the interpolator object that is responsible for variable
interpolation. |
BigDecimal | getBigDecimal(String key) |
BigDecimal | getBigDecimal(String key, BigDecimal defaultValue) |
BigInteger | getBigInteger(String key) |
BigInteger | getBigInteger(String key, BigInteger defaultValue) |
boolean | getBoolean(String key) |
boolean | getBoolean(String key, boolean defaultValue) |
Boolean | getBoolean(String key, Boolean defaultValue)
Obtains the value of the specified key and tries to convert it into a
Boolean object. |
byte | getByte(String key) |
byte | getByte(String key, byte defaultValue) |
Byte | getByte(String key, Byte defaultValue) |
static char | getDefaultListDelimiter()
Retrieve the current delimiter. |
static char | getDelimiter()
Returns the default list delimiter.
|
double | getDouble(String key) |
double | getDouble(String key, double defaultValue) |
Double | getDouble(String key, Double defaultValue) |
float | getFloat(String key) |
float | getFloat(String key, float defaultValue) |
Float | getFloat(String key, Float defaultValue) |
int | getInt(String key) |
int | getInt(String key, int defaultValue) |
Integer | getInteger(String key, Integer defaultValue) |
ConfigurationInterpolator | getInterpolator()
Returns the ConfigurationInterpolator object that manages
the lookup objects for resolving variables. |
abstract Iterator | getKeys() |
Iterator | getKeys(String prefix) |
List | getList(String key) |
List | getList(String key, List defaultValue) |
char | getListDelimiter()
Retrieve the delimiter for this configuration. |
Log | getLogger()
Returns the logger used by this configuration object.
|
long | getLong(String key) |
long | getLong(String key, long defaultValue) |
Long | getLong(String key, Long defaultValue) |
Properties | getProperties(String key) |
Properties | getProperties(String key, Properties defaults)
Get a list of properties associated with the given configuration key.
|
short | getShort(String key) |
short | getShort(String key, short defaultValue) |
Short | getShort(String key, Short defaultValue) |
String | getString(String key) |
String | getString(String key, String defaultValue) |
String[] | getStringArray(String key)
Get an array of strings associated with the given configuration key.
|
StrSubstitutor | getSubstitutor()
Returns the object that is responsible for variable interpolation.
|
protected String | interpolate(String base)
interpolate key names to handle ${key} stuff
|
protected Object | interpolate(Object value)
Returns the interpolated value. |
protected String | interpolateHelper(String base, List priorVariables)
Recursive handler for multple levels of interpolation.
|
boolean | isDelimiterParsingDisabled()
Determine if this configuration is using delimiters when parsing
property values to convert them to lists of values. |
abstract boolean | isEmpty() |
boolean | isThrowExceptionOnMissing()
Returns true if missing values throw Exceptions.
|
protected Object | resolveContainerStore(String key)
Returns an object from the store described by the key. |
static void | setDefaultListDelimiter(char delimiter)
For configurations extending AbstractConfiguration, allow them to change
the listDelimiter from the default comma (","). |
static void | setDelimiter(char delimiter)
Sets the default list delimiter.
|
void | setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Set whether this configuration should use delimiters when parsing
property values to convert them to lists of values. |
void | setListDelimiter(char listDelimiter)
Change the list delimiter for this configuration.
|
void | setLogger(Log log)
Allows to set the logger to be used by this configuration object. |
void | setProperty(String key, Object value) |
void | setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
Allows to set the throwExceptionOnMissing flag. |
Configuration | subset(String prefix) |
Since: 1.3
Since: 1.3
Since: 1.3
Since: 1.4
Since: 1.3
AbstractConfiguration
.ConfigurationErrorListener
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
Parameters: key key to use for mapping value object to store
clearPropertyDirect()
, which will do the real work.
Parameters: key the key to be removed
clearProperty()
after it has done some
preparations. It should be overriden in sub classes. This base
implementation is just left empty.
Parameters: key the key to be removed
ConfigurationInterpolator
and sets the default lookup
object to an implementation that queries this configuration.
Returns: the newly created interpolator object
Since: 1.4
See Also: AbstractConfiguration
See Also: AbstractConfiguration
See Also: toBoolean
See Also: toBoolean
Boolean
object. If the property has no value, the passed
in default value will be used.
Parameters: key the key of the property defaultValue the default value
Returns: the value of this key converted to a Boolean
Throws: ConversionException if the value cannot be converted to a
Boolean
See Also: toBoolean
Returns: The delimiter in use
Deprecated: Use AbstractConfiguration.getDefaultListDelimiter() instead
Returns the default list delimiter.Returns: the default list delimiter
ConfigurationInterpolator
object that manages
the lookup objects for resolving variables. Note: If this
object is manipulated (e.g. new lookup objects added), synchronisation
has to be manually ensured. Because
ConfigurationInterpolator
is not thread-safe concurrent
access to properties of this configuration instance (which causes the
interpolator to be invoked) may cause race conditions.
Returns: the ConfigurationInterpolator
associated with this
configuration
Since: 1.4
See Also: getStringArray
Returns: The listDelimiter in use
Returns: the logger
Since: 1.4
Parameters: key The configuration key. defaults Any default values for the returned
Properties
object. Ignored if null
.
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).
See Also: AbstractConfiguration
setListDelimiter()
method. If this is the case, the string
is splitted at these positions resulting in a property with multiple
values.
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: AbstractConfiguration AbstractConfiguration
Returns: the object responsible for variable interpolation
Since: 1.4
Parameters: base string to interpolate
Returns: returns the key name with the ${key} substituted
Parameters: value the value to interpolate
Returns: returns the value with variables substituted
Deprecated: Interpolation is now handled by
PropertyConverter
; this method will no longer be
called
Parameters: base string with the ${key} variables priorVariables serves two purposes: to allow checking for loops, and creating a meaningful exception message should a loop occur. It's 0'th element will be set to the value of base from the first call. All subsequent interpolated variables are added afterward.
Returns: the string with the interpolation taken care of
Returns: true if delimiters are not being used
Returns: true if missing values throw Exceptions
Parameters: key The property key.
Returns: value Value, transparently resolving a possible List dependency.
Parameters: delimiter The new listDelimiter
Deprecated: Use AbstractConfiguration.setDefaultListDelimiter(char) instead
Sets the default list delimiter.Parameters: delimiter the delimiter character
Parameters: delimiterParsingDisabled a flag whether delimiter parsing should be disabled
Parameters: listDelimiter The new listDelimiter
Parameters: log the new logger
Since: 1.4
throwExceptionOnMissing
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 a
NoSuchElementException
exception. Note that getter methods
for primitive data types are not affected by this flag.
Parameters: throwExceptionOnMissing The new value for the property