Extension DOM2/DOM3 node type for a namespace node.
This class implements the DOM2 and DOM3
Node
interface
to allow namespace nodes to be included in the result
set of an XPath selectNodes operation, even though DOM does
not model namespaces in scope as separate nodes.
While all of the DOM2 methods are implemented with reasonable
defaults, there will be some unexpected surprises, so users are
advised to test for NamespaceNodes and filter them out from the
result sets as early as possible.
- The
getNodeType()
method returns NAMESPACE_NODE
,
which is not one of the usual DOM2 node types. Generic code may
fall unexpectedly out of switch statements, for example. - The
getOwnerDocument()
method returns the owner document
of the parent node, but that owner document will know nothing about
the namespace node.
- The
isSupported(String,String)
method always returns false. - The DOM3 methods sometimes throw UnsupportedOperationException.
They're here only to allow this class to be compiled with Java 1.5.
Do not call or rely on them.
All attempts to modify a
NamespaceNode
will fail with a
DOMException
(
DOMException.NO_MODIFICATION_ALLOWED_ERR
).
appendChild
public Node appendChild(Node newChild)
throws DOMException
Append a new child node (always fails).
newChild
- the node to add
cloneNode
public Node cloneNode(boolean deep)
Create a copy of this node.
deep
- make a deep copy (no effect, since namespace nodes
don't have children).
- a new copy of this namespace node
compareDocumentPosition
public short compareDocumentPosition(Node other)
throws DOMException
Compare relative position of this node to another nbode. (Always fails).
This method is included solely for compatibility with the superclass.
other
- the node to compare to
disallowModification
private void disallowModification()
throws DOMException
Throw a NO_MODIFICATION_ALLOWED_ERR DOMException.
equals
public boolean equals(Object o)
Test for equivalence with another object.
Two Namespace nodes are considered equivalent if their parents,
names, and values are equal.
o
- the object to test for equality
- true if the object is equivalent to this node, false
otherwise
equals
private boolean equals(Object a,
Object b)
Helper method for comparing two objects.
a
- the first object to compare (possibly null)b
- the second object to compare (possibly null)
- true if the objects are equivalent or are both null
getAttributes
public NamedNodeMap getAttributes()
Get the attribute nodes.
getBaseURI
public String getBaseURI()
Return the base URI of the document containing this node.
This only works in DOM 3.
getChildNodes
public NodeList getChildNodes()
Get the list of child nodes.
getFeature
public Object getFeature(String feature,
String version)
Returns the value of the requested feature. Always returns null.
getFirstChild
public Node getFirstChild()
Get the first child node.
getLastChild
public Node getLastChild()
Get the last child node.
getLocalName
public String getLocalName()
Get the XPath name of the namespace node;; i.e. the
namespace prefix.
getNamespaceURI
public String getNamespaceURI()
Get the namespace URI of this node.
Namespace declarations are not themselves
Namespace-qualified.
getNextSibling
public Node getNextSibling()
Get the next sibling node.
getNodeName
public String getNodeName()
Get the namespace prefix.
- the namespace prefix, or "" for the default namespace
getNodeType
public short getNodeType()
Get the node type.
getNodeValue
public String getNodeValue()
Get the namespace URI.
getOwnerDocument
public Document getOwnerDocument()
Get the owner document.
- the owner document of the parent node
getParentNode
public Node getParentNode()
Get the parent node.
This method returns the element that was queried for Namespaces
in effect,
not necessarily the actual element containing
the Namespace declaration.
- the parent node (not null)
getPrefix
public String getPrefix()
Get the namespace prefix of this node.
Namespace declarations are not themselves
namespace-qualified.
getPreviousSibling
public Node getPreviousSibling()
Get the previous sibling node.
getTextContent
public String getTextContent()
Return the namespace URI.
getUserData
public Object getUserData(String key)
Returns the user data associated with the given key.
- the object associated with the key; or null if no such object is available
hasAttributes
public boolean hasAttributes()
Test if this node has attributes.
hasChildNodes
public boolean hasChildNodes()
Test for child nodes.
hashCode
public int hashCode()
Generate a hash code for a namespace node.
- a hash code for this node
hashCode
private int hashCode(Object o)
Helper method for generating a hash code.
o
- the object for generating a hash code (possibly null)
- the object's hash code, or 0 if the object is null
java.lang.Object.hashCode
insertBefore
public Node insertBefore(Node newChild,
Node refChild)
throws DOMException
Insert a new child node (always fails).
newChild
- the node to addrefChild
- ignored
isDefaultNamespace
public boolean isDefaultNamespace(String namespaceURI)
Return true if the specified URI is the default namespace in
scope (always fails). This method is included solely for
compatibility with the superclass.
namespaceURI
- the URI to check
isEqualNode
public boolean isEqualNode(Node arg)
Returns true if this object binds the same prefix to the same URI.
That is, this object has the same prefix and URI as the argument.
arg
- the node to compare to
- true if this object has the same prefix and URI as the argument; false otherwise
isSameNode
public boolean isSameNode(Node other)
Returns true if and only if this object represents the same XPath namespace node
as the argument; that is, they have the same parent, the same prefix, and the
same URI.
other
- the node to compare to
- true if this object represents the same XPath namespace node
as other; false otherwise
isSupported
public boolean isSupported(String feature,
String version)
Test if a DOM2 feature is supported. (None are.)
feature
- the feature nameversion
- the feature version
lookupNamespaceURI
public String lookupNamespaceURI(String prefix)
Return the namespace URI mapped to the specified
prefix within the scope of this namespace node.
prefix
- the prefix to search for
- the namespace URI mapped to this prefix
lookupPrefix
public String lookupPrefix(String namespaceURI)
Return the prefix bound to this namespace URI within the scope
of this node.
namespaceURI
- the URI to find a prefix binding for
- a prefix matching this namespace URI
normalize
public void normalize()
Normalize the text descendants of this node.
This method has no effect, since namespace nodes have no
descendants.
removeChild
public Node removeChild(Node oldChild)
throws DOMException
Remove a child node (always fails).
oldChild
- the child node to remove
replaceChild
public Node replaceChild(Node newChild,
Node oldChild)
throws DOMException
Replace a child node (always fails).
newChild
- the node to addoldChild
- the child node to replace
setNodeValue
public void setNodeValue(String value)
throws DOMException
Change the namespace URI (always fails).
setPrefix
public void setPrefix(String prefix)
throws DOMException
Change the namespace prefix of this node (always fails).
setTextContent
public void setTextContent(String textContent)
throws DOMException
Change the value of this node (always fails).
This method is included solely for compatibility with the superclass.
textContent
- the new content
setUserData
public Object setUserData(String key,
Object data,
org.w3c.dom.UserDataHandler handler)
Associates an object with a key.
key
- the key by which the data will be retrieveddata
- the object to store with the keyhandler
- ignored since namespace nodes cannot be imported, cloned, or renamed
- the value previously associated with this key; or null
if there isn't any such previous value