org.apache.crimson.tree
Class ElementNode2

java.lang.Object
  extended byorg.apache.crimson.tree.NodeBase
      extended byorg.apache.crimson.tree.ParentNode
          extended byorg.apache.crimson.tree.NamespacedNode
              extended byorg.apache.crimson.tree.ElementNode2
All Implemented Interfaces:
org.w3c.dom.Element, ElementEx, org.w3c.dom.Node, NodeEx, org.w3c.dom.NodeList, XmlWritable
Direct Known Subclasses:
ElementNode

public class ElementNode2
extends NamespacedNode
implements ElementEx

Modified version of ElementNode to support DOM Level 2 methods. This class is named ElementNode2 for backward compatibility since old DOM Level 1 apps may have subclassed ElementNode. This class represents XML elements in a parse tree, and is often subclassed to add custom behaviors. When an XML Document object is built using an XmlDocumentBuilder instance, simple declarative configuration information may be used to control whether this class, or some specialized subclass (e.g. supporting HTML DOM methods) is used for elements in the resulting tree.

As well as defining new methods to provide behaviors which are specific to application frameworks, such as Servlets or Swing, such subclasses may also override methods such as doneParse and appendChild to perform some kinds of processing during tree construction. Such processing can include transforming tree structure to better suit the needs of a given application. When such transformation is done, the XmlWritable methods may need to be overridden to make elements transform themselves back to XML without losing information. (One common transformation is eliminating redundant representations of data; attributes of an XML element may correspond to defaultable object properties, and so on.)

Element nodes also support a single userObject property, which may be used to bind objects to elements where subclassing is either not possible or is inappropriate. For example, user interface objects often derive from java.awt.Component, so that they can't extend a different class (ElementNode).

Author:
David Brownell, Edwin Goei
See Also:
XmlDocumentBuilder

Nested Class Summary
 
Nested classes inherited from class org.apache.crimson.tree.NamespacedNode
ParentNode.TagList, ParentNode.TagListNS
 
Field Summary
protected  AttributeSet attributes
           
private  String idAttributeName
           
private static char[] tagEnd
           
private static char[] tagStart
           
private  Object userObject
           
 
Fields inherited from class org.apache.crimson.tree.NamespacedNode
namespaceURI, ownerDocument, qName, readonly
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
ElementNode2(String namespaceURI, String qName)
           
 
Method Summary
(package private) static void checkArguments(String namespaceURI, String qualifiedName)
           
(package private)  void checkChildType(int type)
           
 org.w3c.dom.Node cloneNode(boolean deep)
          Creates a new unparented node whose attributes are the same as this node's attributes; if deep is true, the children of this node are cloned as children of the new node.
(package private)  ElementNode2 createCopyForImportNode(boolean deep)
           
 String getAttribute(String name)
          DOM: Returns the value of the named attribute, or an empty string
 org.w3c.dom.Attr getAttributeNode(String name)
          DOM: returns the attribute
 org.w3c.dom.Attr getAttributeNodeNS(String namespaceURI, String localName)
          Retrieves an Attr node by local name and namespace URI.
 String getAttributeNS(String namespaceURI, String localName)
          Retrieves an attribute value by local name and namespace URI.
 org.w3c.dom.NamedNodeMap getAttributes()
          DOM: Returns the attributes of this element.
 String getIdAttributeName()
          Returns the name of the element's ID attribute, if one is known.
 short getNodeType()
          DOM: Returns the ELEMENT_NODE node type.
 String getTagName()
          DOM: Returns the name of the XML tag for this element.
 Object getUserObject()
          Returns the object associated with this element.
 boolean hasAttribute(String name)
          Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.
 boolean hasAttributeNS(String namespaceURI, String localName)
          Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.
 boolean hasAttributes()
          Returns whether this node (if it is an element) has any attributes.
(package private)  ElementNode2 makeClone()
          Make a clone of this node and return it.
 void removeAttribute(String name)
          DOM: Remove the named attribute.
 org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr oldAttr)
          DOM: removes the attribute with the same name as this one
 void removeAttributeNS(String namespaceURI, String localName)
          DOM2:
 void setAttribute(String name, String value)
          DOM: Assigns or modifies the value of the specified attribute.
 org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr newAttr)
          DOM: assigns the attribute
 org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
          DOM2:
 void setAttributeNS(String namespaceURI, String qualifiedName, String value)
          DOM2:
(package private)  void setAttributes(AttributeSet a)
           
 void setIdAttributeName(String attName)
          Assigns the name of the element's ID attribute; only one attribute may have the ID type.
 void setReadonly(boolean deep)
          Sets the node to be readonly; applies recursively to the children of this node if the parameter is true.
 void setUserObject(Object userObject)
          Assigns an object to be associated with this element.
 String toString()
          Returns the element and its content as a string, which includes all the markup embedded in this element.
 void trimToSize()
          Requests that the element minimize the amount of space it uses, to conserve memory.
 void write(Writer out)
          Convenience method to construct a non-prettyprinting XML write context and call writeXml with it.
 void writeXml(XmlWriteContext context)
          Writes this element and all of its children out, as well formed XML.
 
Methods inherited from class org.apache.crimson.tree.NamespacedNode
appendChild, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFirstChild, getIndexOf, getInheritedAttribute, getLanguage, getLastChild, getLength, getLocalName, getMessage, getMessage, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentImpl, getParentNode, getPrefix, getPreviousSibling, hasChildNodes, insertBefore, isReadonly, isSupported, item, normalize, reduceWaste, removeChild, removeWhiteSpaces, replaceChild, setNodeValue, setOwnerDocument, setParentNode, setPrefix, writeChildrenXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Element
getElementsByTagName, getElementsByTagNameNS
 
Methods inherited from interface org.w3c.dom.Node
appendChild, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 
Methods inherited from interface org.apache.crimson.tree.NodeEx
getIndexOf, getInheritedAttribute, getLanguage, isReadonly
 
Methods inherited from interface org.apache.crimson.tree.XmlWritable
writeChildrenXml
 

Field Detail

attributes

protected AttributeSet attributes

idAttributeName

private String idAttributeName

userObject

private Object userObject

tagStart

private static final char[] tagStart

tagEnd

private static final char[] tagEnd
Constructor Detail

ElementNode2

public ElementNode2(String namespaceURI,
                    String qName)
             throws DomEx
Method Detail

makeClone

ElementNode2 makeClone()
Make a clone of this node and return it. Used for cloneNode().


createCopyForImportNode

ElementNode2 createCopyForImportNode(boolean deep)
Returns:
New ElementNode2 which is a copy of "this" but without attributes that are defaulted in the original document. Used to implement Document.importNode().

checkArguments

static void checkArguments(String namespaceURI,
                           String qualifiedName)
                    throws DomEx
Throws:
DomEx

trimToSize

public void trimToSize()
Description copied from interface: ElementEx
Requests that the element minimize the amount of space it uses, to conserve memory. Children are not affected.

Specified by:
trimToSize in interface ElementEx
Overrides:
trimToSize in class ParentNode

setAttributes

void setAttributes(AttributeSet a)

checkChildType

void checkChildType(int type)
              throws org.w3c.dom.DOMException
Specified by:
checkChildType in class ParentNode
Throws:
org.w3c.dom.DOMException

setReadonly

public void setReadonly(boolean deep)
Description copied from interface: NodeEx
Sets the node to be readonly; applies recursively to the children of this node if the parameter is true.

Specified by:
setReadonly in interface NodeEx
Overrides:
setReadonly in class NodeBase

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()
DOM: Returns the attributes of this element.

Specified by:
getAttributes in interface org.w3c.dom.Node
Overrides:
getAttributes in class NodeBase

hasAttributes

public boolean hasAttributes()
Returns whether this node (if it is an element) has any attributes.

Specified by:
hasAttributes in interface org.w3c.dom.Node
Overrides:
hasAttributes in class NodeBase
Since:
DOM Level 2

toString

public String toString()
Returns the element and its content as a string, which includes all the markup embedded in this element. If the element is not fully constructed, the content will not be an XML tag.

Overrides:
toString in class Object
Returns:
a string representation of the object.

writeXml

public void writeXml(XmlWriteContext context)
              throws IOException
Writes this element and all of its children out, as well formed XML.

Specified by:
writeXml in interface XmlWritable
Throws:
IOException

setIdAttributeName

