Save This Page
Home » openjdk-7 » com.sun.org.apache.xerces.internal » dom » [javadoc | source]
com.sun.org.apache.xerces.internal.dom
abstract public class: ParentNode [javadoc | source]
java.lang.Object
   com.sun.org.apache.xerces.internal.dom.NodeImpl
      com.sun.org.apache.xerces.internal.dom.ChildNode
         com.sun.org.apache.xerces.internal.dom.ParentNode

All Implemented Interfaces:
    Cloneable, Node, EventTarget, Serializable, NodeList

Direct Known Subclasses:
    Header1_1Impl, Body1_1Impl, ElementNSImpl, DeferredDocumentImpl, DocumentImpl, CoreDocumentImpl, ElementImpl, Detail1_2Impl, DetailEntry1_2Impl, DocumentTypeImpl, DeferredElementImpl, EnvelopeImpl, DeferredEntityImpl, SOAPDocumentImpl, FaultImpl, FaultElementImpl, HeaderElement1_1Impl, PSVIDocumentImpl, EntityReferenceImpl, BodyImpl, HeaderElement1_2Impl, HeaderImpl, FaultElement1_1Impl, BodyElement1_2Impl, HeaderElementImpl, Envelope1_1Impl, Detail1_1Impl, DetailImpl, DeferredElementDefinitionImpl, DeferredElementNSImpl, DetailEntryImpl, FaultElement1_2Impl, DocumentFragmentImpl, PSVIElementNSImpl, ElementDefinitionImpl, BodyElement1_1Impl, DeferredDocumentTypeImpl, DetailEntry1_1Impl, SOAPDocumentFragment, Fault1_1Impl, Fault1_2Impl, ElementImpl, EntityImpl, Envelope1_2Impl, Body1_2Impl, Header1_2Impl, DeferredEntityReferenceImpl, BodyElementImpl

ParentNode inherits from ChildNode and adds the capability of having child nodes. Not every node in the DOM can have children, so only nodes that can should inherit from this class and pay the price for it.

ParentNode, just like NodeImpl, also implements NodeList, so it can return itself in response to the getChildNodes() query. This eliminiates the need for a separate ChildNodeList object. Note that this is an IMPLEMENTATION DETAIL; applications should _never_ assume that this identity exists. On the other hand, subclasses may need to override this, in case of conflicting names. This is the case for the classes HTMLSelectElementImpl and HTMLFormElementImpl of the HTML DOM.

While we have a direct reference to the first child, the last child is stored as the previous sibling of the first child. First child nodes are marked as being so, and getNextSibling hides this fact.

Note: Not all parent nodes actually need to also be a child. At some point we used to have ParentNode inheriting from NodeImpl and another class called ChildAndParentNode that inherited from ChildNode. But due to the lack of multiple inheritance a lot of code had to be duplicated which led to a maintenance nightmare. At the same time only a few nodes (Document, DocumentFragment, Entity, and Attribute) cannot be a child so the gain in memory wasn't really worth it. The only type for which this would be the case is Attribute, but we deal with there in another special way, so this is not applicable.

This class doesn't directly support mutation events, however, it notifies the document when mutations are performed so that the document class do so.

WARNING: Some of the code here is partially duplicated in AttrImpl, be careful to keep these two classes in sync!

Nested Class Summary:
class  ParentNode.UserDataRecord   
Field Summary
static final  long serialVersionUID    Serialization version. 
protected  CoreDocumentImpl ownerDocument    Owner document. 
protected  ChildNode firstChild    First child. 
protected transient  NodeListCache fNodeListCache    NodeList cache 
Fields inherited from com.sun.org.apache.xerces.internal.dom.ChildNode:
serialVersionUID,  fBufferStr,  previousSibling,  nextSibling
Fields inherited from com.sun.org.apache.xerces.internal.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 ParentNode() 
 protected ParentNode(CoreDocumentImpl ownerDocument) 
    No public constructor; only subclasses of ParentNode should be instantiated, and those normally via a Document's factory methods
