public abstract class NodeImpl extends Object implements Node, Cloneable
Node
is the primary class in the DOM, representing a
single node in the document tree. All other classes derived and extend
their major functionality from this class.
This class is abstract. All derived classes must extend getNodeType()
. This class does not support child nodes, all classes
supporting child nodes must extend ParentNodeImpl
. In addition,
derived classes might wish to extend Node.cloneNode(boolean)
,
equals(java.lang.Object)
and Object.toString()
and other methods as necessary.
Many methods cannot be extended.
For speed and consistency, this is a "kitchen sink" class. It implements most of the functionality for all derived class types.
NodeImpl
does not support child nodes, such support is available
in the extended class ParentNodeImpl
. Namespace support (for
element and attribute) is available in ParentNSNodeImpl
.
Node
Modifier and Type | Field and Description |
---|---|
static short |
ATTLIST_DECL_NODE
Attributes list declaration node.
|
static short |
ELEMENT_DECL_NODE
Element declaration node.
|
static short |
PARAM_ENTITY_NODE
Parameter entity declaration node.
|
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
Modifier | Constructor and Description |
---|---|
protected |
NodeImpl(DocumentImpl owner,
String name,
String value)
Hidden constructor creates a new node.
|
Modifier and Type | Method and Description |
---|---|
Node |
appendChild(Node newChild)
Insert newChild as the last child of this parent.
|
protected void |
cloneInto(NodeImpl into,
boolean deep)
This clone method is called after a new node has been constructed to
copy the contents of this node into the new one.
|
boolean |
equals(Object other)
Returns true if this node and other are identical by content but
not context.
|
NamedNodeMap |
getAttributes()
Return attributes of node.
|
NodeList |
getChildNodes()
Returns a
NodeList object that can be used to traverse this
node's children. |
Node |
getFirstChild()
Returns the first child of the node.
|
Node |
getLastChild()
Returns the last child of the node.
|
String |
getLocalName() |
String |
getNamespaceURI() |
Node |
getNextSibling()
Returns the next sibling of this node.
|
String |
getNodeName()
Returns the name of the node, set from the constructor.
|
abstract short |
getNodeType()
Abstract method must be implemented by each node class.
|
String |
getNodeValue()
Returns the value of the node.
|
Document |
getOwnerDocument()
Return the document associated with this node.
|
Node |
getParentNode()
Returns the parent node of this node.
|
String |
getPrefix() |
Node |
getPreviousSibling()
Returns the previous sibling of this node.
|
boolean |
hasChildNodes()
Return true if there are any childern to this node.
|
Node |
insertBefore(Node newChild,
Node refChild)
Insert newChild in this parent, before the existing child
refChild.
|
boolean |
isReadOnly()
Returns true if node is read-only and cannot be modified, or if node
belongs to a read-only document.
|
void |
makeReadOnly()
Renders this node read only, preventing it's contents from being
modified.
|
void |
normalize() |
Node |
removeChild(Node oldChild)
Remove oldChild from this parent.
|
Node |
replaceChild(Node newChild,
Node oldChild)
Replace oldChild with newChild, adding the new child
and removing the old one.
|
void |
setNodeValue(String value)
Changes the value of the node.
|
protected void |
setOwnerDocument(Document owner)
Sets the owner document of this node and all its children.
|
void |
setPrefix(String newPrefix) |
boolean |
supports(String feature,
String version)
Returns true if the node defines a subtree within which the specified
feature is supported, false otherwise.
|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
cloneNode, compareDocumentPosition, getBaseURI, getFeature, getTextContent, getUserData, hasAttributes, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, setTextContent, setUserData
public static final short ELEMENT_DECL_NODE
public static final short ATTLIST_DECL_NODE
public static final short PARAM_ENTITY_NODE
ParamEntity
).protected NodeImpl(DocumentImpl owner, String name, String value) throws DOMException
DocumentImpl
and DocumentTypeImpl
.
Name must be supplied, either dynamic or static (e.g. "#document#").
If checkName is true, the supplied named is assumed to be a valid XML name token, one that can contain any Unicode letters and digits, must start with a letter, and may also contain hyphen, underscore, digit or colon.
owner
- Document owner of this node, or nullname
- Name of nodevalue
- Initial value of node or nullDOMException
- INVALID_CHARACTER_ERR
Node name cannot contain whitespaces or non-printable characterspublic abstract short getNodeType()
getNodeType
in interface Node
Node.getNodeType()
public String getNodeName()
getNodeName
in interface Node
Node.getNodeName()
public String getNamespaceURI()
getNamespaceURI
in interface Node
public String getLocalName()
getLocalName
in interface Node
public final String getNodeValue()
Text
),
or always null is node has no notion of a value (e.g. Element
). For complete list of which node types will return
what, see setNodeValue(java.lang.String)
.getNodeValue
in interface Node
public void setNodeValue(String value)
Element Not supported Attr Supported Text Supported CDATASection Supported EntityReference Not supported Entity Not supported ProcessingInstruction Supported Comment Supported Document Not supported DocumentType Not supported DocumentFragment Not supported Notation Not supportedFor most node types, if the value is set to null,
getNodeValue()
will return an empty string instead.setNodeValue
in interface Node
value
- New value of nodepublic Node getParentNode()
Document
node is always
parentless.getParentNode
in interface Node
public NodeList getChildNodes()
NodeList
object that can be used to traverse this
node's children. The node list is live, so every change to this node
is reflected in it. If the node does not support children, returns
an empty node list.getChildNodes
in interface Node
NodeList
on this nodeNodeList
public Node getFirstChild()
getFirstChild
in interface Node
public Node getLastChild()
getLastChild
in interface Node
public Node getPreviousSibling()
getPreviousSibling
in interface Node
public Node getNextSibling()
getNextSibling
in interface Node
public NamedNodeMap getAttributes()
Element
, in which case the returned NamedNodeMap
will provide
access to all the element's
attributes.getAttributes
in interface Node
public final Document getOwnerDocument()
Document
, or a
DocumentType
which is not used with any document, will
return null.getOwnerDocument
in interface Node
public boolean hasChildNodes()
getChildNodes()
.hasChildNodes
in interface Node
public Node appendChild(Node newChild)
If newChild is null, newChild is not a compatible type, or childern are not supported by this node type, an exception is thrown.
newChild is removed from its original parent before adding to
this parent. If newChild is a DocumentFragment
, all
its children are inserted one by one into this parent.
appendChild
in interface Node
newChild
- The new child to addDOMException
- NO_MODIFICATION_ALLOWED_ERR
Node is read-only and cannot be modifiedDOMException
- HIERARCHY_REQUEST_ERR
Children are not supported by this node type, or newChild is
not a compatible type for this nodepublic Node insertBefore(Node newChild, Node refChild) throws DOMException
appendChild(org.w3c.dom.Node)
.
If newChild is null, newChild does not belong to this DOM, refChild is not a direct child of this node, or childern are not supported by this node type, an exception is thrown.
newChild is removed from its original parent before adding
to this parent. If newChild is a DocumentFragment
, all
its children are inserted one by one into this parent.
insertBefore
in interface Node
newChild
- The new child to addrefChild
- Insert new child before this child, or insert at the end
if this child is nullDOMException
- NO_MODIFICATION_ALLOWED_ERR
Node is read-only and cannot be modifiedDOMException
- HIERARCHY_REQUEST_ERR
Children are not supported by this node type, or newChild
is not a compatible type for this nodeDOMException
- NOT_FOUND_ERR
oldChild is not null and not a direct child of this nodepublic Node removeChild(Node oldChild) throws DOMException
removeChild
in interface Node
oldChild
- The child to removeDOMException
- NO_MODIFICATION_ALLOWED_ERR
Node is read-only and cannot be modifiedDOMException
- HIERARCHY_REQUEST_ERR
Children are not supported by this node typeDOMException
- NOT_FOUND_ERR
oldChild is not a direct child of this nodepublic Node replaceChild(Node newChild, Node oldChild) throws DOMException
If newChild does not belong to this DOM, oldChild is not a direct child of this parent, or childern are not supported by this node type, an exception is thrown.
newChild is removed from its original parent before adding to
this parent. If newChild is a DocumentFragment
, all
its children are inserted one by one into this parent.
replaceChild
in interface Node
newChild
- The new child to addoldChild
- The old child to take awayDOMException
- NO_MODIFICATION_ALLOWED_ERR
Node is read-only and cannot be modifiedDOMException
- HIERARCHY_REQUEST_ERR
Children are not supported by this node type, or newChild is
not a compatible type for this nodeDOMException
- NOT_FOUND_ERR
oldChild is not a direct child of this nodepublic final void makeReadOnly()
public final boolean isReadOnly()
makeReadOnly()
public final boolean supports(String feature, String version)
feature
- The package name of the feature setversion
- The version number of the feature set (e.g. "2.0" for
Level 2), or any version if nullprotected final void setOwnerDocument(Document owner) throws DOMException
owner
- The new ownerDOMException
- The owner is not of this DOM implementationprotected void cloneInto(NodeImpl into, boolean deep)
equals(java.lang.Object)
).
into must be a valid node of the exact same class as this one. deep is true if deep cloning (includes all children nodes) is to be performed. If deep is false, the clone might not pass the equality test.
Derived classes override and call this method to add per-class variable
copying. This method is called by Node.cloneNode(boolean)
and the default
Object.clone()
method.
Contents cloning duplicates the node's name and value, and its children. It does not duplicate it's context, that is, the node's parent or sibling. Initially a clone node has no parents or siblings. However, the node does belong to the same document, since all nodes must belong to some document. The cloned node is never read-only.
into
- A node into which to duplicate this onedeep
- True if deep cloning is requiredpublic boolean equals(Object other)
equals(java.lang.Object)
on each pair
Note that for large document roots, the equality operation can be very expensive.
Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© © Mindus SARL, 2024. All rights reserved.