Class FlatConfigData
- java.lang.Object
-
- jcckit.util.FlatConfigData
-
- All Implemented Interfaces:
ConfigData
- Direct Known Subclasses:
AppletBasedConfigData
,PropertiesBasedConfigData
public abstract class FlatConfigData extends Object implements ConfigData
An implementation of ConfigData based on a flat representation of the hierachically organized key-value pairs. Concrete subclasses must implement the methodsgetValue(java.lang.String)
andcreateConfigData(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 = 0xff0000
The 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 * 7
The 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 - Author:
- Franz-Josef Elmer
-
-
Constructor Summary
Constructors Constructor Description FlatConfigData(String path)
Creates a new instance for the specified path.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ConfigData
createConfigData(String path)
Returns the FlatConfigData object for the specified full path.String
get(String key)
Returns the value associated with this key.String
getFullKey(String key)
Returns the full key.ConfigData
getNode(String key)
Returns the ConfigData object associated with this key.protected abstract String
getValue(String fullKey)
Returns the value for the specified full key from the flat representation of the hierarchically organized key-value pairs.
-
-
-
Constructor Detail
-
FlatConfigData
public FlatConfigData(String path)
Creates a new instance for the specified path.
-
-
Method Detail
-
getFullKey
public String getFullKey(String key)
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
public String get(String key)
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
public ConfigData getNode(String key)
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
protected abstract String getValue(String fullKey)
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
protected abstract ConfigData createConfigData(String path)
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.
-
-