EAF 7.6 Util

com.lutris.util
Class KeywordValueTable

java.lang.Object
  extended by com.lutris.util.KeywordValueTable
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Config

public class KeywordValueTable
extends java.lang.Object
implements java.io.Serializable

Class that implements a recursive keyword/value table. The key is a string that is restricted to be a valid Java identifier. That is, starting with an letter and containing letters or digits. The characters '_' and '$' are also allowed and are treated as letters. The value maybe any object. A keyword and its value are collectively referred to as a field The table is recursive. Values of class KeywordValueTable are referred to as sections. A field of a section maybe addressed from the parent object using a dot ('.') separated name path.

Since:
Harmony 1.0
Version:
$Revision: 1.4 $
Author:
Mark Diekhans
See Also:
Serialized Form

Constructor Summary
KeywordValueTable()
          Constructor.
 
Method Summary
 boolean containsKey(java.lang.String keyword)
          Determine if the a field with the specified keyword exists.
 java.lang.Object get(java.lang.String keyword)
          Get the value of a field as an object.
 java.lang.Object get(java.lang.String keyword, java.lang.Object defaultValue)
          Get the value of a field as an object, return a default if it does not exist.
 KeywordValueTable getSection(java.lang.String keyword)
          Get the value of a section.
 java.lang.String getString(java.lang.String keyword)
          Get the value of a field as a string
 java.lang.String getString(java.lang.String keyword, java.lang.String defaultValue)
          Get the value of a field as a string, return a default if it does not exist.
 java.lang.String[] keys()
          Get the keywords in the table.
 java.lang.String[] leafKeys()
          Recursively get the keywords for the entire table.
protected  KeywordValueTable newSection()
          Allocate a new section.
 void remove(java.lang.String keyword)
          Delete a field, if the field does not exist, the operation is ignored.
 void set(java.lang.String keyword, java.lang.Object value)
          Set the value of a field.
 void setDefault(java.lang.String keyword, java.lang.Object defaultValue)
          Sets a default value for a keyword.
 java.lang.String toHtml()
          Convert to an Html representation.
 java.lang.String toString()
          Convert to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeywordValueTable

public KeywordValueTable()
Constructor.

Method Detail

newSection

protected KeywordValueTable newSection()
Allocate a new section. The default implementation of this method returns a new KeywordValueTable object. A class derived from KeywordValueTable overrides this method to create a new object of the derived type. Sections are only allocated by this method.

Returns:
A reference to a new section.

get

public java.lang.Object get(java.lang.String keyword)
                     throws com.lutris.util.KeywordValueException
Get the value of a field as an object.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
The object value or null if its not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or is a non-leaf element of the keyword is not a section.

get

public java.lang.Object get(java.lang.String keyword,
                            java.lang.Object defaultValue)
                     throws com.lutris.util.KeywordValueException
Get the value of a field as an object, return a default if it does not exist.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
defaultValue - The default value to return it the keyword does not exist.
Returns:
The object value or defaultValue if its not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or is a non-leaf element of the keyword is not a section.

getString

public java.lang.String getString(java.lang.String keyword)
                           throws com.lutris.util.KeywordValueException
Get the value of a field as a string

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
The result of calling toString on the value object or null if its not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or is a non-leaf element of the keyword is not a section.

getString

public java.lang.String getString(java.lang.String keyword,
                                  java.lang.String defaultValue)
                           throws com.lutris.util.KeywordValueException
Get the value of a field as a string, return a default if it does not exist.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
The result of calling toString on the value object or defaultValue if its not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or the value object is not a String.

getSection

public KeywordValueTable getSection(java.lang.String keyword)
                             throws com.lutris.util.KeywordValueException
Get the value of a section. The section is a value that is another KeywordValueTable object.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
A reference to the section object or null if not found.
Throws:
KeywordValueException - If the keyword is not syntactically legal or a non-leaf element of the keyword is not a section or the value object is not a KeywordValueTable.

set

public void set(java.lang.String keyword,
                java.lang.Object value)
         throws com.lutris.util.KeywordValueException
Set the value of a field. If a keyword path is specified and the subsections do not exist, they are created. If a field other than a KeywordValueTable is one of the intermediate sections in the path, it will be deleted and replaced by a section.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
value - The value to associate with the keyword. The value may not be null.
Throws:
KeywordValueException - If the keyword is not syntactically legal.

setDefault

public void setDefault(java.lang.String keyword,
                       java.lang.Object defaultValue)
                throws com.lutris.util.KeywordValueException
Sets a default value for a keyword. This method only sets a value for the specified keyword if a value is not already set for that keyword. If a value is not set for the keyword, then if a keyword path is specified and the subsections do not exist, they are created. If a field other than a KeywordValueTable is one of the intermediate sections in the path, it will be deleted and replaced by a section.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
defaultValue - The default value to associate with the keyword. The default value may not be null. The default value is only set if the specified keyword does not already have a value associated with it.
Throws:
KeywordValueException - If the keyword is not syntactically legal.

containsKey

public boolean containsKey(java.lang.String keyword)
                    throws com.lutris.util.KeywordValueException
Determine if the a field with the specified keyword exists.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Returns:
true if the code is in the table; false if its not.
Throws:
KeywordValueException - If the keyword is not syntactically legal.

keys

public java.lang.String[] keys()
Get the keywords in the table. This is only the keywords at the top level, its doesn't recurse.

Returns:
An string array of the keywords.

leafKeys

public java.lang.String[] leafKeys()
Recursively get the keywords for the entire table. This returns the full keyword of all leaf values.

Returns:
An string array of the keywords.

remove

public void remove(java.lang.String keyword)
            throws com.lutris.util.KeywordValueException
Delete a field, if the field does not exist, the operation is ignored.

Parameters:
keyword - The keyword of the field. This can be a simple keyword or a recursive, dot-seperated keyword path.
Throws:
KeywordValueException - If the keyword is not syntactically legal.

toString

public java.lang.String toString()
Convert to a string.

Overrides:
toString in class java.lang.Object
Returns:
Generate a string representation of this object.

toHtml

public java.lang.String toHtml()
Convert to an Html representation.

Returns:
the generated Html.

EAF 7.6 Util