public void setIdAttributeName(String attName)
Assigns the name of the element's ID attribute; only one attribute may have the ID type. XML supports a kind of validatable internal linking using ID attributes, with IDREF attributes identifying specific nodes (and IDREFS attributes identifying sets of them).


getIdAttributeName

public String getIdAttributeName()
Returns the name of the element's ID attribute, if one is known.

Specified by:
getIdAttributeName in interface ElementEx
Returns:
the name of the ID attribute

setUserObject

public void setUserObject(Object userObject)
Description copied from interface: ElementEx
Assigns an object to be associated with this element.

Specified by:
setUserObject in interface ElementEx

getUserObject

public Object getUserObject()
Description copied from interface: ElementEx
Returns the object associated with this element. In cases where more than one such object must be so associated, the association must be maintained externally.

Specified by:
getUserObject in interface ElementEx

getNodeType

public short getNodeType()
DOM: Returns the ELEMENT_NODE node type.

Specified by:
getNodeType in interface org.w3c.dom.Node

getTagName

public String getTagName()
DOM: Returns the name of the XML tag for this element.

Specified by:
getTagName in interface org.w3c.dom.Element

hasAttribute

public boolean hasAttribute(String name)
Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

Specified by:
hasAttribute in interface org.w3c.dom.Element
Since:
DOM Level 2

hasAttributeNS

public boolean hasAttributeNS(String namespaceURI,
                              String localName)
Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.

Specified by:
hasAttributeNS in interface org.w3c.dom.Element
Since:
DOM Level 2

getAttribute

public String getAttribute(String name)
DOM: Returns the value of the named attribute, or an empty string

Specified by:
getAttribute in interface org.w3c.dom.Element

getAttributeNS

public String getAttributeNS(String namespaceURI,
                             String localName)
Retrieves an attribute value by local name and namespace URI.

Specified by:
getAttributeNS in interface org.w3c.dom.Element
Since:
DOM Level 2

getAttributeNodeNS

public org.w3c.dom.Attr getAttributeNodeNS(String namespaceURI,
                                           String localName)
Retrieves an Attr node by local name and namespace URI.

Specified by:
getAttributeNodeNS in interface org.w3c.dom.Element
Since:
DOM Level 2

setAttribute

public void setAttribute(String name,
                         String value)
                  throws org.w3c.dom.DOMException
DOM: Assigns or modifies the value of the specified attribute.

Specified by:
setAttribute in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

setAttributeNS

public void setAttributeNS(String namespaceURI,
                           String qualifiedName,
                           String value)
                    throws org.w3c.dom.DOMException
DOM2:

Specified by:
setAttributeNS in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException
Since:
DOM Level 2

setAttributeNodeNS

public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
                                    throws org.w3c.dom.DOMException
DOM2:

Specified by:
setAttributeNodeNS in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException
Since:
DOM Level 2

removeAttribute

public void removeAttribute(String name)
                     throws org.w3c.dom.DOMException
DOM: Remove the named attribute.

Specified by:
removeAttribute in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

removeAttributeNS

public void removeAttributeNS(String namespaceURI,
                              String localName)
                       throws org.w3c.dom.DOMException
DOM2:

Specified by:
removeAttributeNS in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException
Since:
DOM Level 2

getAttributeNode

public org.w3c.dom.Attr getAttributeNode(String name)
DOM: returns the attribute

Specified by:
getAttributeNode in interface org.w3c.dom.Element

setAttributeNode

public org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr newAttr)
                                  throws org.w3c.dom.DOMException
DOM: assigns the attribute

Specified by:
setAttributeNode in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

removeAttributeNode

public org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr oldAttr)
                                     throws org.w3c.dom.DOMException
DOM: removes the attribute with the same name as this one

Specified by:
removeAttributeNode in interface org.w3c.dom.Element
Throws:
org.w3c.dom.DOMException

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)
Creates a new unparented node whose attributes are the same as this node's attributes; if deep is true, the children of this node are cloned as children of the new node.

Specified by:
cloneNode in interface org.w3c.dom.Node

write

public void write(Writer out)
           throws IOException
Convenience method to construct a non-prettyprinting XML write context and call writeXml with it. Subclasses may choose to to override this method to generate non-XML text,

Parameters:
out - where to emit the XML content of this node
Throws:
IOException