Save This Page
Home » Xerces-J-src.2.9.1 » org.apache.xerces » dom » [javadoc | source]
org.apache.xerces.dom
public class: DocumentImpl [javadoc | source]
java.lang.Object
   org.apache.xerces.dom.NodeImpl
      org.apache.xerces.dom.ChildNode
         org.apache.xerces.dom.ParentNode
            org.apache.xerces.dom.CoreDocumentImpl
               org.apache.xerces.dom.DocumentImpl

All Implemented Interfaces:
    DocumentTraversal, DocumentRange, DocumentEvent, Document, Cloneable, Node, EventTarget, Serializable, NodeList

Direct Known Subclasses:
    WMLDocumentImpl, PSVIDocumentImpl, DeferredDocumentImpl, HTMLDocumentImpl

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.

Nested Class Summary:
class  DocumentImpl.LEntry   
class  DocumentImpl.EnclosingAttr  NON-DOM INTERNAL: Return object for getEnclosingAttr. Carries (two values, the Attr node affected (if any) and its previous string value. Simple struct, no methods. 
Field Summary
static final  long serialVersionUID    Serialization version. 
protected  Vector iterators    Iterators 
protected  Vector ranges    Ranges 
protected  Hashtable eventListeners    Table for event listeners registered to this document nodes. 
protected  boolean mutationEvents    Bypass mutation events firing. 
 DocumentImpl.EnclosingAttr savedEnclosingAttr     
Fields inherited from org.apache.xerces.dom.CoreDocumentImpl:
serialVersionUID,  docType,  docElement,  fFreeNLCache,  encoding,  actualEncoding,  version,  standalone,  fDocumentURI,  userData,  identifiers,  domNormalizer,  fConfiguration,  fXPathEvaluator,  changes,  allowGrammarAccess,  errorChecking,  xmlVersionChanged
Fields inherited from org.apache.xerces.dom.ParentNode:
serialVersionUID,  ownerDocument,  firstChild,  fNodeListCache
Fields inherited from org.apache.xerces.dom.ChildNode:
serialVersionUID,  previousSibling,  nextSibling
Fields inherited from org.apache.xerces.dom.NodeImpl:
TREE_POSITION_PRECEDING,  TREE_POSITION_FOLLOWING,  TREE_POSITION_ANCESTOR,  TREE_POSITION_DESCENDANT,  TREE_POSITION_EQUIVALENT,  TREE_POSITION_SAME_NODE,  TREE_POSITION_DISCONNECTED,  DOCUMENT_POSITION_DISCONNECTED,  DOCUMENT_POSITION_PRECEDING,  DOCUMENT_POSITION_FOLLOWING,  DOCUMENT_POSITION_CONTAINS,  DOCUMENT_POSITION_IS_CONTAINED,  DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC,  serialVersionUID,  ELEMENT_DEFINITION_NODE,  ownerNode,  flags,  READONLY,  SYNCDATA,  SYNCCHILDREN,  OWNED,  FIRSTCHILD,  SPECIFIED,  IGNORABLEWS,  HASSTRING,  NORMALIZED,  ID
Constructor:
 public DocumentImpl() 
 public DocumentImpl(boolean grammarAccess) 
 public DocumentImpl(DocumentType doctype) 
    For DOM2 support. The createDocument factory method is in DOMImplementation.
 public DocumentImpl(DocumentType doctype,
    boolean grammarAccess) 
    For DOM2 support.
Method from org.apache.xerces.dom.DocumentImpl Summary:
addEventListener,   cloneNode,   copyEventListeners,   createEvent,   createNodeIterator,   createNodeIterator,   createRange,   createTreeWalker,   createTreeWalker,   deletedText,   dispatchAggregateEvents,   dispatchAggregateEvents,   dispatchEvent,   dispatchEventToSubtree,   dispatchingEventToSubtree,   getEventListeners,   getImplementation,   getMutationEvents,   insertedNode,   insertedText,   insertingNode,   modifiedAttrValue,   modifiedCharacterData,   modifyingCharacterData,   removeEventListener,   removeNodeIterator,   removeRange,   removedAttrNode,   removedNode,   removingNode,   renamedAttrNode,   renamedElement,   replacedCharacterData,   replacedNode,   replacedText,   replacingData,   replacingNode,   saveEnclosingAttr,   setAttrNode,   setEventListeners,   setMutationEvents,   splitData
Methods from org.apache.xerces.dom.CoreDocumentImpl:
abort,   addEventListener,   adoptNode,   callUserDataHandlers,   callUserDataHandlers,   changed,   changes,   checkDOMNSErr,   checkNamespaceWF,   checkQName,   clearIdentifiers,   clone,   cloneNode,   cloneNode,   copyEventListeners,   createAttribute,   createAttributeNS,   createAttributeNS,   createCDATASection,   createComment,   createDocumentFragment,   createDocumentType,   createElement,   createElementDefinition,   createElementNS,   createElementNS,   createEntity,   createEntityReference,   createNotation,   createProcessingInstruction,   createTextNode,   deletedText,   dispatchEvent,   freeNodeListCache,   getAsync,   getBaseURI,   getDoctype,   getDocumentElement,   getDocumentURI,   getDomConfig,   getElementById,   getElementsByTagName,   getElementsByTagNameNS,   getEncoding,   getErrorChecking,   getFeature,   getIdentifier,   getIdentifiers,   getImplementation,   getInputEncoding,   getMutationEvents,   getNodeListCache,   getNodeName,   getNodeNumber,   getNodeNumber,   getNodeType,   getOwnerDocument,   getStandalone,   getStrictErrorChecking,   getTextContent,   getUserData,   getUserData,   getUserDataRecord,   getVersion,   getXmlEncoding,   getXmlStandalone,   getXmlVersion,   importNode,   insertBefore,   insertedNode,   insertedText,   insertingNode,   isKidOK,   isNormalizeDocRequired,   isValidQName,   isXML11Version,   isXMLName,   isXMLVersionChanged,   load,   loadXML,   modifiedAttrValue,   modifiedCharacterData,   modifyingCharacterData,   normalizeDocument,   putIdentifier,   removeChild,   removeEventListener,   removeIdentifier,   removeUserDataTable,   removedAttrNode,   removedNode,   removingNode,   renameNode,   renamedAttrNode,   renamedElement,   replaceChild,   replacedCharacterData,   replacedNode,   replacedText,   replacingData,   replacingNode,   saveXML,   setAsync,   setAttrNode,   setDocumentURI,   setEncoding,   setErrorChecking,   setInputEncoding,   setMutationEvents,   setStandalone,   setStrictErrorChecking,   setTextContent,   setUserData,   setUserData,   setUserDataTable,   setVersion,   setXmlEncoding,   setXmlStandalone,   setXmlVersion,   undeferChildren
Methods from org.apache.xerces.dom.ParentNode:
checkNormalizationAfterInsert,   checkNormalizationAfterRemove,   cloneNode,   getChildNodes,   getChildNodesUnoptimized,   getFirstChild,   getLastChild,   getLength,   getOwnerDocument,   getTextContent,   getTextContent,   hasChildNodes,   hasTextContent,   insertBefore,   internalInsertBefore,   internalRemoveChild,   isEqualNode,   item,   lastChild,   lastChild,   normalize,   ownerDocument,   removeChild,   replaceChild,   setOwnerDocument,   setReadOnly,   setTextContent,   synchronizeChildren
Methods from org.apache.xerces.dom.ChildNode:
cloneNode,   getNextSibling,   getParentNode,   getPreviousSibling,   parentNode,   previousSibling
Methods from org.apache.xerces.dom.NodeImpl:
addEventListener,   appendChild,   changed,   changes,   cloneNode,   compareDocumentPosition,   compareTreePosition,   dispatchEvent,   getAttributes,   getBaseURI,   getChildNodes,   getContainer,   getElementAncestor,   getFeature,   getFirstChild,   getLastChild,   getLength,   getLocalName,   getNamespaceURI,   getNextSibling,   getNodeName,   getNodeNumber,   getNodeType,   getNodeValue,   getOwnerDocument,   getParentNode,   getPrefix,   getPreviousSibling,   getReadOnly,   getTextContent,   getTextContent,   getUserData,   getUserData,   getUserDataRecord,   hasAttributes,   hasChildNodes,   hasStringValue,   hasStringValue,   insertBefore,   internalIsIgnorableWhitespace,   isDefaultNamespace,   isEqualNode,   isFirstChild,   isFirstChild,   isIdAttribute,   isIdAttribute,   isIgnorableWhitespace,   isNormalized,   isNormalized,   isOwned,   isOwned,   isReadOnly,   isReadOnly,   isSameNode,   isSpecified,   isSpecified,   isSupported,   item,   lookupNamespacePrefix,   lookupNamespaceURI,   lookupPrefix,   needsSyncChildren,   needsSyncChildren,   needsSyncData,   needsSyncData,   normalize,   ownerDocument,   parentNode,   previousSibling,   removeChild,   removeEventListener,   replaceChild,   setNodeValue,   setOwnerDocument,   setPrefix,   setReadOnly,   setTextContent,   setUserData,   setUserData,   synchronizeData,   toString
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.xerces.dom.DocumentImpl Detail:
 protected  void addEventListener(NodeImpl node,
    String type,
    EventListener listener,
    boolean useCapture) 
    Introduced in DOM Level 2.

    Register an event listener with this Node. A listener may be independently registered as both Capturing and Bubbling, but may only be registered once per role; redundant registrations are ignored.

 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.
 protected  void copyEventListeners(NodeImpl src,
    NodeImpl tgt) 
 public Event createEvent(String type) throws DOMException 
    Introduced in DOM Level 2. Optional.

    Create and return Event objects.

 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.
 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.
 public Range createRange() 
 public TreeWalker createTreeWalker(Node root,
    short whatToShow,
    NodeFilter filter) 
    NON-DOM extension: Create and return a TreeWalker.
 public TreeWalker createTreeWalker(Node root,
    int whatToShow,
    NodeFilter filter,
    boolean entityReferenceExpansion) 
    Create and return a TreeWalker.
  void deletedText(CharacterDataImpl node,
    int offset,
    int count) 
    A method to be called when some text was deleted from a text node, so that live objects can be notified.
 protected  void dispatchAggregateEvents(NodeImpl node,
    DocumentImpl.EnclosingAttr ea) 
    NON-DOM INTERNAL: Convenience wrapper for calling dispatchAggregateEvents when the context was established by savedEnclosingAttr.
 protected  void dispatchAggregateEvents(NodeImpl node,
    AttrImpl enclosingAttr,
    String oldvalue,
    short change) 
    NON-DOM INTERNAL: Generate the "aggregated" post-mutation events DOMAttrModified and DOMSubtreeModified. Both of these should be issued only once for each user-requested mutation operation, even if that involves multiple changes to the DOM. For example, if a DOM operation makes multiple changes to a single Attr before returning, it would be nice to generate only one DOMAttrModified, and multiple changes over larger scope but within a recognizable single subtree might want to generate only one DOMSubtreeModified, sent to their lowest common ancestor.

    To manage this, use the "internal" versions of insert and remove with MUTATION_LOCAL, then make an explicit call to this routine at the higher level. Some examples now exist in our code.

 protected boolean dispatchEvent(NodeImpl node,
    Event event) 
    Introduced in DOM Level 2.

    Distribution engine for DOM Level 2 Events.

    Event propagation runs as follows:

    1. Event is dispatched to a particular target node, which invokes this code. Note that the event's stopPropagation flag is cleared when dispatch begins; thereafter, if it has been set before processing of a node commences, we instead immediately advance to the DEFAULT phase.
    2. The node's ancestors are established as destinations for events. For capture and bubble purposes, node ancestry is determined at the time dispatch starts. If an event handler alters the document tree, that does not change which nodes will be informed of the event.
    3. CAPTURING_PHASE: Ancestors are scanned, root to target, for Capturing listeners. If found, they are invoked (see below).
    4. AT_TARGET: Event is dispatched to NON-CAPTURING listeners on the target node. Note that capturing listeners on this node are _not_ invoked.
    5. BUBBLING_PHASE: Ancestors are scanned, target to root, for non-capturing listeners.
    6. Default processing: Some DOMs have default behaviors bound to specific nodes. If this DOM does, and if the event's preventDefault flag has not been set, we now return to the target node and process its default handler for this event, if any.

    Note that registration of handlers during processing of an event does not take effect during this phase of this event; they will not be called until the next time this node is visited by dispatchEvent. On the other hand, removals take effect immediately.

    If an event handler itself causes events to be dispatched, they are processed synchronously, before processing resumes on the event which triggered them. Please be aware that this may result in events arriving at listeners "out of order" relative to the actual sequence of requests.

    Note that our implementation resets the event's stop/prevent flags when dispatch begins. I believe the DOM's intent is that event objects be redispatchable, though it isn't stated in those terms.

 protected  void dispatchEventToSubtree(Node n,
    Event e) 
    NON-DOM INTERNAL: DOMNodeInsertedIntoDocument and ...RemovedFrom... are dispatched to an entire subtree. This is the distribution code therefor. They DO NOT bubble, thanks be, but may be captured.

    Similar to code in dispatchingEventToSubtree however this method is only used on the target node and does not start a dispatching chain on the sibling of the target node as this is not part of the subtree ***** At the moment I'm being sloppy and using the normal capture dispatcher on every node. This could be optimized hugely by writing a capture engine that tracks our position in the tree to update the capture chain without repeated chases up to root.

 protected  void dispatchingEventToSubtree(Node n,
    Event e) 
    Dispatches event to the target node's descendents recursively
 protected Vector getEventListeners(NodeImpl n) 
    Retreive event listener registered on a given node
 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.
 boolean getMutationEvents() 
    Returns true if the DOM implementation generates mutation events.
  void insertedNode(NodeImpl node,
    NodeImpl newInternal,
    boolean replace) 
    A method to be called when a node has been inserted in the tree.
  void insertedText(CharacterDataImpl node,
    int offset,
    int count) 
    A method to be called when some text was inserted into a text node, so that live objects can be notified.
  void insertingNode(NodeImpl node,
    boolean replace) 
    A method to be called when a node is about to be inserted in the tree.
  void modifiedAttrValue(AttrImpl attr,
    String oldvalue) 
    A method to be called when an attribute value has been modified
  void modifiedCharacterData(NodeImpl node,
    String oldvalue,
    String value,
    boolean replace) 
    A method to be called when a character data node has been modified
  void modifyingCharacterData(NodeImpl node,
    boolean replace) 
    A method to be called when a character data node has been modified
 protected  void removeEventListener(NodeImpl node,
    String type,
    EventListener listener,
    boolean useCapture) 
    Introduced in DOM Level 2.

    Deregister an event listener previously registered with this Node. A listener must be independently removed from the Capturing and Bubbling roles. Redundant removals (of listeners not currently registered for this role) are ignored.

  void removeNodeIterator(NodeIterator nodeIterator) 
    This is not called by the developer client. The developer client uses the detach() function on the NodeIterator itself.

    This function is called from the NodeIterator#detach().

  void removeRange(Range range) 
    Not a client function. Called by Range.detach(), so a Range can remove itself from the list of Ranges.
  void removedAttrNode(AttrImpl attr,
    NodeImpl oldOwner,
    String name) 
    A method to be called when an attribute node has been removed
  void removedNode(NodeImpl node,
    boolean replace) 
    A method to be called when a node has been removed from the tree.
  void removingNode(NodeImpl node,
    NodeImpl oldChild,
    boolean replace) 
    A method to be called when a node is about to be removed from the tree.
  void renamedAttrNode(Attr oldAt,
    Attr newAt) 
    A method to be called when an attribute node has been renamed
  void renamedElement(Element oldEl,
    Element newEl) 
    A method to be called when an element has been renamed
  void replacedCharacterData(NodeImpl node,
    String oldvalue,
    String value) 
    A method to be called when a character data node has been replaced
  void replacedNode(NodeImpl node) 
    A method to be called when a node has been replaced in the tree.
  void replacedText(CharacterDataImpl node) 
    A method to be called when some text was changed in a text node, so that live objects can be notified.
  void replacingData(NodeImpl node) 
    A method to be called when character data is about to be replaced in the tree.
  void replacingNode(NodeImpl node) 
    A method to be called when a node is about to be replaced in the tree.
 protected  void saveEnclosingAttr(NodeImpl node) 
    NON-DOM INTERNAL: Pre-mutation context check, in preparation for later generating DOMAttrModified events. Determines whether this node is within an Attr
  void setAttrNode(AttrImpl attr,
    AttrImpl previous) 
    A method to be called when an attribute node has been set
 protected  void setEventListeners(NodeImpl n,
    Vector listeners) 
    Store event listener registered on a given node This is another place where we could use weak references! Indeed, the node here won't be GC'ed as long as some listener is registered on it, since the eventsListeners table will have a reference to the node.
  void setMutationEvents(boolean set) 
    Sets whether the DOM implementation generates mutation events upon operations.
  void splitData(Node node,
    Node newNode,
    int offset) 
    A method to be called when a text node has been split, so that live objects can be notified.