|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.configuration.event.EventSource
org.apache.commons.configuration.AbstractConfiguration
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.EVENT_XXX
constants to get an impression about which event types are supported.
Field Summary | |
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_SET_PROPERTY
Constant for the set property event type. |
protected static String |
START_TOKEN
start token |
Constructor Summary | |
AbstractConfiguration()
|
Method Summary | |
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 = 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"] |
protected abstract void |
addPropertyDirect(String key,
Object value)
Adds a key/value pair to the Configuration. |
void |
clear()
Remove all properties from the configuration. |
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)
Check if the configuration contains the specified key. |
BigDecimal |
getBigDecimal(String key)
Get a BigDecimal associated with the given configuration key. |
BigDecimal |
getBigDecimal(String key,
BigDecimal defaultValue)
Get a BigDecimal associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned. |
BigInteger |
getBigInteger(String key)
Get a BigInteger associated with the given configuration key. |
BigInteger |
getBigInteger(String key,
BigInteger defaultValue)
Get a BigInteger associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned. |
boolean |
getBoolean(String key)
Get a boolean associated with the given configuration key. |
boolean |
getBoolean(String key,
boolean defaultValue)
Get a boolean associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
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)
Get a byte associated with the given configuration key. |
byte |
getByte(String key,
byte defaultValue)
Get a byte associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
Byte |
getByte(String key,
Byte defaultValue)
Get a Byte associated with the given configuration key. |
static char |
getDefaultListDelimiter()
Retrieve the current delimiter. |
static char |
getDelimiter()
Deprecated. Use AbstractConfiguration.getDefaultListDelimiter() instead |
double |
getDouble(String key)
Get a double associated with the given configuration key. |
double |
getDouble(String key,
double defaultValue)
Get a double associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
Double |
getDouble(String key,
Double defaultValue)
Get a Double associated with the given configuration key. |
float |
getFloat(String key)
Get a float associated with the given configuration key. |
float |
getFloat(String key,
float defaultValue)
Get a float associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
Float |
getFloat(String key,
Float defaultValue)
Get a Float associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned. |
int |
getInt(String key)
Get a int associated with the given configuration key. |
int |
getInt(String key,
int defaultValue)
Get a int associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
Integer |
getInteger(String key,
Integer defaultValue)
Get an Integer associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned. |
abstract Iterator |
getKeys()
Get the list of the keys contained in the configuration. The returned iterator can be used to obtain all defined keys. Note that the exact behavior of the iterator's remove() method is specific to
a concrete implementation. It may remove the corresponding
property from the configuration, but this is not guaranteed. In any case
it is no replacement for calling
for this property. So it is
highly recommended to avoid using the iterator's remove()
method. |
Iterator |
getKeys(String prefix)
Get the list of the keys contained in the configuration that match the specified prefix. |
List |
getList(String key)
Get a List of strings associated with the given configuration key. If the key doesn't map to an existing object an empty List is returned. |
List |
getList(String key,
List defaultValue)
Get a List of strings associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
char |
getListDelimiter()
Retrieve the delimiter for this configuration. |
long |
getLong(String key)
Get a long associated with the given configuration key. |
long |
getLong(String key,
long defaultValue)
Get a long associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
Long |
getLong(String key,
Long defaultValue)
Get a Long associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned. |
Properties |
getProperties(String key)
Get a list of properties associated with the given configuration key. This method expects the given key to have an arbitrary number of String values, each of which is of the form key=value . These
strings are splitted at the equals sign, and the key parts will become
keys of the returned Properties object, the value parts
become values. |
Properties |
getProperties(String key,
Properties defaults)
Get a list of properties associated with the given configuration key. |
short |
getShort(String key)
Get a short associated with the given configuration key. |
short |
getShort(String key,
short defaultValue)
Get a short associated with the given configuration key. |
Short |
getShort(String key,
Short defaultValue)
Get a Short associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned. |
String |
getString(String key)
Get a string associated with the given configuration key. |
String |
getString(String key,
String defaultValue)
Get a string associated with the given configuration key. If the key doesn't map to an existing object, the default value is returned. |
String[] |
getStringArray(String key)
Get an array of strings associated with the given configuration key. If the key doesn't map to an existing object an empty array is returned |
protected Object |
interpolate(Object value)
Returns the interpolated value. |
protected String |
interpolate(String base)
interpolate key names to handle ${key} stuff |
protected String |
interpolateHelper(String base,
List priorVariables)
Deprecated. Interpolation is now handled by ; this method will no longer be
called |
boolean |
isDelimiterParsingDisabled()
Determine if this configuration is using delimiters when parsing property values to convert them to lists of values. |
abstract boolean |
isEmpty()
Check if the configuration is empty. |
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)
Deprecated. Use AbstractConfiguration.setDefaultListDelimiter(char) instead |
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 |
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). |
void |
setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
Allows to set the throwExceptionOnMissing flag. |
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 = 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. |
Methods inherited from class org.apache.commons.configuration.event.EventSource |
addConfigurationListener, clearConfigurationListeners, createEvent, fireEvent, getConfigurationListeners, isDetailEvents, removeConfigurationListener, setDetailEvents |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.commons.configuration.Configuration |
getProperty |
Field Detail |
public static final int EVENT_ADD_PROPERTY
public static final int EVENT_CLEAR_PROPERTY
public static final int EVENT_SET_PROPERTY
public static final int EVENT_CLEAR
protected static final String START_TOKEN
protected static final String END_TOKEN
Constructor Detail |
public AbstractConfiguration()
Method Detail |
public static void setDefaultListDelimiter(char delimiter)
delimiter
- The new listDelimiterpublic static void setDelimiter(char delimiter)
delimiter
- the delimiter characterpublic static char getDefaultListDelimiter()
public static char getDelimiter()
public void setListDelimiter(char listDelimiter)
listDelimiter
- The new listDelimiterpublic char getListDelimiter()
public boolean isDelimiterParsingDisabled()
public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
delimiterParsingDisabled
- a flag whether delimiter parsing should
be disabledpublic void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
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.
throwExceptionOnMissing
- The new value for the propertypublic boolean isThrowExceptionOnMissing()
public 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"]
addProperty
in interface Configuration
key
- The key to add the property to.value
- The value to add.protected abstract void addPropertyDirect(String key, Object value)
key
- key to use for mappingvalue
- object to storeprotected String interpolate(String base)
base
- string to interpolate
protected Object interpolate(Object value)
value
- the value to interpolate
protected String interpolateHelper(String base, List priorVariables)
PropertyConverter
; this method will no longer be
called
base
- string with the ${key} variablespriorVariables
- 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.
public 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.
subset
in interface Configuration
prefix
- The prefix used to select the properties.
SubsetConfiguration
public abstract boolean isEmpty()
isEmpty
in interface Configuration
true
if the configuration contains no property,
false
otherwise.public abstract boolean containsKey(String key)
containsKey
in interface Configuration
key
- the key whose presence in this configuration is to be tested
true
if the configuration contains a value for this
key, false
otherwisepublic void setProperty(String key, Object value)
setProperty
in interface Configuration
key
- The key of the property to changevalue
- The new valuepublic void clearProperty(String key)
clearPropertyDirect()
, which will do the real work.
clearProperty
in interface Configuration
key
- the key to be removedprotected void clearPropertyDirect(String key)
clearProperty()
after it has done some
preparations. It should be overriden in sub classes. This base
implementation is just left empty.
key
- the key to be removedpublic void clear()
clear
in interface Configuration
public abstract Iterator getKeys()
remove()
method is specific to
a concrete implementation. It may remove the corresponding
property from the configuration, but this is not guaranteed. In any case
it is no replacement for calling
Configuration.clearProperty(String)
for this property. So it is
highly recommended to avoid using the iterator's remove()
method.
getKeys
in interface Configuration
public Iterator getKeys(String prefix)
getKeys
in interface Configuration
prefix
- The prefix to test against.
Configuration.getKeys()
public Properties getProperties(String key)
key=value
. These
strings are splitted at the equals sign, and the key parts will become
keys of the returned Properties
object, the value parts
become values.
getProperties
in interface Configuration
key
- The configuration key.
public Properties getProperties(String key, Properties defaults)
key
- The configuration key.defaults
- Any default values for the returned
Properties
object. Ignored if null
.
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).public boolean getBoolean(String key)
getBoolean
in interface Configuration
key
- The configuration key.
PropertyConverter.toBoolean(Object)
public boolean getBoolean(String key, boolean defaultValue)
getBoolean
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
PropertyConverter.toBoolean(Object)
public Boolean getBoolean(String key, Boolean defaultValue)
Boolean
object. If the property has no value, the passed
in default value will be used.
getBoolean
in interface Configuration
key
- the key of the propertydefaultValue
- the default value
Boolean
ConversionException
- if the value cannot be converted to a
Boolean
PropertyConverter.toBoolean(Object)
public byte getByte(String key)
getByte
in interface Configuration
key
- The configuration key.
public byte getByte(String key, byte defaultValue)
getByte
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public Byte getByte(String key, Byte defaultValue)
Byte
associated with the given configuration key.
getByte
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public double getDouble(String key)
getDouble
in interface Configuration
key
- The configuration key.
public double getDouble(String key, double defaultValue)
getDouble
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public Double getDouble(String key, Double defaultValue)
Double
associated with the given configuration key.
getDouble
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public float getFloat(String key)
getFloat
in interface Configuration
key
- The configuration key.
public float getFloat(String key, float defaultValue)
getFloat
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public Float getFloat(String key, Float defaultValue)
Float
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getFloat
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public int getInt(String key)
getInt
in interface Configuration
key
- The configuration key.
public int getInt(String key, int defaultValue)
getInt
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public Integer getInteger(String key, Integer defaultValue)
Integer
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getInteger
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public long getLong(String key)
getLong
in interface Configuration
key
- The configuration key.
public long getLong(String key, long defaultValue)
getLong
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public Long getLong(String key, Long defaultValue)
Long
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getLong
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public short getShort(String key)
getShort
in interface Configuration
key
- The configuration key.
public short getShort(String key, short defaultValue)
getShort
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public Short getShort(String key, Short defaultValue)
Short
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getShort
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public BigDecimal getBigDecimal(String key)
BigDecimal
associated with the given configuration key.
getBigDecimal
in interface Configuration
key
- The configuration key.
public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
BigDecimal
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getBigDecimal
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public BigInteger getBigInteger(String key)
BigInteger
associated with the given configuration key.
getBigInteger
in interface Configuration
key
- The configuration key.
public BigInteger getBigInteger(String key, BigInteger defaultValue)
BigInteger
associated with the given configuration key.
If the key doesn't map to an existing object, the default value
is returned.
getBigInteger
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public String getString(String key)
getString
in interface Configuration
key
- The configuration key.
public String getString(String key, String defaultValue)
getString
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public String[] getStringArray(String key)
getStringArray
in interface Configuration
key
- The configuration key.
public List getList(String key)
getList
in interface Configuration
key
- The configuration key.
public List getList(String key, List defaultValue)
getList
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
protected Object resolveContainerStore(String key)
key
- The property key.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |