|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A class for retrieving configuration data from properties and XML files. See the package documentation for further information.
Method Summary | |
java.lang.String |
get(java.lang.String key)
Gets the named property value. |
java.lang.String |
get(java.lang.String key,
java.lang.String defaultValue)
Gets the named property value. |
boolean |
getBoolean(java.lang.String key)
Gets the named property value as a boolean value. |
boolean |
getBoolean(java.lang.String key,
boolean defaultValue)
Gets the named property value as a boolean value. |
double |
getDouble(java.lang.String key)
Gets the named property value as a double value. |
double |
getDouble(java.lang.String key,
double defaultValue)
Gets the named property value as a double value. |
int |
getInt(java.lang.String key)
Gets the named property value as an int value. |
int |
getInt(java.lang.String key,
int defaultValue)
Gets the named property value as an int value. |
java.lang.String[] |
getList(java.lang.String key)
Gets an array of strings for a property key. |
java.lang.String[] |
getList(java.lang.String key,
java.lang.String[] defaultList)
As getList(java.lang.String) , but with a default. |
java.util.SortedMap |
getMap(java.lang.String key)
Gets a sorted map consisting of all entries beginning with the specified key. |
java.util.Map |
getOrderedMap(java.lang.String key)
Gets an ordered map consisting of all entries beginning with the specified key. |
Method Detail |
public java.lang.String get(java.lang.String key) throws ConfigurationException
key
- The search key.ConfigurationException
- If the property is not found.public java.lang.String get(java.lang.String key, java.lang.String defaultValue)
key
- The search key.defaultValue
- A default value.public int getInt(java.lang.String key) throws ConfigurationException
key
- The search key.ConfigurationException
- If the property is not found or is not a
number.public int getInt(java.lang.String key, int defaultValue)
key
- The search key.defaultValue
- A default value.public double getDouble(java.lang.String key) throws ConfigurationException
key
- The search key.ConfigurationException
- If the property is not found or is not a
number.public double getDouble(java.lang.String key, double defaultValue)
key
- The search key.defaultValue
- A default value.public boolean getBoolean(java.lang.String key) throws ConfigurationException
key
- The search key.ConfigurationException
- If the property is not found.public boolean getBoolean(java.lang.String key, boolean defaultValue)
key
- The search key.defaultValue
- A default value.public java.lang.String[] getList(java.lang.String key) throws ConfigurationException
Gets an array of strings for a property key. This is done in one of two ways:
Note that this method never returns an empty list. If the property
is not found, a ConfigurationException
is thrown. If
you need to allow for the possibility of empty lists, use the values
of the getMap()
method instead:
Collection list = config.getMap().values();
key
- The search key.ConfigurationException
- If the property is not found.public java.lang.String[] getList(java.lang.String key, java.lang.String[] defaultList)
As getList(java.lang.String)
, but with a default.
key
- The search key.defaultList
- The default list.public java.util.SortedMap getMap(java.lang.String key)
Gets a sorted map consisting of all entries beginning with the specified key. The keys in the sorted map will be the property keys with the search key (and any leading ".") removed. For example, suppose the following values are in the property file:
map.value.1=Value 1 map.value.2=Value 2 map.value.3=Value 3
The method call config.getMap("map.value")
will
result in a map with 3 values, whose keys are "1", "2" and "3".
Note that the sort order is based on string ordering, not numeric ordering. This means if you have more than 10 values, you will have to number them more carefully if the ordering is important:
map.value.01=Value 1 map.value.02=Value 2 map.value.03=Value 3 map.value.04=Value 4 map.value.05=Value 5 map.value.06=Value 6 map.value.07=Value 7 map.value.08=Value 8 map.value.09=Value 9 map.value.10=Value 10 map.value.11=Value 11
key
- The search key, which is used as the initial part
of property keys.public java.util.Map getOrderedMap(java.lang.String key)
Gets an ordered map consisting of all entries beginning with the specified key. The keys in the sorted map will be the property keys with the search key (and any leading ".") removed. If the configuration data is in an XML file, the data retains the sequential ordering of the elements in the XML file. For example, suppose the XML data were as follows:
<map.values> <value name="C">Item 1</data> <value name="B">Item 2</data> <value name="A">Item 3</data> <map.values>
The method call config.getOrderedMap("map.values")
will
result in a map with 3 values, whose keys are "C", "B" and "A" in that
order. Compare this to the getMap()
method, which sorts keys
in alphabetical order rather than in sequential order.
This method only functions correctly for configuration data in XML files, because property files are not ordered. Using this method for data in property files will result in keys sorted in pseudo-random order.
key
- The search key, which is used as the initial part
of property keys.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |