|
|||||||||||
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.PropertiesTokenizer
This class divides into tokens a property value. |
Field Summary | |
protected static String |
END_TOKEN
end token |
protected static String |
START_TOKEN
start token |
Constructor Summary | |
AbstractConfiguration()
|
Method Summary | |
void |
addProperty(String key,
Object token)
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 obj)
Adds a key/value pair to the Configuration. |
abstract void |
clearProperty(String key)
Remove a property from the 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. |
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. |
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. |
Boolean |
getBoolean(String key,
Boolean defaultValue)
Get a Boolean associated with the given configuration key. |
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. |
Byte |
getByte(String key,
Byte defaultValue)
Get a Byte associated with the given configuration key. |
static char |
getDelimiter()
Retrieve the current delimiter. |
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. |
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. |
Float |
getFloat(String key,
Float defaultValue)
Get a Float associated with the given configuration key. |
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. |
Integer |
getInteger(String key,
Integer defaultValue)
Get an Integer associated with the given configuration key. |
abstract Iterator |
getKeys()
Get the list of the keys contained in the configuration. |
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. |
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. |
Long |
getLong(String key,
Long defaultValue)
Get a Long associated with the given configuration key. |
Properties |
getProperties(String key)
Get a list of properties associated with the given configuration key. |
Properties |
getProperties(String key,
Properties defaults)
Get a list of properties associated with the given configuration key. |
Object |
getProperty(String key)
Gets a property from the configuration. |
protected abstract Object |
getPropertyDirect(String key)
Read property. |
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. |
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. |
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 |
Vector |
getVector(String key)
Get a Vector of strings associated with the given configuration key. If the key doesn't map to an existing object an empty Vector is returned. |
Vector |
getVector(String key,
Vector defaultValue)
Get a Vector of strings associated with the given configuration key. |
protected String |
interpolate(String base)
interpolate key names to handle ${key} stuff |
protected String |
interpolateHelper(String base,
List priorVariables)
Recursive handler for multple levels of interpolation. |
abstract boolean |
isEmpty()
Check if the configuration is empty. |
boolean |
isThrowExceptionOnMissing()
Returns true if missing values throw Exceptions. |
static void |
setDelimiter(char delimiter)
For configurations extending AbstractConfiguration, allow them to change the delimiter from the default comma (","). |
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)
If set to false, missing elements return null if possible (for objects). |
protected List |
split(String token)
Returns a List of Strings built from the supplied String. |
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final String START_TOKEN
protected static final String END_TOKEN
Constructor Detail |
public AbstractConfiguration()
Method Detail |
public static void setDelimiter(char delimiter)
delimiter
- The new delimiterpublic static char getDelimiter()
public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
throwExceptionOnMissing
- The new value for the propertypublic boolean isThrowExceptionOnMissing()
public void addProperty(String key, Object token)
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.token
- The value to add.protected abstract Object getPropertyDirect(String key)
null
if the key doesn't
map to an existing object.
key
- key to use for mapping
protected abstract void addPropertyDirect(String key, Object obj)
key
- key to use for mappingobj
- object to storeprotected String interpolate(String base)
base
- string to interpolate
protected String interpolateHelper(String base, 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 List split(String token)
token
- The String to tokenize
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 abstract void clearProperty(String key)
clearProperty
in interface Configuration
key
- the key to remove along with corresponding value.public abstract Iterator getKeys()
getKeys
in interface Configuration
public Iterator getKeys(String prefix)
getKeys
in interface Configuration
prefix
- The prefix to test against.
public Properties getProperties(String key)
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 Object getProperty(String key)
getProperty
in interface Configuration
key
- property to retrieve
public boolean getBoolean(String key)
getBoolean
in interface Configuration
key
- The configuration key.
public boolean getBoolean(String key, boolean defaultValue)
getBoolean
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
public Boolean getBoolean(String key, Boolean defaultValue)
Boolean
associated with the given configuration key.
getBoolean
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
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.
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.
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.
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.
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.
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.
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.
public Vector getVector(String key)
getVector
in interface Configuration
key
- The configuration key.
public Vector getVector(String key, Vector defaultValue)
getVector
in interface Configuration
key
- The configuration key.defaultValue
- The default value.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |