org.apache.xerces.dom
public abstract class ParentNode extends ChildNode
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!
Version: $Id: ParentNode.java,v 1.50 2005/05/02 22:02:22 mrglavas Exp $
Field Summary | |
---|---|
protected ChildNode | firstChild First child. |
protected NodeListCache | fNodeListCache NodeList cache |
protected CoreDocumentImpl | ownerDocument Owner document. |
Constructor Summary | |
---|---|
protected | ParentNode(CoreDocumentImpl ownerDocument)
No public constructor; only subclasses of ParentNode should be
instantiated, and those normally via a Document's factory methods |
ParentNode() Constructor for serialization. |
Method Summary | |
---|---|
Node | cloneNode(boolean deep)
Returns a duplicate of a given node. |
NodeList | getChildNodes()
Obtain a NodeList enumerating all children of this node. |
protected NodeList | getChildNodesUnoptimized()
Create a NodeList to access children that is use by subclass elements
that have methods named getLength() or item(int). |
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). |
String | getTextContent() |
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. |
boolean | isEqualNode(Node arg)
DOM Level 3 WD- Experimental.
|
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. |
void | setTextContent(String textContent) |
protected void | synchronizeChildren()
Override this method in subclass to hook in efficient
internal data structure. |
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.
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.
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.
Returns: int
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().
Returns: newChild, in its new state (relocated, or emptied in the case of DocumentNode.)
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.
Parameters: index int
Returns: org.w3c.dom.Node
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.
Returns: oldChild, in its new state (removed).
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.
See Also:
Note: this will not change the state of an EntityReference or its
children, which are always read-only.Node