at.knowcenter.wag.egov.egiz.cfg
Class PropertyTree

java.lang.Object
  extended by at.knowcenter.wag.egov.egiz.cfg.PropertyTree
All Implemented Interfaces:
Serializable

public class PropertyTree
extends Object
implements Serializable

This class can be used to store a property config tree. The property key are separated by the SPLIT_STRING. Therefore the keys an also the values of a configuration is stored in nested hashes. The keys in an area are stored in a HashMap. The values of a key are stored in a Vector to overload some keys. The property tree can be used to extract sub nodes and sub keys of different tree levels.

Author:
wlackner
See Also:
HashMap, Vector, Serialized Form

Field Summary
static String SPLIT_STRING
          The key split string.
 
Constructor Summary
PropertyTree()
          The default constructor od the class.
 
Method Summary
 boolean containsNode(String key)
          This method checks if a key is a reference to a sub tree in the current node.
 String getFirstValue(String key)
          Returns the first value (keys can be overloaded) of a key.
 Map getKeyEntries()
          This method return all keys (sub tree references) of the current node as a Map.
 ArrayList getKeys()
          This method return all keys (sub tree references) of the current node as an ArrayList.
 ArrayList getKeys(String key)
          This method return all sub tree references of a key as an ArrayList.
 String getLastValue(String key)
          Returns the last value (keys can be overloaded) of a key.
 PropertyTree getSubTree(String key)
          Extracts a sub tree of a nested key.
 Vector getValues()
          This method return all values of the current node.
 Vector getValues(String key)
          This method return all values of a key.
 void setKeyValue(String splitKey, String value)
          This method takes a key value tupel and store them in the property tree.
 String toString()
          The default toString method.
static String toString(String prefix, PropertyTree tree)
          The toString method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SPLIT_STRING

public static final String SPLIT_STRING
The key split string. A key can be a complex key. Sub keys are separated from each other with the split string. This string is used to devide the complex key.

See Also:
Constant Field Values
Constructor Detail

PropertyTree

public PropertyTree()
The default constructor od the class.

Method Detail

setKeyValue

public void setKeyValue(String splitKey,
                        String value)
This method takes a key value tupel and store them in the property tree. The key splitted into different levels (splitted by the string SPLIT_STRING). All subnodes not stored in the tree will be created. The last part of the key (last splitted element) adds the value to there own value data structure (Vector).
Example: setKeyValue("key.1_level.2_level","the value for k_1_2")
Parameters:
splitKey - the key that has to be store the value
value - only String values can be stored

getLastValue

public String getLastValue(String key)
Returns the last value (keys can be overloaded) of a key. The key are splitted into subnodes and the last node of the key is the current value holder. If a key or subnode is not in the sub tree the return value is null.

Parameters:
key - the key that holds the value (can be a nested key like "key.1.2.3")
Returns:
the value of the key (last node of the key) or null otherwise

getFirstValue

public String getFirstValue(String key)
Returns the first value (keys can be overloaded) of a key. The key are splitted into subnodes and the last node of the key is the current value holder. If a key or subnode is not in the sub tree the return value is null.

Parameters:
key - the key that holds the value (can be a nested key like "key.1.2.3")
Returns:
the value of the key (last node of the key) or null otherwise

getValues

public Vector getValues()
This method return all values of the current node. The values are stored as String values.

Returns:
the values (type String) of the current node
See Also:
Vector

getKeyEntries

public Map getKeyEntries()
This method return all keys (sub tree references) of the current node as a Map. The keys are stored as String values.

Returns:
the keys (type String) of the current node
See Also:
Map

getKeys

public ArrayList getKeys()
This method return all keys (sub tree references) of the current node as an ArrayList. The keys are stored as String values.

Returns:
the keys (type String) of the current node
See Also:
ArrayList

getKeys

public ArrayList getKeys(String key)
This method return all sub tree references of a key as an ArrayList. The keys are stored as String values.

Parameters:
key - (can be a nested key like "key.1.2.3")
Returns:
the keys (type String) of the current node
See Also:
ArrayList

getValues

public Vector getValues(String key)
This method return all values of a key. The values are stored as String values.

Parameters:
key - (can be a nested key like "key.1.2.3")
Returns:
the values (type Vector) of the key or null if the key is not in the sub tree of the current node
See Also:
Vector

getSubTree

public PropertyTree getSubTree(String key)
Extracts a sub tree of a nested key. The Method returns the last sub tree of the nested key. Example: if the key is like: key.1.2.3 the sub tree of the last node 3 is returned.

Parameters:
key - the reference of the sub tree
Returns:
a sub tree of the key or null if the key can not be found

containsNode

public boolean containsNode(String key)
This method checks if a key is a reference to a sub tree in the current node.

Parameters:
key - a simple key that is a parent reference of a sub tree
Returns:
true if the key is found, false otherwise

toString

public String toString()
The default toString method. It starts with the current node recursively downwards and return the String representation of the node.

Overrides:
toString in class Object
Returns:
the string representation of the node

toString

public static String toString(String prefix,
                              PropertyTree tree)
The toString method. It starts with a special level prefix, sub tree and recursively adds all sub trees.

Parameters:
prefix - the prefix for this node
tree - the current node
Returns:
the string representation of the node


Copyright © 2006-2007 EGIZ - E-Government Innovationszentrum. All Rights Reserved.