simkin
Class TreeNodeObject

java.lang.Object
  |
  +--simkin.ExecutableRoot
        |
        +--simkin.TreeNodeObject
All Implemented Interfaces:
Executable
Direct Known Subclasses:
ScriptedExecutable

public class TreeNodeObject
extends ExecutableRoot

This class provides and Executable interface to a TreeNode

The method getValue, setValue and method all search for matching child labels within the TreeNode object. Only the first matching tag is used.


Constructor Summary
TreeNodeObject()
          Default Constructor
TreeNodeObject(java.lang.String location, java.io.InputStream in)
          Constructor
TreeNodeObject(java.lang.String location, TreeNode node)
          Constructor
 
Method Summary
 TreeNodeObject addNode(java.lang.String label, java.lang.String data)
          this method adds a new child node with the given name and data
 boolean containsNode(java.lang.String label)
          this method returns true if the node contains a child with the given label
 ExecutableIterator createIterator()
          This method returns a TreeNodeObjectEnumerator object which is used in a foreach statement.
 ExecutableIterator createIterator(java.lang.String qualifier)
          This method returns a TreeNodeObjectEnumerator object which is used in a foreach statement.
protected  TreeNodeObject createTreeNodeObject(java.lang.String location, TreeNode node)
          This method creates a new TreeNodeObject object to wrap a treenode.
 java.lang.String data()
          returns the data for the underlying node
 void dump()
          This method writes the entire node tree to stdout
 TreeNodeObjectEnumerator enumerate()
          This method returns an object which can iterate over all the immediate child node of this node
 TreeNodeObjectEnumerator enumerate(java.lang.String label)
          This method returns an object which can iterate over all the immediate child nodes of this node whose label matches the one given
 boolean equals(java.lang.Object o)
           
 TreeNodeObject findChild(java.lang.String label)
          this method finds a new child node with the given name
 TreeNodeObject findChild(java.lang.String label, java.lang.String data)
          this method finds a new child node with the given name and data
 boolean getAddIfNotPresent()
          this returns the value of the flag controlling whether new elements are created as they are accessed
 java.lang.String getLocation()
          returns the location of this node
 TreeNode getNode()
           
 java.lang.Object getValue(java.lang.String s, java.lang.String attribute)
          this method retrieves a value from the in-memory treenode object.
 java.lang.Object getValueAt(java.lang.Object array_index, java.lang.String attribute)
          this method retrieves a value from the in-memory treenode object.
 java.lang.String label()
          returns the label for the underlying node
 void load(java.lang.String location, java.io.InputStream stream)
          loads the treenode from the given stream
 java.lang.Object method(java.lang.String s, java.lang.Object[] args)
          this method attempts to find the named method within the in-memory treenode object.
 TreeNodeObject nthChild(int index)
          this method finds the nth child node
 boolean removeNode(java.lang.String label)
          this method removes the first child node with the given label - it returns true if successfull
 void save(java.io.OutputStream out, boolean compiled)
          saves the treenode into the given stream
 void setAddIfNotPresent(boolean enable)
          sets the flag controlling whether new elements are created as they are accessed
 void setLocation(java.lang.String location)
          This method changes the location associated with this object
 void setNode(TreeNode node)
          sets the node and clears the method cache
 void setValue(java.lang.String s, java.lang.String attribute, java.lang.Object v)
          this method stores a value in the in-memory treenode object.
 void setValueAt(java.lang.Object array_index, java.lang.String attribute, java.lang.Object v)
          this method stores a value in the in-memory treenode object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeNodeObject

public TreeNodeObject()
Default Constructor

TreeNodeObject

public TreeNodeObject(java.lang.String location,
                      TreeNode node)
Constructor
Parameters:
location - location of this node
node - the treenode to be stored

TreeNodeObject

public TreeNodeObject(java.lang.String location,
                      java.io.InputStream in)
               throws java.io.IOException
Constructor
Parameters:
location - location of this node
in - a stream containing the node
Method Detail

setNode

public void setNode(TreeNode node)
sets the node and clears the method cache

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
the value of the treenode data as a string

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
Returns:
true if the data in both nodes is the same

getNode

public TreeNode getNode()
Returns:
the underlying treenode

setValue

public void setValue(java.lang.String s,
                     java.lang.String attribute,
                     java.lang.Object v)
              throws java.lang.RuntimeException,
                     FieldNotSupportedException
this method stores a value in the in-memory treenode object. If the value is of treenode type, the treenode is first copied and then stored. If the m_AddIfNotPresent flag is true, a new item will be added if one is not already present
Overrides:
setValue in class ExecutableRoot
Parameters:
s - the name of the value
v - the value itself
Throws:
java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)
FieldNotSupportedException - - if the field could not be found

setValueAt

public void setValueAt(java.lang.Object array_index,
                       java.lang.String attribute,
                       java.lang.Object v)
                throws java.lang.RuntimeException
this method stores a value in the in-memory treenode object. If the value is of treenode type, the treenode is first copied and then stored. If the m_AddIfNotPresent flag is true, a new item will be added if one is not already present with a blank label
Overrides:
setValueAt in class ExecutableRoot
Parameters:
array_index - the index of the item to update
v - the value itself
Throws:
java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)

getValueAt

public java.lang.Object getValueAt(java.lang.Object array_index,
                                   java.lang.String attribute)
                            throws java.lang.RuntimeException
this method retrieves a value from the in-memory treenode object. If the value retrieved is a treenode type, it is *not* copied. If the m_AddIfNotPresent flag is true, a new item will be added if one is not already present with a blank label
Overrides:
getValueAt in class ExecutableRoot
Parameters:
array_index - the name of the value
Returns:
the value or null
Throws:
java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)

getValue

public java.lang.Object getValue(java.lang.String s,
                                 java.lang.String attribute)
                          throws java.lang.RuntimeException,
                                 FieldNotSupportedException
this method retrieves a value from the in-memory treenode object. If the value retrieved is a treenode type, it is *not* copied. If the m_AddIfNotPresent flag is true, a new item will be added if one is not already present
Overrides:
getValue in class ExecutableRoot
Parameters:
s - the name of the value
Returns:
the value or null
Throws:
java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)
FieldNotSupportedException - - if the field could not be found

enumerate

public TreeNodeObjectEnumerator enumerate()
This method returns an object which can iterate over all the immediate child node of this node

enumerate

public TreeNodeObjectEnumerator enumerate(java.lang.String label)
This method returns an object which can iterate over all the immediate child nodes of this node whose label matches the one given

dump

public void dump()
This method writes the entire node tree to stdout

method

public java.lang.Object method(java.lang.String s,
                               java.lang.Object[] args)
                        throws ParseException,
                               java.lang.RuntimeException,
                               MethodNotSupportedException
this method attempts to find the named method within the in-memory treenode object. If it is found, the Interpreter is used to execute the method
Overrides:
method in class ExecutableRoot
Parameters:
s - the name of the method
args - an array of arguments to the method
ret - the object to receive the result of the method call
Returns:
true if the method was found, false otherwise
Throws:
ParseException - if the code contained syntax errors
MethodNotSupportedException - if the method could not be found
java.lang.RuntimeException - if there was an error running the code

load

public void load(java.lang.String location,
                 java.io.InputStream stream)
          throws java.io.IOException
loads the treenode from the given stream
Parameters:
location - the location of the node
in - the input stream containing the node

save

public void save(java.io.OutputStream out,
                 boolean compiled)
          throws java.io.IOException
saves the treenode into the given stream
Parameters:
out - the stream to write to
compiled - whether to store the treenode in compiled format

createTreeNodeObject

protected TreeNodeObject createTreeNodeObject(java.lang.String location,
                                              TreeNode node)
This method creates a new TreeNodeObject object to wrap a treenode. Override this for special behaviour in derived classes. In this method, the newly created object inherits this object's m_AddIfNotPresent flag

setAddIfNotPresent

public void setAddIfNotPresent(boolean enable)
sets the flag controlling whether new elements are created as they are accessed
Parameters:
enable - enables this feature (which by default is disabled)

getAddIfNotPresent

public boolean getAddIfNotPresent()
this returns the value of the flag controlling whether new elements are created as they are accessed
Returns:
true if the feature is enabled, otherwise false (the default)

addNode

public TreeNodeObject addNode(java.lang.String label,
                              java.lang.String data)
this method adds a new child node with the given name and data

removeNode

public boolean removeNode(java.lang.String label)
this method removes the first child node with the given label - it returns true if successfull

findChild

public TreeNodeObject findChild(java.lang.String label,
                                java.lang.String data)
this method finds a new child node with the given name and data
Parameters:
label - the label to match
data - the data to match
Returns:
a new TreeNodeObject wrapping the node found, or null

findChild

public TreeNodeObject findChild(java.lang.String label)
this method finds a new child node with the given name
Parameters:
label - the label to match
Returns:
a new TreeNodeObject wrapping the node found, or null

nthChild

public TreeNodeObject nthChild(int index)
this method finds the nth child node
Parameters:
index - the index to find
Returns:
a new TreeNodeObject wrapping the node found, or null

containsNode

public boolean containsNode(java.lang.String label)
this method returns true if the node contains a child with the given label

label

public java.lang.String label()
returns the label for the underlying node

data

public java.lang.String data()
returns the data for the underlying node

getLocation

public java.lang.String getLocation()
returns the location of this node

createIterator

public ExecutableIterator createIterator()
This method returns a TreeNodeObjectEnumerator object which is used in a foreach statement. This version iterates unconditionally over all the children of this node.
Overrides:
createIterator in class ExecutableRoot
Returns:
a new iterator object, or null if this object cannot be iterated

createIterator

public ExecutableIterator createIterator(java.lang.String qualifier)
This method returns a TreeNodeObjectEnumerator object which is used in a foreach statement. This version is iterates over the child nodes with the matching label.
Overrides:
createIterator in class ExecutableRoot
Parameters:
qualifier - - a string, children with a matching label will be returned
Returns:
a new iterator object, or null if this object cannot be iterated

setLocation

public void setLocation(java.lang.String location)
This method changes the location associated with this object