|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.configuration.AbstractConfiguration
Abstract configuration class. Provide 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.
Nested Class Summary | |
(package private) static class |
AbstractConfiguration.Container
Private Wrapper class for List, so we can distinguish between List objects and our container |
(package private) class |
AbstractConfiguration.PropertiesTokenizer
This class divides into tokens a property value. |
Field Summary | |
protected Configuration |
defaults
stores the configuration key-value pairs |
protected static java.lang.String |
END_TOKEN
end token |
private static int |
INITIAL_LIST_SIZE
how big the initial arraylist for splitting up name value pairs |
protected static java.lang.String |
START_TOKEN
start token |
Constructor Summary | |
AbstractConfiguration()
Empty constructor. |
|
AbstractConfiguration(Configuration defaults)
Creates an empty AbstractConfiguration object with a Super-Object which is queries for every key. |
Method Summary | |
void |
addProperty(java.lang.String key,
java.lang.Object token)
Add a property to the configuration. |
protected abstract void |
addPropertyDirect(java.lang.String key,
java.lang.Object obj)
Adds a key/value pair to the Configuration. |
abstract void |
clearProperty(java.lang.String key)
Clear a property in the configuration. |
abstract boolean |
containsKey(java.lang.String key)
check if the configuration contains the key |
boolean |
getBoolean(java.lang.String key)
Get a boolean associated with the given configuration key. |
boolean |
getBoolean(java.lang.String key,
boolean defaultValue)
Get a boolean associated with the given configuration key. |
java.lang.Boolean |
getBoolean(java.lang.String key,
java.lang.Boolean defaultValue)
Get a boolean associated with the given configuration key. |
byte |
getByte(java.lang.String key)
Get a byte associated with the given configuration key. |
byte |
getByte(java.lang.String key,
byte defaultValue)
Get a byte associated with the given configuration key. |
java.lang.Byte |
getByte(java.lang.String key,
java.lang.Byte defaultValue)
Get a byte associated with the given configuration key. |
double |
getDouble(java.lang.String key)
Get a double associated with the given configuration key. |
double |
getDouble(java.lang.String key,
double defaultValue)
Get a double associated with the given configuration key. |
java.lang.Double |
getDouble(java.lang.String key,
java.lang.Double defaultValue)
Get a double associated with the given configuration key. |
float |
getFloat(java.lang.String key)
Get a float associated with the given configuration key. |
float |
getFloat(java.lang.String key,
float defaultValue)
Get a float associated with the given configuration key. |
java.lang.Float |
getFloat(java.lang.String key,
java.lang.Float defaultValue)
Get a float associated with the given configuration key. |
int |
getInt(java.lang.String key)
Get a int associated with the given configuration key. |
int |
getInt(java.lang.String key,
int defaultValue)
Get a int associated with the given configuration key. |
java.lang.Integer |
getInteger(java.lang.String key,
java.lang.Integer defaultValue)
Get a int associated with the given configuration key. |
abstract java.util.Iterator |
getKeys()
Get the list of the keys contained in the configuration repository. |
java.util.Iterator |
getKeys(java.lang.String prefix)
Get the list of the keys contained in the configuration repository that match the specified prefix. |
java.util.List |
getList(java.lang.String key)
Get a List of strings associated with the given configuration key. |
java.util.List |
getList(java.lang.String key,
java.util.List defaultValue)
Get a List of strings associated with the given configuration key. |
long |
getLong(java.lang.String key)
Get a long associated with the given configuration key. |
long |
getLong(java.lang.String key,
long defaultValue)
Get a long associated with the given configuration key. |
java.lang.Long |
getLong(java.lang.String key,
java.lang.Long defaultValue)
Get a long associated with the given configuration key. |
java.util.Properties |
getProperties(java.lang.String key)
Get a list of properties associated with the given configuration key. |
java.util.Properties |
getProperties(java.lang.String key,
java.util.Properties defaults)
Get a list of properties associated with the given configuration key. |
java.lang.Object |
getProperty(java.lang.String key)
Gets a property from the configuration. |
protected abstract java.lang.Object |
getPropertyDirect(java.lang.String key)
Read property. |
short |
getShort(java.lang.String key)
Get a short associated with the given configuration key. |
short |
getShort(java.lang.String key,
short defaultValue)
Get a short associated with the given configuration key. |
java.lang.Short |
getShort(java.lang.String key,
java.lang.Short defaultValue)
Get a short associated with the given configuration key. |
java.lang.String |
getString(java.lang.String key)
Get a string associated with the given configuration key. |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Get a string associated with the given configuration key. |
java.lang.String[] |
getStringArray(java.lang.String key)
Get an array of strings associated with the given configuration key. |
protected java.lang.String |
interpolate(java.lang.String base)
interpolate key names to handle ${key} stuff |
protected java.lang.String |
interpolateHelper(java.lang.String base,
java.util.List priorVariables)
Recursive handler for multple levels of interpolation. |
abstract boolean |
isEmpty()
Check if the configuration is empty |
protected java.util.List |
processString(java.lang.String token)
Returns a List of Strings built from the supplied String. |
private java.lang.Object |
resolveContainerStore(java.lang.String key)
Returns an object from the store described by the key. |
void |
setProperty(java.lang.String key,
java.lang.Object value)
Set a property, this will replace any previously set values. |
Configuration |
subset(java.lang.String prefix)
Create an BaseConfiguration object that is a subset of this one. |
protected java.lang.Boolean |
testBoolean(java.lang.String value)
Test whether the string represent by value maps to a boolean value or not. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final int INITIAL_LIST_SIZE
protected Configuration defaults
protected static final java.lang.String START_TOKEN
protected static final java.lang.String END_TOKEN
Constructor Detail |
public AbstractConfiguration()
public AbstractConfiguration(Configuration defaults)
defaults
- Configuration defaults to use if key not in fileMethod Detail |
public void addProperty(java.lang.String key, java.lang.Object token)
addProperty
in interface Configuration
key
- The Key to add the property to.token
- The Value to add.protected abstract java.lang.Object getPropertyDirect(java.lang.String key)
null
if the key doesn't
map to an existing object.
key
- key to use for mapping
protected abstract void addPropertyDirect(java.lang.String key, java.lang.Object obj)
key
- key to use for mappingobj
- object to storeprotected java.lang.String interpolate(java.lang.String base)
base
- string to interpolate
protected java.lang.String interpolateHelper(java.lang.String base, java.util.List priorVariables)
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.
protected java.util.List processString(java.lang.String token)
token
- The String to tokenize
protected final java.lang.Boolean testBoolean(java.lang.String value)
true
, on
,
and yes
for a true
boolean value, and
false
, off
, and no
for
false
boolean values. Case of value to test for
boolean status is ignored.
value
- The value to test for boolean state.
true
or false
if the supplied
text maps to a boolean value, or null
otherwise.public Configuration subset(java.lang.String prefix)
subset
in interface Configuration
prefix
- prefix string for keys
null
if there is no such keys.public abstract boolean isEmpty()
isEmpty
in interface Configuration
true
if Configuration is empty,
false
otherwise.public abstract boolean containsKey(java.lang.String key)
containsKey
in interface Configuration
key
- the configuration key
true
if Configuration contain given key,
false
otherwise.public void setProperty(java.lang.String key, java.lang.Object value)
setProperty
in interface Configuration
key
- the configuration keyvalue
- the property valuepublic abstract void clearProperty(java.lang.String key)
clearProperty
in interface Configuration
key
- the key to remove along with corresponding value.public abstract java.util.Iterator getKeys()
getKeys
in interface Configuration
public java.util.Iterator getKeys(java.lang.String prefix)
getKeys
in interface Configuration
prefix
- The prefix to test against.
public java.util.Properties getProperties(java.lang.String key)
getProperties
in interface Configuration
key
- The configuration key.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a String/List.
java.lang.IllegalArgumentException
- if one of the tokens is
malformed (does not contain an equals sign).getProperties(String, Properties)
public java.util.Properties getProperties(java.lang.String key, java.util.Properties defaults)
key
- The configuration key.defaults
- Any default values for the returned
Properties
object. Ignored if null
.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a String/List of Strings.
java.lang.IllegalArgumentException
- if one of the tokens is
malformed (does not contain an equals sign).public java.lang.Object getProperty(java.lang.String key)
getProperty
in interface Configuration
key
- property to retrieve
public boolean getBoolean(java.lang.String key)
getBoolean
in interface Configuration
key
- The configuration key.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Boolean.public boolean getBoolean(java.lang.String key, boolean defaultValue)
getBoolean
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Boolean.public java.lang.Boolean getBoolean(java.lang.String key, java.lang.Boolean defaultValue)
getBoolean
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Boolean.public byte getByte(java.lang.String key)
getByte
in interface Configuration
key
- The configuration key.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Byte.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public byte getByte(java.lang.String key, byte defaultValue)
getByte
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Byte.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public java.lang.Byte getByte(java.lang.String key, java.lang.Byte defaultValue)
getByte
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an object that
is not a Byte.
java.lang.NumberFormatException
- is thrown if the value mapped by the key
has not a valid number format.public double getDouble(java.lang.String key)
getDouble
in interface Configuration
key
- The configuration key.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Double.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public double getDouble(java.lang.String key, double defaultValue)
getDouble
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Double.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public java.lang.Double getDouble(java.lang.String key, java.lang.Double defaultValue)
getDouble
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Double.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public float getFloat(java.lang.String key)
getFloat
in interface Configuration
key
- The configuration key.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Float.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public float getFloat(java.lang.String key, float defaultValue)
getFloat
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Float.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public java.lang.Float getFloat(java.lang.String key, java.lang.Float defaultValue)
getFloat
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Float.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public int getInt(java.lang.String key)
getInt
in interface Configuration
key
- The configuration key.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Integer.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public int getInt(java.lang.String key, int defaultValue)
getInt
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Integer.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public java.lang.Integer getInteger(java.lang.String key, java.lang.Integer defaultValue)
getInteger
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an object that
is not a Integer.
java.lang.NumberFormatException
- is thrown if the value mapped by the key
has not a valid number format.public long getLong(java.lang.String key)
getLong
in interface Configuration
key
- The configuration key.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Long.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public long getLong(java.lang.String key, long defaultValue)
getLong
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Long.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public java.lang.Long getLong(java.lang.String key, java.lang.Long defaultValue)
getLong
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Long.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public short getShort(java.lang.String key)
getShort
in interface Configuration
key
- The configuration key.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Short.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public short getShort(java.lang.String key, short defaultValue)
getShort
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Short.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public java.lang.Short getShort(java.lang.String key, java.lang.Short defaultValue)
getShort
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a Short.
java.lang.NumberFormatException
- is thrown if the value mapped
by the key has not a valid number format.public java.lang.String getString(java.lang.String key)
getString
in interface Configuration
key
- The configuration key.
java.lang.ClassCastException
- is thrown if the key maps to an object that
is not a String.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.public java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
getString
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an object that
is not a String.public java.lang.String[] getStringArray(java.lang.String key)
getStringArray
in interface Configuration
key
- The configuration key.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a String/List of Strings.public java.util.List getList(java.lang.String key)
getList
in interface Configuration
key
- The configuration key.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a List.
java.util.NoSuchElementException
- is thrown if the key doesn't
map to an existing object.public java.util.List getList(java.lang.String key, java.util.List defaultValue)
getList
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
java.lang.ClassCastException
- is thrown if the key maps to an
object that is not a List.private java.lang.Object resolveContainerStore(java.lang.String key)
key
- The property key.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |