|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.chwf.config.ConfigImpl | +--org.chwf.config.PolymorphicConfig
A subclass of Config
that adds the superclass configuration
to the configuration search path. Other than the factory method, it may
be used in every respect like the Config
class.
Constructor Summary | |
PolymorphicConfig()
|
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. |
static Config |
getConfig(java.lang.Class contextClass)
Factory method for PolymorphicConfig class. |
static Config |
getConfig(java.lang.Class contextClass,
java.util.Locale locale)
Factory method for PolymorphicConfig class. |
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 ConfigImpl.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. |
java.util.Map |
getRawData()
Get the raw configuration data. |
java.lang.String |
getRawValue(java.lang.String key)
Get raw data value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PolymorphicConfig()
Method Detail |
public static Config getConfig(java.lang.Class contextClass) throws ConfigurationException
contextClass
- The context class for the configuration.ConfigurationException
- For errors in loading configuration data.public static Config getConfig(java.lang.Class contextClass, java.util.Locale locale) throws ConfigurationException
contextClass
- The context class for the configuration.locale
- The locale.ConfigurationException
- For errors in loading configuration data.public java.lang.String get(java.lang.String key) throws ConfigurationException
get
in interface Config
key
- The search key.ConfigurationException
- If the property is not found.public java.lang.String get(java.lang.String key, java.lang.String defaultValue)
get
in interface Config
key
- The search key.defaultValue
- A default value.public int getInt(java.lang.String key) throws ConfigurationException
getInt
in interface Config
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)
getInt
in interface Config
key
- The search key.defaultValue
- A default value.public double getDouble(java.lang.String key) throws ConfigurationException
getDouble
in interface Config
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)
getDouble
in interface Config
key
- The search key.defaultValue
- A default value.public boolean getBoolean(java.lang.String key) throws ConfigurationException
getBoolean
in interface Config
key
- The search key.ConfigurationException
- If the property is not found.public boolean getBoolean(java.lang.String key, boolean defaultValue)
getBoolean
in interface Config
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();
getList
in interface Config
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 ConfigImpl.getList(java.lang.String)
, but with a default.
getList
in interface Config
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
getMap
in interface Config
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.
getOrderedMap
in interface Config
key
- The search key, which is used as the initial part
of property keys.public java.util.Map getRawData()
getRawData
in interface RawConfig
public java.lang.String getRawValue(java.lang.String key)
getRawValue
in interface RawConfig
key
- The search key.null
if it does not exist.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |