Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jcckit.util
Class FlatConfigData

    java.lang.Object
      jcckit.util.FlatConfigData

All Implemented Interfaces:
  ConfigData

Direct Known Subclasses:
  AppletBasedConfigData, PropertiesBasedConfigData

public abstract class FlatConfigData
extends java.lang.Object
implements ConfigData

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 = 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
`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

### FlatConfigData

    public FlatConfigData(java.lang.String path)

  Creates a new instance for the specified path.

Method Detail

### getFullKey

    public java.lang.String getFullKey(java.lang.String key)

  Returns the full key.

  Specified by:
    `getFullKey` in interface `ConfigData`
  Parameters:
    `key` - A (relative) key. `null` is not allowed.
  Returns:
    the path concatenated with `key` or `key` if the path is undefined.

### get

    public java.lang.String get(java.lang.String key)

  Returns the value associated with this key.

  Specified by:
    `get` in interface `ConfigData`
  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(java.lang.String key)

  Returns the `ConfigData` object associated with this key.

  Specified by:
    `getNode` in interface `ConfigData`
  Parameters:
    `key` - The relative key.
  Returns:
    the associated value. Will never return `null`. Instead an empty `ConfigData` is returned.

### getValue

    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.

  Parameters:
    `fullKey` - The full key including path. `null` is not allowed.
  Returns:
    the value or `null` if not found.

### createConfigData

    protected abstract ConfigData createConfigData(java.lang.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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD