org.apache.xerces.dom
Class DocumentImpl

java.lang.Object
  extended by org.apache.xerces.dom.NodeImpl
      extended by org.apache.xerces.dom.ChildNode
          extended by org.apache.xerces.dom.ParentNode
              extended by org.apache.xerces.dom.CoreDocumentImpl
                  extended by org.apache.xerces.dom.DocumentImpl
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Document, DocumentEvent, EventTarget, Node, NodeList, DocumentRange, DocumentTraversal
Direct Known Subclasses:
DeferredDocumentImpl, HTMLDocumentImpl, PSVIDocumentImpl, WMLDocumentImpl

public class DocumentImpl
extends CoreDocumentImpl
implements DocumentTraversal, DocumentEvent, DocumentRange

The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.

Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.

The DocumentImpl class also implements the DOM Level 2 DocumentTraversal interface. This interface is comprised of factory methods needed to create NodeIterators and TreeWalkers. The process of creating NodeIterator objects also adds these references to this document. After finishing with an iterator it is important to remove the object using the remove methods in this implementation. This allows the release of the references from the iterator objects to the DOM Nodes.

Note: When any node in the document is serialized, the entire document is serialized along with it.

Since:
PR-DOM-Level-1-19980818.
Version:
$Id: DocumentImpl.java 542096 2007-05-28 03:18:11Z mrglavas $
Author:
Arnaud Le Hors, IBM, Joe Kesselman, IBM, Andy Clark, IBM, Ralf Pfeiffer, IBM
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.xerces.dom.NodeImpl
DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_IS_CONTAINED, DOCUMENT_POSITION_PRECEDING, ELEMENT_DEFINITION_NODE, TREE_POSITION_ANCESTOR, TREE_POSITION_DESCENDANT, TREE_POSITION_DISCONNECTED, TREE_POSITION_EQUIVALENT, TREE_POSITION_FOLLOWING, TREE_POSITION_PRECEDING, TREE_POSITION_SAME_NODE
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
DocumentImpl()
          NON-DOM: Actually creating a Document is outside the DOM's spec, since it has to operate in terms of a particular implementation.
DocumentImpl(boolean grammarAccess)
          Constructor.
DocumentImpl(DocumentType doctype)
          For DOM2 support.
DocumentImpl(DocumentType doctype, boolean grammarAccess)
          For DOM2 support.
 
Method Summary
 Node cloneNode(boolean deep)
          Deep-clone a document, including fixing ownerDoc for the cloned children.
 Event createEvent(java.lang.String type)
          Introduced in DOM Level 2.
 NodeIterator createNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion)
          Create and return a NodeIterator.
 NodeIterator createNodeIterator(Node root, short whatToShow, NodeFilter filter)
          NON-DOM extension: Create and return a NodeIterator.
 Range createRange()
          This interface can be obtained from the object implementing the Document interface using binding-specific casting methods.
 TreeWalker createTreeWalker(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion)
          Create and return a TreeWalker.
 TreeWalker createTreeWalker(Node root, short whatToShow, NodeFilter filter)
          NON-DOM extension: Create and return a TreeWalker.
 DOMImplementation getImplementation()
          Retrieve information describing the abilities of this particular DOM implementation.
 
Methods inherited from class org.apache.xerces.dom.CoreDocumentImpl
abort, adoptNode, clone, createAttribute, createAttributeNS, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createDocumentType, createElement, createElementDefinition, createElementNS, createElementNS, createEntity, createEntityReference, createNotation, createProcessingInstruction, createTextNode, getAsync, getBaseURI, getDoctype, getDocumentElement, getDocumentURI, getDomConfig, getElementById, getElementsByTagName, getElementsByTagNameNS, getEncoding, getErrorChecking, getFeature, getIdentifier, getIdentifiers, getInputEncoding, getNodeName, getNodeType, getOwnerDocument, getStandalone, getStrictErrorChecking, getTextContent, getUserData, getVersion, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, insertBefore, isValidQName, isXMLName, load, loadXML, normalizeDocument, putIdentifier, removeChild, removeIdentifier, renameNode, replaceChild, saveXML, setAsync, setDocumentURI, setEncoding, setErrorChecking, setInputEncoding, setStandalone, setStrictErrorChecking, setTextContent, setUserData, setVersion, setXmlEncoding, setXmlStandalone, setXmlVersion
 
Methods inherited from class org.apache.xerces.dom.ParentNode
getChildNodes, getFirstChild, getLastChild, getLength, hasChildNodes, isEqualNode, item, normalize, setReadOnly
 
Methods inherited from class org.apache.xerces.dom.ChildNode
getNextSibling, getParentNode, getPreviousSibling
 
Methods inherited from class org.apache.xerces.dom.NodeImpl
addEventListener, appendChild, compareDocumentPosition, compareTreePosition, dispatchEvent, getAttributes, getLocalName, getNamespaceURI, getNodeValue, getPrefix, getReadOnly, getUserData, getUserData, hasAttributes, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, needsSyncChildren, removeEventListener, setNodeValue, setPrefix, setUserData, setUserData, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
appendChild, compareDocumentPosition, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getParentNode, getPrefix, getPreviousSibling, getUserData, hasAttributes, hasChildNodes, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, setNodeValue, setPrefix, setUserData
 

Constructor Detail

DocumentImpl

public DocumentImpl()
NON-DOM: Actually creating a Document is outside the DOM's spec, since it has to operate in terms of a particular implementation.


DocumentImpl

public DocumentImpl(boolean grammarAccess)
Constructor.


DocumentImpl

public DocumentImpl(DocumentType doctype)
For DOM2 support. The createDocument factory method is in DOMImplementation.


DocumentImpl

public DocumentImpl(DocumentType doctype,
                    boolean grammarAccess)
For DOM2 support.

Method Detail

cloneNode

public Node cloneNode(boolean deep)
Deep-clone a document, including fixing ownerDoc for the cloned children. Note that this requires bypassing the WRONG_DOCUMENT_ERR protection. I've chosen to implement it by calling importNode which is DOM Level 2.

Specified by:
cloneNode in interface Node
Overrides:
cloneNode in class CoreDocumentImpl
Parameters:
deep - boolean, iff true replicate children
Returns:
org.w3c.dom.Node
See Also:

Example: Cloning a Text node will copy both the node and the text it contains.

Example: Cloning something that has children -- Element or Attr, for example -- will _not_ clone those children unless a "deep clone" has been requested. A shallow clone of an Attr node will yield an empty Attr of the same name.

NOTE: Clones will always be read/write, even if the node being cloned is read-only, to permit applications using only the DOM API to obtain editable copies of locked portions of the tree.


getImplementation

public DOMImplementation getImplementation()
Retrieve information describing the abilities of this particular DOM implementation. Intended to support applications that may be using DOMs retrieved from several different sources, potentially with different underlying representations.

Specified by:
getImplementation in interface Document
Overrides:
getImplementation in class CoreDocumentImpl

createNodeIterator

public NodeIterator createNodeIterator(Node root,
                                       short whatToShow,
                                       NodeFilter filter)
NON-DOM extension: Create and return a NodeIterator. The NodeIterator is added to a list of NodeIterators so that it can be removed to free up the DOM Nodes it references.

Parameters:
root - The root of the iterator.
whatToShow - The whatToShow mask.
filter - The NodeFilter installed. Null means no filter.

createNodeIterator

public NodeIterator createNodeIterator(Node root,
                                       int whatToShow,
                                       NodeFilter filter,
                                       boolean entityReferenceExpansion)
Create and return a NodeIterator. The NodeIterator is added to a list of NodeIterators so that it can be removed to free up the DOM Nodes it references.

Specified by:
createNodeIterator in interface DocumentTraversal
Parameters:
root - The root of the iterator.
whatToShow - The whatToShow mask.
filter - The NodeFilter installed. Null means no filter.
entityReferenceExpansion - true to expand the contents of EntityReference nodes
Returns:
The newly created NodeIterator.
Since:
WD-DOM-Level-2-19990923

createTreeWalker

public TreeWalker createTreeWalker(Node root,
                                   short whatToShow,
                                   NodeFilter filter)
NON-DOM extension: Create and return a TreeWalker.

Parameters:
root - The root of the iterator.
whatToShow - The whatToShow mask.
filter - The NodeFilter installed. Null means no filter.

createTreeWalker

public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean entityReferenceExpansion)
Create and return a TreeWalker.

Specified by:
createTreeWalker in interface DocumentTraversal
Parameters:
root - The root of the iterator.
whatToShow - The whatToShow mask.
filter - The NodeFilter installed. Null means no filter.
entityReferenceExpansion - true to expand the contents of EntityReference nodes
Returns:
The newly created TreeWalker.
Since:
WD-DOM-Level-2-19990923

createRange

public Range createRange()
Description copied from interface: DocumentRange
This interface can be obtained from the object implementing the Document interface using binding-specific casting methods.

Specified by:
createRange in interface DocumentRange
Returns:
The initial state of the Range returned from this method is such that both of its boundary-points are positioned at the beginning of the corresponding Document, before any content. The Range returned can only be used to select content associated with this Document, or with DocumentFragments and Attrs for which this Document is the ownerDocument.

createEvent

public Event createEvent(java.lang.String type)
                  throws DOMException
Introduced in DOM Level 2. Optional.

Create and return Event objects.

Specified by:
createEvent in interface DocumentEvent
Parameters:
type - The eventType parameter specifies the type of Event interface to be created. If the Event interface specified is supported by the implementation this method will return a new Event of the interface type requested. If the Event is to be dispatched via the dispatchEvent method the appropriate event init method must be called after creation in order to initialize the Event's values. As an example, a user wishing to synthesize some kind of Event would call createEvent with the parameter "Events". The initEvent method could then be called on the newly created Event to set the specific type of Event to be dispatched and set its context information.
Returns:
Newly created Event
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if the implementation does not support the type of Event interface requested
Since:
WD-DOM-Level-2-19990923