BEA Systems, Inc.

com.beasys.commerce.util.dom
Class DocumentImpl

java.lang.Object
  |
  +--com.beasys.commerce.util.dom.DOMBase
        |
        +--com.beasys.commerce.util.dom.NodeImpl
              |
              +--com.beasys.commerce.util.dom.DocumentImpl

public class DocumentImpl
extends NodeImpl
implements org.w3c.dom.Document, org.w3c.dom.DOMImplementation

An implementation of the W3C's DOM Document object.

Although we store the DocType and the root Element in instance variables, we also store them as children. Therefore, this will override the adding children methods to guarentee that the instance variables are also set. I'm also assuming that a document can only have 1 DocumentType child, as well as only 1 Element child.

See Also:
Serialized Form

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
DocumentImpl()
          Constructor.
DocumentImpl(org.w3c.dom.DocumentType docType)
          Constructor.
 
Method Summary
 org.w3c.dom.Node appendChild(org.w3c.dom.Node child)
          Override to check if the new node is an element or document-type.
 org.w3c.dom.Node cloneNode()
          Clone this node.
 org.w3c.dom.Attr createAttribute(java.lang.String name)
          Create an Attribute.
 org.w3c.dom.CDATASection createCDATASection(java.lang.String data)
          Create a CDATASection.
 org.w3c.dom.Comment createComment(java.lang.String data)
          Create a Comment.
 org.w3c.dom.DocumentFragment createDocumentFragment()
          Create a DocumentFragment.
 org.w3c.dom.Element createElement(java.lang.String tagName)
          Create an Element.
 org.w3c.dom.EntityReference createEntityReference(java.lang.String name)
          Create an EntityReference.
 org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data)
          Create a ProcessingInstruction.
 org.w3c.dom.Text createTextNode(java.lang.String data)
          Create a Text node.
 org.w3c.dom.DocumentType getDoctype()
          Get the DocType of the document.
 org.w3c.dom.Element getDocumentElement()
          Get the document element.
static org.w3c.dom.NodeList getElementsByTagName(org.w3c.dom.Node node, java.lang.String tagName)
          Get a NodeList of all Elements under a node with the given tag name.
static void getElementsByTagName(org.w3c.dom.Node node, java.lang.String tagName, java.util.Vector list)
          Get all the Elements under a node with the given tag name and put them into the specified Vector.
 org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
          Find all the children Elements with the given tagName.
 org.w3c.dom.DOMImplementation getImplementation()
          Get the DOMImplementation object.
static java.util.Vector getNodeListVector(org.w3c.dom.NodeList list)
          Get a copy of a NodeList as a Vector.
 java.lang.String getNodeName()
          Return #document.
 short getNodeType()
          Return Node.DOCUMENT_NODE.
 boolean hasFeature(java.lang.String feature, java.lang.String version)
          Tests if the DOM implementation implements a specific feature.
 org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
          Override to check if the new node is an element or document-type.
static void normalize(org.w3c.dom.Node node)
          Normalize (tree-recursive) any adjacent Text nodes under the supplied node.
 org.w3c.dom.Node removeChild(org.w3c.dom.Node child)
          Override to check if the new node is an element or document-type.
 org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
          Override to check if the new node is an element or document-type.
 
Methods inherited from class com.beasys.commerce.util.dom.NodeImpl
cloneNode, getAttributes, getChildNodes, getFirstChild, getLastChild, getNextSibling, getNodeType, getNodeValue, getParentNode, getPreviousSibling, hasChildNodes, setNodeValue, setParentNode
 
Methods inherited from class com.beasys.commerce.util.dom.DOMBase
checkOwnerDocument, getOwnerDocument, isReadOnly, setReadOnly
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentImpl

public DocumentImpl(org.w3c.dom.DocumentType docType)
Constructor.

DocumentImpl

public DocumentImpl()
Constructor.
Method Detail

cloneNode

public org.w3c.dom.Node cloneNode()
Clone this node.
Overrides:
cloneNode in class NodeImpl

getNodeType

public short getNodeType()
Return Node.DOCUMENT_NODE.
Overrides:
getNodeType in class NodeImpl

getNodeName

public java.lang.String getNodeName()
Return #document.
Overrides:
getNodeName in class NodeImpl

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.Node child)
                             throws org.w3c.dom.DOMException
Override to check if the new node is an element or document-type.

If the new node is an Element, we will remove the previous documentElement, and then set documentElement to the new Element. Similarily, if the new node is a DocumentType, we will remove the previous docType, and then set docType to tne new DocumentType.

Overrides:
appendChild in class NodeImpl
Parameters:
child - the child to append.
Returns:
child.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be added.

insertBefore

public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node refChild)
                              throws org.w3c.dom.DOMException
Override to check if the new node is an element or document-type.

If the new node is an Element, we will remove the previous documentElement, and then set documentElement to the new Element. Similarily, if the new node is a DocumentType, we will remove the previous docType, and then set docType to tne new DocumentType.

