net.livesite.xml
Class XMLElement

java.lang.Object
  extended by net.livesite.xml.XMLElement

public class XMLElement
extends Object

An XML Element extension with utility methods manipulating children.

Author:
Ryan Gies

Constructor Summary
XMLElement(Document document, Element element)
          Proper constructor, wraps an existing element.
 
Method Summary
 Object createObject(String classname)
          Create this element's value (text content) as an object.
 XMLElement getChild(String tag)
          Get a single child element.
 Document getDocument()
          Gets the document for this instance.
 Element getElement()
          Gets the element for this instance.
 String getValue()
          Return the elements value.
 XMLElement newChild(String tag, Object content)
          Create a new child and append it to the list.
 XMLElement newChild(String tag, String content)
          Create a new child and append it to the list.
 void setDocument(Document document)
          Sets the document for this instance.
 void setElement(Element element)
          Sets the element for this instance.
 void setValue(Object value)
          Set the element's value.
 void setValue(String value)
          Set the element's value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLElement

public XMLElement(Document document,
                  Element element)
Proper constructor, wraps an existing element.

Parameters:
document - DOM
element - to wrap
Method Detail

getChild

public XMLElement getChild(String tag)
Get a single child element. If there are multiple children, the last one (in the underlying array) is choosen.

Parameters:
tag - name

newChild

public XMLElement newChild(String tag,
                           Object content)
Create a new child and append it to the list.

Parameters:
tag - name
content - object which supports toString()

newChild

public XMLElement newChild(String tag,
                           String content)
Create a new child and append it to the list.

Parameters:
tag - name
content - text content

getValue

public String getValue()
Return the elements value.

Returns:
text content

setValue

public void setValue(Object value)
Set the element's value.

Parameters:
value - object which supports toString()

setValue

public void setValue(String value)
Set the element's value.

Parameters:
value - new

createObject

public Object createObject(String classname)
                    throws ClassNotFoundException,
                           NoSuchMethodException,
                           InvocationTargetException,
                           InstantiationException,
                           IllegalAccessException
Create this element's value (text content) as an object. The class to create must have a constructor which accpets a single string parameter.

Parameters:
classname - like "java.lang.String"
Returns:
object of the requested classname
Throws:
ClassNotFoundException
NoSuchMethodException
InvocationTargetException
InstantiationException
IllegalAccessException

getElement

public Element getElement()
Gets the element for this instance.

Returns:
unwrapped element

setElement

public void setElement(Element element)
Sets the element for this instance.

Parameters:
element - to wrapped

setDocument

public void setDocument(Document document)
Sets the document for this instance.

Parameters:
document - DOM

getDocument

public Document getDocument()
Gets the document for this instance.

Returns:
DOM