Project JXTA

net.jxta.impl.document
Class DOMXMLElement

java.lang.Object
  extended by net.jxta.impl.document.TextElementCommon
      extended by net.jxta.impl.document.XMLElementCommon
          extended by net.jxta.impl.document.DOMXMLElement
All Implemented Interfaces:
Attributable, Element, TextElement, XMLElement
Direct Known Subclasses:
DOMXMLDocument

public class DOMXMLElement
extends XMLElementCommon

This class represent an element of an XML document. XML Documents are formed as a hierarchy of elements. Each element provides a proxy for DOM elements and the text nodes containing values.


Field Summary
protected  Node domNode
          The DOM node for which this element is a proxy.
protected  DOMXMLDocument root
           
 
Constructor Summary
protected DOMXMLElement(DOMXMLDocument root, Node node)
          Constructor for associating a DOM node with a StructuredDocument Element.
 
Method Summary
 String addAttribute(Attribute newAttrib)
          Adds an attribute with the given name and value.
 String addAttribute(String name, String value)
          Adds an attribute with the given name and value.
 void appendChild(TextElement element)
          Add a child element to this element
 boolean equals(Object element)
          Tests two elements for equality.
protected  Node getAssocNode()
          Returns the DOM Node associated with this StructuredDocument element.
 Attribute getAttribute(String name)
          returns a single attribute which matches the name provided.
 Enumeration getAttributes()
          Returns an enumerations of the attributes assosicated with this object.
 Enumeration getChildren()
          Returns an enumeration of the immediate children of this element
 Enumeration getChildren(String name)
          Returns an enumeration of the immediate children of this element whose name match the specified string.
 String getName()
          Get the name associated with an element.
 Element getParent()
          Get the parent of this element.
 StructuredDocument getRoot()
          Get the root element of the hierarchy this element belongs to.
 String getTextValue()
          Get the value (if any) associated with an element.
 
Methods inherited from class net.jxta.impl.document.TextElementCommon
appendChild, getChildren, getKey, getValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.jxta.document.Element
appendChild, getChildren, getKey, getValue
 

Field Detail

root

protected DOMXMLDocument root

domNode

protected Node domNode
The DOM node for which this element is a proxy.

Constructor Detail

DOMXMLElement

protected DOMXMLElement(DOMXMLDocument root,
                        Node node)
Constructor for associating a DOM node with a StructuredDocument Element.

Parameters:
root - the DOM not which is to be associated with this element.
Method Detail

getName

public String getName()
Get the name associated with an element.

Returns:
A string containing the name of this element.

getTextValue

public String getTextValue()
Get the value (if any) associated with an element.

Returns:
A string containing the value of this element, if any, otherwise null.

getRoot

public StructuredDocument getRoot()
Get the root element of the hierarchy this element belongs to.

Returns:
StructuredDocument root of this element's hierarchy.

getParent

public Element getParent()
Get the parent of this element. If the element has not been inserted into the Document then null is returned. If this element is the root of the Document then it returns itself.


appendChild

public void appendChild(TextElement element)
Add a child element to this element

Parameters:
element - the element to be added as a child

getChildren

public Enumeration getChildren()
Returns an enumeration of the immediate children of this element

Returns:
An enumeration containing all of the children of this element.

getChildren

public Enumeration getChildren(String name)
Returns an enumeration of the immediate children of this element whose name match the specified string.

Parameters:
name - The name which will be matched against.
Returns:
An enumeration containing all of the children of this element.

equals

public boolean equals(Object element)
Tests two elements for equality. For the XML document the definition of equality is:

Overrides:
equals in class Object
Parameters:
element - the element to be compared against.
Returns:
true if the elements are equal

getAssocNode

protected Node getAssocNode()
Returns the DOM Node associated with this StructuredDocument element.

Returns:
Node The DOM Node associated with this StructuredDocument element.

addAttribute

public String addAttribute(String name,
                           String value)
Adds an attribute with the given name and value. Some implementations may support only a single value for each distinct name. Others may support multiple values for each name. If the value being provided replaces some other value then that value is returned otherwise null is returned.

Parameters:
name - name of the attribute.
value - value for the attribute.
Returns:
String containing previous value for this name if the value is being replaced otherwise null.

addAttribute

public String addAttribute(Attribute newAttrib)
Adds an attribute with the given name and value. Some implementations may support only a single value for each distinct name. Others may support multiple values for each name. If the value being provided replaces some other value then that value is returned otherwise null is returned.

Parameters:
newAttrib - new attribute.
Returns:
String containing previous value for this name if the value is being replaced otherwise null.

getAttributes

public Enumeration getAttributes()
Returns an enumerations of the attributes assosicated with this object. Each element is of type Attribute.

Returns:
Enumeration the attributes associated with this object.

getAttribute

public Attribute getAttribute(String name)
returns a single attribute which matches the name provided. If no such named attribute exists then null is returned. For impelementations of this interface which support multiple values for each name only the first value will be returned. To access all values for a name you must use getAttributes.

Returns:
Attribute the attributes matching the given name.

JXTA J2SE