- All Implemented Interfaces:
Cloneable,EventTarget,Node,NodeList
The Node interface provides shared behaviors such as siblings and children,
both for consistency and so that the most common tree operations may be
performed without constantly having to downcast to specific node types. When
there is no obvious mapping for one of these queries, it will respond with
null. Note that the default behavior is that children are forbidden. To
permit them, the subclass ParentNode overrides several methods.
NodeImpl also implements NodeList, so it can return itself in response to the getChildNodes() query. This eliminates the need for a separate ChildNodeList object. Note that this is an IMPLEMENTATION DETAIL; applications should never assume that this identity exists.
All nodes in a single document must originate in that document. (Note that this is much tighter than "must be same implementation") Nodes are all aware of their ownerDocument, and attempts to mismatch will throw WRONG_DOCUMENT_ERR.
However, to save memory not all nodes always have a direct reference to their ownerDocument. When a node is owned by another node it relies on its owner to store its ownerDocument. Parent nodes always store it though, so there is never more than one level of indirection. And when a node doesn't have an owner, ownerNode refers to its ownerDocument.
This class doesn't directly support mutation events; however, it still implements the EventTarget interface and forwards all related calls to the document so that the document class can do so.
- Author:
- Arnaud Le Hors, IBM, Joe Kesselman, IBM, Ronald Brill
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected NodeImplTypically the parent, but not always!protected static final intprotected static final intprotected static final intFields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNodeImpl(CoreDocumentImpl ownerDocument) No public constructor; only subclasses of Node should be instantiated, and those normally via a Document's factory methods. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListener(String type, EventListener listener, boolean useCapture) appendChild(Node newChild) Adds a child node to the end of the list of children for this node.protected voidchanged()Denotes that this node has changed.protected intchanges()Returns the number of changes to this node.cloneNode(boolean deep) Returns a duplicate of a given node.shortcompareDocumentPosition(Node other) booleandispatchEvent(Event event) getFeature(String feature, String version) intabstract StringReturns the name of this node.protected intReturns the node number.abstract shortA short integer indicating what type of node this is.Returns the node value.Finds the Document that this Node belongs to (the document in whose context the Node was created).Obtain the DOM-tree parent of this node, ornullif it is not currently active in the DOM tree (perhaps because it has just been created or removed).getUserData(String key) booleanbooleaninsertBefore(Node newChild, Node refChild) booleanisDefaultNamespace(String namespaceURI) booleanisEqualNode(Node arg) booleanisSameNode(Node other) booleanisSupported(String feature, String version) item(int index) lookupNamespaceURI(String specifiedPrefix) lookupPrefix(String namespaceURI) final voidneedsSyncChildren(boolean value) voidremoveChild(Node oldChild) voidremoveEventListener(String type, EventListener listener, boolean useCapture) replaceChild(Node newChild, Node oldChild) voidSets the node value.protected voidvoidvoidsetTextContent(String textContent) setUserData(String key, Object data, UserDataHandler handler) toString()
-
Field Details
-
DOCUMENT_POSITION_DISCONNECTED
public static final short DOCUMENT_POSITION_DISCONNECTED- See Also:
-
DOCUMENT_POSITION_PRECEDING
public static final short DOCUMENT_POSITION_PRECEDING- See Also:
-
DOCUMENT_POSITION_FOLLOWING
public static final short DOCUMENT_POSITION_FOLLOWING- See Also:
-
DOCUMENT_POSITION_CONTAINS
public static final short DOCUMENT_POSITION_CONTAINS- See Also:
-
DOCUMENT_POSITION_IS_CONTAINED
public static final short DOCUMENT_POSITION_IS_CONTAINED- See Also:
-
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
public static final short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC- See Also:
-
ownerNode_
Typically the parent, but not always! -
READONLY
protected static final int READONLY- See Also:
-
SYNCCHILDREN
protected static final int SYNCCHILDREN- See Also:
-
OWNED
protected static final int OWNED- See Also:
-
FIRSTCHILD
protected static final int FIRSTCHILD- See Also:
-
SPECIFIED
protected static final int SPECIFIED- See Also:
-
HASSTRING
protected static final int HASSTRING- See Also:
-
NORMALIZED
protected static final int NORMALIZED- See Also:
-
ID
protected static final int ID- See Also:
-
-
Constructor Details
-
NodeImpl
No public constructor; only subclasses of Node should be instantiated, and those normally via a Document's factory methods.Every Node knows what Document it belongs to.
- Parameters:
ownerDocument- the owner document
-
-
Method Details
-
getNodeType
public abstract short getNodeType()A short integer indicating what type of node this is. The named constants for this value are defined in the org.w3c.dom.Node interface.- Specified by:
getNodeTypein interfaceNode
-
getNodeName
Returns the name of this node.- Specified by:
getNodeNamein interfaceNode
-
getNodeValue
Returns the node value.- Specified by:
getNodeValuein interfaceNode- Returns:
- the node value, or
null - Throws:
DOMException- DOMSTRING_SIZE_ERR
-
setNodeValue
Sets the node value.- Specified by:
setNodeValuein interfaceNode- Parameters:
x- the new node value- Throws:
DOMException- NO_MODIFICATION_ALLOWED_ERR
-
appendChild
Adds a child node to the end of the list of children for this node. Convenience shorthand for insertBefore(newChild,null).- Specified by:
appendChildin interfaceNode- Parameters:
newChild- the child node to add- 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 nodeDOMException- WRONG_DOCUMENT_ERR if newChild has a different owner document than we doDOMException- NO_MODIFICATION_ALLOWED_ERR if this node is read-only- See Also:
-
cloneNode
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.Note: since we never have any children deep is meaningless here, ParentNode overrides this behavior.
-
getOwnerDocument
Finds 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.- Specified by:
getOwnerDocumentin interfaceNode
-
setOwnerDocument
-
getNodeNumber
protected int getNodeNumber()Returns the node number.- Returns:
- the node number
-
getParentNode
Obtain the DOM-tree parent of this node, ornullif it is not currently active in the DOM tree (perhaps because it has just been created or removed). Note that Document, DocumentFragment, and Attribute will never have parents.- Specified by:
getParentNodein interfaceNode- Returns:
- the parent node, or
null
-
getNextSibling
- Specified by:
getNextSiblingin interfaceNode
-
getPreviousSibling
- Specified by:
getPreviousSiblingin interfaceNode
-
getAttributes
- Specified by:
getAttributesin interfaceNode
-
hasAttributes
public boolean hasAttributes()- Specified by:
hasAttributesin interfaceNode
-
hasChildNodes
public boolean hasChildNodes()- Specified by:
hasChildNodesin interfaceNode
-
getChildNodes
- Specified by:
getChildNodesin interfaceNode
-
getFirstChild
- Specified by:
getFirstChildin interfaceNode
-
getLastChild
- Specified by:
getLastChildin interfaceNode
-
insertBefore
- Specified by:
insertBeforein interfaceNode- Throws:
DOMException
-
removeChild
- Specified by:
removeChildin interfaceNode- Throws:
DOMException
-
replaceChild
- Specified by:
replaceChildin interfaceNode- Throws:
DOMException
-
getLength
public int getLength() -
item
-
normalize
public void normalize() -
isSupported
- Specified by:
isSupportedin interfaceNode
-
getNamespaceURI
- Specified by:
getNamespaceURIin interfaceNode
-
getPrefix
-
setPrefix
- Specified by:
setPrefixin interfaceNode- Throws:
DOMException
-
getLocalName
- Specified by:
getLocalNamein interfaceNode
-
addEventListener
- Specified by:
addEventListenerin interfaceEventTarget
-
removeEventListener
- Specified by:
removeEventListenerin interfaceEventTarget
-
dispatchEvent
- Specified by:
dispatchEventin interfaceEventTarget
-
getBaseURI
- Specified by:
getBaseURIin interfaceNode
-
compareDocumentPosition
- Specified by:
compareDocumentPositionin interfaceNode- Throws:
DOMException
-
getTextContent
- Specified by:
getTextContentin interfaceNode- Throws:
DOMException
-
setTextContent
- Specified by:
setTextContentin interfaceNode- Throws:
DOMException
-
isSameNode
- Specified by:
isSameNodein interfaceNode
-
isDefaultNamespace
- Specified by:
isDefaultNamespacein interfaceNode
-
lookupPrefix
- Specified by:
lookupPrefixin interfaceNode
-
lookupNamespaceURI
- Specified by:
lookupNamespaceURIin interfaceNode
-
isEqualNode
- Specified by:
isEqualNodein interfaceNode
-
getFeature
- Specified by:
getFeaturein interfaceNode
-
setUserData
- Specified by:
setUserDatain interfaceNode
-
getUserData
- Specified by:
getUserDatain interfaceNode
-
changed
protected void changed()Denotes that this node has changed. -
changes
protected int changes()Returns the number of changes to this node.- Returns:
- the number of changes
-
needsSyncChildren
public final void needsSyncChildren(boolean value) -
toString
-