Overrides:
insertBefore in class NodeImpl
Parameters:
newChild - the child to insert.
refChild - the child to insert before.
Returns:
newChild.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be added.

removeChild

public org.w3c.dom.Node removeChild(org.w3c.dom.Node child)
                             throws org.w3c.dom.DOMException
Override to check if the new node is an element or document-type.

If the removed child was our documentElement, we will clear our documentElement. If the remove child was our docType, we will clear our docType.

Overrides:
removeChild in class NodeImpl
Parameters:
child - the child to remove.
Returns:
child.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be removed.

replaceChild

public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node oldChild)
                              throws org.w3c.dom.DOMException
Override to check if the new node is an element or document-type.

If the oldChild was our documentElement: if the newChild is an Element, we will set documentElement to it; otherwise, we will clear documentElement. If the oldChild was our docType: if the newChild is a docType, we will set docType to it; otherwise, we will clear docType.

Overrides:
replaceChild in class NodeImpl
Parameters:
newChild - the new child.
oldChild - the child to replace.
Returns:
oldChild.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be replaced.

createAttribute

public org.w3c.dom.Attr createAttribute(java.lang.String name)
Create an Attribute.
Specified by:
createAttribute in interface org.w3c.dom.Document
Parameters:
name - the attribute name.
Returns:
a new Attr.
See Also:
AttrImpl

createCDATASection

public org.w3c.dom.CDATASection createCDATASection(java.lang.String data)
Create a CDATASection.
Specified by:
createCDATASection in interface org.w3c.dom.Document
Parameters:
data - the character data.
Returns:
a new CDATASection.
See Also:
CDATASectionImpl

createComment

public org.w3c.dom.Comment createComment(java.lang.String data)
Create a Comment.
Specified by:
createComment in interface org.w3c.dom.Document
Parameters:
data - the character data.
Returns:
a new Comment.
See Also:
CommentImpl

createDocumentFragment

public org.w3c.dom.DocumentFragment createDocumentFragment()
Create a DocumentFragment.
Specified by:
createDocumentFragment in interface org.w3c.dom.Document
Returns:
a new DocumentFragment.
See Also:
DocumentFragmentImpl

createElement

public org.w3c.dom.Element createElement(java.lang.String tagName)
Create an Element.
Specified by:
createElement in interface org.w3c.dom.Document
Parameters:
tagName - the tagName.
Returns:
a new Element.
See Also:
ElementImpl

createEntityReference

public org.w3c.dom.EntityReference createEntityReference(java.lang.String name)
Create an EntityReference.
Specified by:
createEntityReference in interface org.w3c.dom.Document
Parameters:
name - the name of the entity to reference.
Returns:
a new EntityReference object.
See Also:
EntityReference

createProcessingInstruction

public org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target,
                                                                     java.lang.String data)
Create a ProcessingInstruction.
Specified by:
createProcessingInstruction in interface org.w3c.dom.Document
Parameters:
target - the target of the PI.
data - the data of the PI.
Returns:
a new ProcessingInstruction.
See Also:
ProcessingInstruction

createTextNode

public org.w3c.dom.Text createTextNode(java.lang.String data)
Create a Text node.
Specified by:
createTextNode in interface org.w3c.dom.Document
Parameters:
data - the text.
Returns:
a new Text.
See Also:
Text

getDoctype

public org.w3c.dom.DocumentType getDoctype()
Get the DocType of the document.
Specified by:
getDoctype in interface org.w3c.dom.Document
Returns:
the DocumentType or null.

getDocumentElement

public org.w3c.dom.Element getDocumentElement()
Get the document element.
Specified by:
getDocumentElement in interface org.w3c.dom.Document

getElementsByTagName

public org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
Find all the children Elements with the given tagName.
Specified by:
getElementsByTagName in interface org.w3c.dom.Document

getImplementation

public org.w3c.dom.DOMImplementation getImplementation()
Get the DOMImplementation object.
Specified by:
getImplementation in interface org.w3c.dom.Document

hasFeature

public boolean hasFeature(java.lang.String feature,
                          java.lang.String version)
Tests if the DOM implementation implements a specific feature.

This implementation only supports XML v1.0.

Specified by:
hasFeature in interface org.w3c.dom.DOMImplementation

getElementsByTagName

public static org.w3c.dom.NodeList getElementsByTagName(org.w3c.dom.Node node,
                                                        java.lang.String tagName)
Get a NodeList of all Elements under a node with the given tag name.
See Also:
getElementsByTagName(java.lang.String), ElementImpl.getElementsByTagName(java.lang.String)

getElementsByTagName

public static void getElementsByTagName(org.w3c.dom.Node node,
                                        java.lang.String tagName,
                                        java.util.Vector list)
Get all the Elements under a node with the given tag name and put them into the specified Vector.

getNodeListVector

public static java.util.Vector getNodeListVector(org.w3c.dom.NodeList list)
Get a copy of a NodeList as a Vector.

normalize

public static void normalize(org.w3c.dom.Node node)
Normalize (tree-recursive) any adjacent Text nodes under the supplied node.

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved