simkin
Class XMLElementObject

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

public class XMLElementObject
extends ExecutableRoot

This object is a container for an XML element, and exposes an interface to it to Simkin The class implements methods from the Executable interface.

The method getValue, setValue and method all search for matching element tags within the XML document. Only the first matching tag is used.


Constructor Summary
XMLElementObject()
          Default Constructor
XMLElementObject(org.w3c.dom.Element elem)
          Constructor which takes an Element
 
Method Summary
 void copyItemsInto(org.w3c.dom.Element other)
          Clears the other element and does a deep copy of the children of this node into that one
 void dump()
          This method writes the entire XML element out to the tracer
 XMLElementObjectEnumerator enumerate()
          This method returns an object which can iterate over all the immediate child elements of this element
 XMLElementObjectEnumerator enumerate(java.lang.String tagName)
          This method returns an object which can iterate over all the immediate child elements of this element whose tagname matches the one given
 boolean equals(java.lang.Object o)
          tests for equality with another object, using the string value
static org.w3c.dom.Element findChild(org.w3c.dom.Element parent, java.lang.String tagname)
          returns a child element
static org.w3c.dom.Element findChild(org.w3c.dom.Element parent, java.lang.String tagname, java.lang.String attribute, java.lang.String value)
          returns a child element with the given attribute set to the given value
 java.lang.String getAttribute(java.lang.String name)
          This method returns the value of an attribute attached to this element.
static java.lang.String getData(org.w3c.dom.Element element)
          retrieves the text data from an element
 org.w3c.dom.Element getElement()
          This method returns the XML Element being held by the object.
 java.lang.Object getValue(java.lang.String name, java.lang.String attrib)
          Retrieves a field from the XML.
 java.lang.Object method(java.lang.String s, java.lang.Object[] args)
          this method attempts to execute a method stored in the XML.
 void setAttribute(java.lang.String name, java.lang.String value)
          Sets an attribute on this node
static void setData(org.w3c.dom.Element element, java.lang.String data)
          sets the text data for a node by looking for the first CDATA and TEXT child node
 void setValue(java.lang.String name, java.lang.String attrib, java.lang.Object v)
          sets the value of an item in the element.
 java.lang.String toString()
           
 
Methods inherited from class simkin.ExecutableRoot
setTracer
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLElementObject

public XMLElementObject()
Default Constructor

XMLElementObject

public XMLElementObject(org.w3c.dom.Element elem)
Constructor which takes an Element
Parameters:
elem - the element to be stored
Method Detail

toString

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

setValue

public void setValue(java.lang.String name,
                     java.lang.String attrib,
                     java.lang.Object v)
              throws java.lang.RuntimeException,
                     java.lang.NoSuchFieldException
sets the value of an item in the element. If the value passed is an element, it is first copied.
Overrides:
setValue in class ExecutableRoot
Parameters:
name - the name of the element tag to set (null if it's the overall element)
attrib - the name of the attribute to set (null to set text for the element)
Throws:
java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)
java.lang.NoSuchFieldException - - if the field could not be found

copyItemsInto

public void copyItemsInto(org.w3c.dom.Element other)
Clears the other element and does a deep copy of the children of this node into that one
Parameters:
child - - the element into which our children will be copied

equals

public boolean equals(java.lang.Object o)
tests for equality with another object, using the string value
Overrides:
equals in class java.lang.Object
Returns:
true if the data in both elements is the same

getElement

public org.w3c.dom.Element getElement()
This method returns the XML Element being held by the object.
Returns:
the underlying Element

getValue

public java.lang.Object getValue(java.lang.String name,
                                 java.lang.String attrib)
                          throws java.lang.RuntimeException,
                                 java.lang.NoSuchFieldException
Retrieves a field from the XML. The value returned is an XMLElementObject, unless the attrib value is specified
Overrides:
getValue in class ExecutableRoot
Parameters:
name - the tag name containing the data
attrib - the attribute name to retrieve
Returns:
the value of the field
Throws:
java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)
java.lang.NoSuchFieldException - - if the field could not be found

getData

public static java.lang.String getData(org.w3c.dom.Element element)
retrieves the text data from an element
Parameters:
element -  
Returns:
the text from a child node of type CDATA or TEXT

setData

public static void setData(org.w3c.dom.Element element,
                           java.lang.String data)
sets the text data for a node by looking for the first CDATA and TEXT child node
Parameters:
element - the element to be changed
data - the data to be set

findChild

public static org.w3c.dom.Element findChild(org.w3c.dom.Element parent,
                                            java.lang.String tagname)
returns a child element
Parameters:
parent - the parent element
tagname - the tag name of the element
Returns:
the first element child of the parent with the matching tag name, or null if not found

findChild

public static org.w3c.dom.Element findChild(org.w3c.dom.Element parent,
                                            java.lang.String tagname,
                                            java.lang.String attribute,
                                            java.lang.String value)
returns a child element with the given attribute set to the given value
Parameters:
parent - the parent element
tagname - the tag name of the element
attribute - name of the attribute
value - value of the named attribute
Returns:
the first element child of the parent with the matching tag name and attribute value, or null if not found

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Sets an attribute on this node

getAttribute

public java.lang.String getAttribute(java.lang.String name)
This method returns the value of an attribute attached to this element.
Returns:
the value of the given attribute

enumerate

public XMLElementObjectEnumerator enumerate()
This method returns an object which can iterate over all the immediate child elements of this element

enumerate

public XMLElementObjectEnumerator enumerate(java.lang.String tagName)
This method returns an object which can iterate over all the immediate child elements of this element whose tagname matches the one given

dump

public void dump()
This method writes the entire XML element out to the tracer

method

public java.lang.Object method(java.lang.String s,
                               java.lang.Object[] args)
                        throws ParseException,
                               java.lang.RuntimeException,
                               java.lang.NoSuchMethodException
this method attempts to execute a method stored in the XML. It searches for an element whose tag matches the method name and if found passes the text for the tag through to the interpeter
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
java.lang.RuntimeException - if there was an error running the code
java.lang.NoSuchMethodException - if the method could not be found