Xerces 3.1.1

org.apache.xerces.dom
Class ChildAndParentNode

java.lang.Object
  |
  +--org.apache.xerces.dom.NodeImpl
        |
        +--org.apache.xerces.dom.ChildNode
              |
              +--org.apache.xerces.dom.ChildAndParentNode
All Implemented Interfaces:
java.lang.Cloneable, EventTarget, Node, NodeList, java.io.Serializable
Direct Known Subclasses:
DocumentTypeImpl, ElementImpl, EntityReferenceImpl

public abstract class ChildAndParentNode
extends ChildNode

If we had multiple inheritance ChildAndParentNode would simply inherit both from ChildNode and ParentNode. In this case it only inherits from ChildNode and all the code of ParentNode is duplicated here (bummer :-(

See Also:
Serialized Form

Field Summary
protected  ChildNode firstChild
          First child.
protected  int nodeListIndex
          Last requested node index.
protected  int nodeListLength
          Cached node list length.
protected  ChildNode nodeListNode
          Last requested node.
protected  DocumentImpl ownerDocument
          Owner document.
 
Fields inherited from class org.apache.xerces.dom.ChildNode
nextSibling, previousSibling
 
Fields inherited from class org.apache.xerces.dom.NodeImpl
ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, IGNORABLEWS, MUTATION_AGGREGATE, MUTATION_ALL, MUTATION_LOCAL, MUTATION_NONE, MUTATIONEVENTS, OWNED, ownerNode, READONLY, SETVALUE, SPECIFIED, SYNCCHILDREN, SYNCDATA
 
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
  ChildAndParentNode()
          Constructor for serialization.
protected ChildAndParentNode(DocumentImpl ownerDocument)
          No public constructor; only subclasses of ParentNode should be instantiated, and those normally via a Document's factory methods
 
Method Summary
 Node cloneNode(boolean deep)
          Returns a duplicate of a given node.
 NodeList getChildNodes()
          Obtain a NodeList enumerating all children of this node.
 Node getFirstChild()
          The first child of this Node, or null if none.
 Node getLastChild()
          The last child of this Node, or null if none.
 int getLength()
          NodeList method: Count the immediate children of this node
 Document getOwnerDocument()
          Find the Document that this Node belongs to (the document in whose context the Node was created).
 boolean hasChildNodes()
          Test whether this node has any children.
 Node insertBefore(Node newChild, Node refChild)
          Move one or more node(s) to our list of children.
 Node item(int index)
          NodeList method: Return the Nth immediate child of this node, or null if the index is out of bounds.
 void normalize()
          Override default behavior to call normalize() on this Node's children.
 Node removeChild(Node oldChild)
          Remove a child from this Node.
 Node replaceChild(Node newChild, Node oldChild)
          Make newChild occupy the location that oldChild used to have.
 void setReadOnly(boolean readOnly, boolean deep)
          Override default behavior so that if deep is true, children are also toggled.
protected  void synchronizeChildren()
          Override this method in subclass to hook in efficient internal data structure.
protected  void synchronizeChildren(int nodeIndex)
          Synchronizes the node's children with the internal structure.
 
Methods inherited from class org.apache.xerces.dom.ChildNode
getNextSibling, getParentNode, getPreviousSibling
 
Methods inherited from class org.apache.xerces.dom.NodeImpl
addEventListener, appendChild, changed, changes, dispatchEvent, getAttributes, getLocalName, getNamespaceURI, getNodeName, getNodeType, getNodeValue, getPrefix, getReadOnly, getUserData, hasAttributes, isSupported, removeEventListener, setNodeValue, setPrefix, setUserData, synchronizeData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ownerDocument

protected DocumentImpl ownerDocument
Owner document.

firstChild

protected ChildNode firstChild
First child.

nodeListLength

protected transient int nodeListLength
Cached node list length.

nodeListNode

protected transient ChildNode nodeListNode
Last requested node.

nodeListIndex

protected transient int nodeListIndex
Last requested node index.
Constructor Detail

ChildAndParentNode

protected ChildAndParentNode(DocumentImpl ownerDocument)
No public constructor; only subclasses of ParentNode should be instantiated, and those normally via a Document's factory methods

ChildAndParentNode

public ChildAndParentNode()
Constructor for serialization.
Method Detail

cloneNode

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.

Overrides:
cloneNode in class ChildNode
Following copied from class: org.apache.xerces.dom.ChildNode
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.


getOwnerDocument

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.
Overrides:
getOwnerDocument in class NodeImpl

hasChildNodes

public boolean hasChildNodes()
Test whether this node has any children. Convenience shorthand for (Node.getFirstChild()!=null)
Overrides:
hasChildNodes in class NodeImpl
Following copied from class: org.apache.xerces.dom.NodeImpl
See Also:
ParentNode

getChildNodes

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.

Overrides:
getChildNodes in class NodeImpl

getFirstChild

public Node getFirstChild()
The first child of this Node, or null if none.
Overrides:
getFirstChild in class NodeImpl
Following copied from class: org.apache.xerces.dom.NodeImpl
See Also:
ParentNode

getLastChild

public Node getLastChild()
The last child of this Node, or null if none.
Overrides:
getLastChild in class NodeImpl
Following copied from class: org.apache.xerces.dom.NodeImpl
See Also:
ParentNode

insertBefore

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.
Overrides:
insertBefore in class NodeImpl
Parameters:
newChild - The Node to be moved to our subtree. As a convenience feature, inserting a DocumentNode will instead insert all its children.
refChild - Current child which newChild should be placed immediately before. If refChild is null, the insertion occurs after all existing Nodes, like appendChild().
Throws:
DOMException(HIERARCHY_REQUEST_ERR) - if newChild is of a type that shouldn't be a child of this node, or if newChild is an ancestor of this node.
DOMException(WRONG_DOCUMENT_ERR) - if newChild has a different owner document than we do.
DOMException(NOT_FOUND_ERR) - if refChild is not a child of this node.
DOMException(NO_MODIFICATION_ALLOWED_ERR) - if this node is read-only.

removeChild

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.
Overrides:
removeChild in class NodeImpl
Returns:
oldChild, in its new state (removed).
Throws:
DOMException(NOT_FOUND_ERR) - if oldChild is not a child of this node.
DOMException(NO_MODIFICATION_ALLOWED_ERR) - if this node is read-only.

replaceChild

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.
Overrides:
replaceChild in class NodeImpl
Throws:
DOMException(HIERARCHY_REQUEST_ERR) - if newChild is of a type that shouldn't be a child of this node, or if newChild is one of our ancestors.
DOMException(WRONG_DOCUMENT_ERR) - if newChild has a different owner document than we do.
DOMException(NOT_FOUND_ERR) - if oldChild is not a child of this node.
DOMException(NO_MODIFICATION_ALLOWED_ERR) - if this node is read-only.

getLength

public int getLength()
NodeList method: Count the immediate children of this node
Overrides:
getLength in class NodeImpl
Returns:
int

item

public Node item(int index)
NodeList method: Return the Nth immediate child of this node, or null if the index is out of bounds.
Overrides:
item in class NodeImpl
Parameters:
Index - int
Returns:
org.w3c.dom.Node

normalize

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.
Overrides:
normalize in class NodeImpl

setReadOnly

public void setReadOnly(boolean readOnly,
                        boolean deep)
Override default behavior so that if deep is true, children are also toggled.
Overrides:
setReadOnly in class NodeImpl
See Also:

Note: this will not change the state of an EntityReference or its children, which are always read-only.


synchronizeChildren

protected void synchronizeChildren()
Override this method in subclass to hook in efficient internal data structure.

synchronizeChildren

protected final void synchronizeChildren(int nodeIndex)
Synchronizes the node's children with the internal structure. Fluffing the children at once solves a lot of work to keep the two structures in sync. The problem gets worse when editing the tree -- this makes it a lot easier. Even though this is only used in deferred classes this method is put here so that it can be shared by all deferred classes.

Xerces 3.1.1