Class FlatConfigData
- All Implemented Interfaces:
ConfigData
- Direct Known Subclasses:
AppletBasedConfigData
,PropertiesBasedConfigData
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
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ConfigData
createConfigData
(String path) Returns the FlatConfigData object for the specified full path.Returns the value associated with this key.getFullKey
(String key) Returns the full key.Returns the ConfigData object associated with this key.protected abstract String
Returns the value for the specified full key from the flat representation of the hierarchically organized key-value pairs.
-
Constructor Details
-
FlatConfigData
Creates a new instance for the specified path.
-
-
Method Details
-
getFullKey
Returns the full key.- Specified by:
getFullKey
in interfaceConfigData
- Parameters:
key
- A (relative) key. null is not allowed.- Returns:
- the path concatenated with key or key if the path is undefined.
-
get
Returns the value associated with this key.- Specified by:
get
in interfaceConfigData
- Parameters:
key
- The relative key. null is not allowed.- Returns:
- the associated value. Will be null if no value exists for key.
-
getNode
Returns the ConfigData object associated with this key.- Specified by:
getNode
in interfaceConfigData
- Parameters:
key
- The relative key.- Returns:
- the associated value. Will never return null. Instead an empty ConfigData is returned.
-
getValue
Returns the value for the specified full key from the flat representation of the hierarchically organized key-value pairs.- Parameters:
fullKey
- The full key including path. null is not allowed.- Returns:
- the value or null if not found.
-
createConfigData
Returns the FlatConfigData object for the specified full path. In general path will be used in the constructor with path argument.- Parameters:
path
- The full path.- Returns:
- a new instance in any case.
-