Method from com.sun.org.apache.xerces.internal.dom.ParentNode Summary:
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 com.sun.org.apache.xerces.internal.dom.ChildNode:
cloneNode,   getNextSibling,   getParentNode,   getPreviousSibling,   parentNode,   previousSibling
Methods from com.sun.org.apache.xerces.internal.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 com.sun.org.apache.xerces.internal.dom.ParentNode Detail:
  void checkNormalizationAfterInsert(ChildNode insertedChild) 
    Checks the normalized state of this node after inserting a child. If the inserted child causes this node to be unnormalized, then this node is flagged accordingly. The conditions for changing the normalized state are:
    • The inserted child is a text node and one of its adjacent siblings is also a text node.
    • The inserted child is is itself unnormalized.
  void checkNormalizationAfterRemove(ChildNode previousSibling) 
    Checks the normalized of this node after removing a child. If the removed child causes this node to be unnormalized, then this node is flagged accordingly. The conditions for changing the normalized state are:
    • The removed child had two adjacent siblings that were text nodes.
 public Node cloneNode(boolean deep) 
    Returns a duplicate of a given node. You can consider this a generic "copy constructor" for nodes. The newly returned object should be completely independent of the source object's subtree, so changes in one after the clone has been made will not affect the other.

    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.

 public NodeList getChildNodes() 
    Obtain a NodeList enumerating all children of this node. If there are none, an (initially) empty NodeList is returned.

    NodeLists are "live"; as children are added/removed the NodeList will immediately reflect those changes. Also, the NodeList refers to the actual nodes, so changes to those nodes made via the DOM tree will be reflected in the NodeList and vice versa.

    In this implementation, Nodes implement the NodeList interface and provide their own getChildNodes() support. Other DOMs may solve this differently.

 protected final NodeList getChildNodesUnoptimized() 
    Create a NodeList to access children that is use by subclass elements that have methods named getLength() or item(int). ChildAndParentNode optimizes getChildNodes() by implementing NodeList itself. However if a subclass Element implements methods with the same name as the NodeList methods, they will override the actually methods in this class.

    To use this method, the subclass should implement getChildNodes() and have it call this method. The resulting NodeList instance maybe shared and cached in a transient field, but the cached value must be cleared if the node is cloned.

 public Node getFirstChild() 
    The first child of this Node, or null if none.
 public Node getLastChild() 
    The last child of this Node, or null if none.
 public int getLength() 
    NodeList method: Count the immediate children of this node
 public Document getOwnerDocument() 
    Find the Document that this Node belongs to (the document in whose context the Node was created). The Node may or may not currently be part of that Document's actual contents.
 public String getTextContent() throws DOMException 
  void getTextContent(StringBuffer buf) throws DOMException 
 public boolean hasChildNodes() 
    Test whether this node has any children. Convenience shorthand for (Node.getFirstChild()!=null)
 final boolean hasTextContent(Node child) 
 public Node insertBefore(Node newChild,
    Node refChild) throws DOMException 
    Move one or more node(s) to our list of children. Note that this implicitly removes them from their previous parent.
 Node internalInsertBefore(Node newChild,
    Node refChild,
    boolean replace) throws DOMException 
    NON-DOM INTERNAL: Within DOM actions,we sometimes need to be able to control which mutation events are spawned. This version of the insertBefore operation allows us to do so. It is not intended for use by application programs.
 Node internalRemoveChild(Node oldChild,
    boolean replace) throws DOMException 
    NON-DOM INTERNAL: Within DOM actions,we sometimes need to be able to control which mutation events are spawned. This version of the removeChild operation allows us to do so. It is not intended for use by application programs.
 public boolean isEqualNode(Node arg) 
    DOM Level 3 WD- Experimental. Override inherited behavior from NodeImpl to support deep equal.
 public Node item(int index) 
    NodeList method: Return the Nth immediate child of this node, or null if the index is out of bounds.
 final ChildNode lastChild() 
 final  void lastChild(ChildNode node) 
 public  void normalize() 
    Override default behavior to call normalize() on this Node's children. It is up to implementors or Node to override normalize() to take action.
 CoreDocumentImpl ownerDocument() 
    same as above but returns internal type and this one is not overridden by CoreDocumentImpl to return null
 public Node removeChild(Node oldChild) throws DOMException 
    Remove a child from this Node. The removed child's subtree remains intact so it may be re-inserted elsewhere.
 public Node replaceChild(Node newChild,
    Node oldChild) throws DOMException 
    Make newChild occupy the location that oldChild used to have. Note that newChild will first be removed from its previous parent, if any. Equivalent to inserting newChild before oldChild, then removing oldChild.
  void setOwnerDocument(CoreDocumentImpl doc) 
    NON-DOM set the ownerDocument of this node and its children
 public  void setReadOnly(boolean readOnly,
    boolean deep) 
    Override default behavior so that if deep is true, children are also toggled.
 public  void setTextContent(String textContent) throws DOMException 
 protected  void synchronizeChildren() 
    Override this method in subclass to hook in efficient internal data structure.