|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jcckit.util.FlatConfigData
An implementation of ConfigData based on a flat
representation of the hierachically organized key-value pairs.
Concrete subclasses must implement the methods
getValue(java.lang.String)
and createConfigData(java.lang.String)
in accordance
with the Template Method pattern and Factory Method pattern,
respectively.
In a flat representation of hierachically organized key-value pairs all key-value pairs are stored in a single Hashtable. Its key is the full key of the configuration data (i.e. the key including its path).
Example (using the notation for a .properties file):
title = example symbolAttributes/className = jcckit.graphic.BasicDrawingAttributes symbolAttributes/fillColor = 0xcaffee symbolAttributes/lineColor = 0xff0000The following table shows the result of some method calls at a FlatConfigData instance prepared with this example:
Method call | Result |
---|---|
get("title") | example |
getNode("symbolAttributes").get("fillColor") | 0xcaffee |
In addition FlatConfigData implements inheritance of key-value pairs. Basically a node in the tree of key-value pairs may extend another node in the tree. The extended node inherit all key-value pairs from the extending one including the key-value pairs of all descendants. The value of a inherited key-value pair may be overridden. Also new key-value pairs may be placed in the inherited node or anywhere in the subtree. Note, that the extending node has to be a node which is not a descendant of the extended node (otherwise a circulary chain of references occurs). As a consequence not more than 20 inheritance levels are allowed.
The implementation of this kind of inheritance in a flat hashtable is done by an additional key-value pair of the form
extending-node/ = extended-node/Example:
A/a/priority = high A/a/alpha/hello = universe A/a/alpha/answer = 42 A/b/1/ = A/a/ A/b/1/alpha/hello = world A/b/1/alpha/question = 6 * 7The following table shows the result of various method calls applied at the node A/b/1/ of a FlatConfigData instance prepared with this example:
Method call | Result | Comment |
---|---|---|
get("priority") | high | inherited |
getNode("alpha").get("hello") | world | overridden |
getNode("alpha").get("question") | 6 * 7 | added |
getNode("alpha").get("answer") | 42 | inherited |
Constructor Summary | |
FlatConfigData(java.lang.String path)
Creates a new instance for the specified path. |
Method Summary | |
protected abstract ConfigData |
createConfigData(java.lang.String path)
Returns the FlatConfigData object for the specified full path. |
java.lang.String |
get(java.lang.String key)
Returns the value associated with this key. |
java.lang.String |
getFullKey(java.lang.String key)
Returns the full key. |
ConfigData |
getNode(java.lang.String key)
Returns the ConfigData object associated with this key. |
protected abstract java.lang.String |
getValue(java.lang.String fullKey)
Returns the value for the specified full key from the flat representation of the hierarchically organized key-value pairs. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public FlatConfigData(java.lang.String path)
Method Detail |
public java.lang.String getFullKey(java.lang.String key)
getFullKey
in interface ConfigData
key
- A (relative) key. null is not allowed.
public java.lang.String get(java.lang.String key)
get
in interface ConfigData
key
- The relative key. null is not allowed.
public ConfigData getNode(java.lang.String key)
getNode
in interface ConfigData
key
- The relative key.
protected abstract java.lang.String getValue(java.lang.String fullKey)
fullKey
- The full key including path. null is not allowed.
protected abstract ConfigData createConfigData(java.lang.String path)
path
- The full path.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |