public class NamespaceNode
extends java.lang.Object
implements org.w3c.dom.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.
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.getOwnerDocument()
method returns the owner document
of the parent node, but that owner document will know nothing about
the namespace node.
isSupported(java.lang.String, java.lang.String)
method always returns false.All attempts to modify a NamespaceNode
will fail with a DOMException
(DOMException.NO_MODIFICATION_ALLOWED_ERR
).
DocumentNavigator
Modifier and Type | Class and Description |
---|---|
private static class |
NamespaceNode.EmptyNodeList
A node list with no members.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
name |
static short |
NAMESPACE_NODE
Constant: this is a NamespaceNode.
|
private org.w3c.dom.Node |
parent |
private java.util.HashMap |
userData |
private java.lang.String |
value |
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
Constructor and Description |
---|
NamespaceNode(org.w3c.dom.Node parent,
org.w3c.dom.Node attribute)
Constructor.
|
NamespaceNode(org.w3c.dom.Node parent,
java.lang.String name,
java.lang.String value)
Create a new NamespaceNode.
|
Modifier and Type | Method and Description |
---|---|
org.w3c.dom.Node |
appendChild(org.w3c.dom.Node newChild)
Append a new child node (always fails).
|
org.w3c.dom.Node |
cloneNode(boolean deep)
Create a copy of this node.
|
short |
compareDocumentPosition(org.w3c.dom.Node other)
Compare relative position of this node to another nbode.
|
private void |
disallowModification()
Throw a NO_MODIFICATION_ALLOWED_ERR DOMException.
|
boolean |
equals(java.lang.Object o)
Test for equivalence with another object.
|
private boolean |
equals(java.lang.Object a,
java.lang.Object b)
Helper method for comparing two objects.
|
org.w3c.dom.NamedNodeMap |
getAttributes()
Get the attribute nodes.
|
java.lang.String |
getBaseURI()
Return the base URI of the document containing this node.
|
org.w3c.dom.NodeList |
getChildNodes()
Get the list of child nodes.
|
java.lang.Object |
getFeature(java.lang.String feature,
java.lang.String version)
Returns the value of the requested feature.
|
org.w3c.dom.Node |
getFirstChild()
Get the first child node.
|
org.w3c.dom.Node |
getLastChild()
Get the last child node.
|
java.lang.String |
getLocalName()
Get the XPath name of the namespace node;; i.e.
|
java.lang.String |
getNamespaceURI()
Get the namespace URI of this node.
|
org.w3c.dom.Node |
getNextSibling()
Get the next sibling node.
|
java.lang.String |
getNodeName()
Get the namespace prefix.
|
short |
getNodeType()
Get the node type.
|
java.lang.String |
getNodeValue()
Get the namespace URI.
|
org.w3c.dom.Document |
getOwnerDocument()
Get the owner document.
|
org.w3c.dom.Node |
getParentNode()
Get the parent node.
|
java.lang.String |
getPrefix()
Get the namespace prefix of this node.
|
org.w3c.dom.Node |
getPreviousSibling()
Get the previous sibling node.
|
java.lang.String |
getTextContent()
Return the namespace URI.
|
java.lang.Object |
getUserData(java.lang.String key)
Returns the user data associated with the given key.
|
boolean |
hasAttributes()
Test if this node has attributes.
|
boolean |
hasChildNodes()
Test for child nodes.
|
int |
hashCode()
Generate a hash code for a namespace node.
|
private int |
hashCode(java.lang.Object o)
Helper method for generating a hash code.
|
org.w3c.dom.Node |
insertBefore(org.w3c.dom.Node newChild,
org.w3c.dom.Node refChild)
Insert a new child node (always fails).
|
boolean |
isDefaultNamespace(java.lang.String namespaceURI)
Return true if the specified URI is the default namespace in
scope (always fails).
|
boolean |
isEqualNode(org.w3c.dom.Node arg)
Returns true if this object binds the same prefix to the same URI.
|
boolean |
isSameNode(org.w3c.dom.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.
|
boolean |
isSupported(java.lang.String feature,
java.lang.String version)
Test if a DOM2 feature is supported.
|
java.lang.String |
lookupNamespaceURI(java.lang.String prefix)
Return the namespace URI mapped to the specified
prefix within the scope of this namespace node.
|
java.lang.String |
lookupPrefix(java.lang.String namespaceURI)
Return the prefix bound to this namespace URI within the scope
of this node.
|
void |
normalize()
Normalize the text descendants of this node.
|
org.w3c.dom.Node |
removeChild(org.w3c.dom.Node oldChild)
Remove a child node (always fails).
|
org.w3c.dom.Node |
replaceChild(org.w3c.dom.Node newChild,
org.w3c.dom.Node oldChild)
Replace a child node (always fails).
|
void |
setNodeValue(java.lang.String value)
Change the namespace URI (always fails).
|
void |
setPrefix(java.lang.String prefix)
Change the namespace prefix of this node (always fails).
|
void |
setTextContent(java.lang.String textContent)
Change the value of this node (always fails).
|
java.lang.Object |
setUserData(java.lang.String key,
java.lang.Object data,
UserDataHandler handler)
Associates an object with a key.
|
public static final short NAMESPACE_NODE
getNodeType()
,
Constant Field Valuesprivate org.w3c.dom.Node parent
private java.lang.String name
private java.lang.String value
private java.util.HashMap userData
public NamespaceNode(org.w3c.dom.Node parent, java.lang.String name, java.lang.String value)
parent
- the DOM node to which the namespace is attachedname
- the namespace prefixvalue
- the namespace URINamespaceNode(org.w3c.dom.Node parent, org.w3c.dom.Node attribute)
parent
- the DOM node to which the namespace is attachedattribute
- the DOM attribute object containing the
namespace declarationpublic java.lang.String getNodeName()
getNodeName
in interface org.w3c.dom.Node
public java.lang.String getNodeValue()
getNodeValue
in interface org.w3c.dom.Node
public void setNodeValue(java.lang.String value) throws org.w3c.dom.DOMException
setNodeValue
in interface org.w3c.dom.Node
value
- the new URIorg.w3c.dom.DOMException
- alwayspublic short getNodeType()
getNodeType
in interface org.w3c.dom.Node
NAMESPACE_NODE
.public org.w3c.dom.Node getParentNode()
This method returns the element that was queried for Namespaces in effect, not necessarily the actual element containing the Namespace declaration.
getParentNode
in interface org.w3c.dom.Node
public org.w3c.dom.NodeList getChildNodes()
getChildNodes
in interface org.w3c.dom.Node
public org.w3c.dom.Node getFirstChild()
getFirstChild
in interface org.w3c.dom.Node
public org.w3c.dom.Node getLastChild()
getLastChild
in interface org.w3c.dom.Node
public org.w3c.dom.Node getPreviousSibling()
getPreviousSibling
in interface org.w3c.dom.Node
public org.w3c.dom.Node getNextSibling()
getNextSibling
in interface org.w3c.dom.Node
public org.w3c.dom.NamedNodeMap getAttributes()
getAttributes
in interface org.w3c.dom.Node
public org.w3c.dom.Document getOwnerDocument()
getOwnerDocument
in interface org.w3c.dom.Node
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws org.w3c.dom.DOMException
insertBefore
in interface org.w3c.dom.Node
newChild
- the node to addrefChild
- ignoredorg.w3c.dom.DOMException
- alwaysNode.insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws org.w3c.dom.DOMException
replaceChild
in interface org.w3c.dom.Node
newChild
- the node to addoldChild
- the child node to replaceorg.w3c.dom.DOMException
- alwaysNode.replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws org.w3c.dom.DOMException
removeChild
in interface org.w3c.dom.Node
oldChild
- the child node to removeorg.w3c.dom.DOMException
- alwaysNode.removeChild(org.w3c.dom.Node)
public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws org.w3c.dom.DOMException
appendChild
in interface org.w3c.dom.Node
newChild
- the node to addorg.w3c.dom.DOMException
- alwaysNode.appendChild(org.w3c.dom.Node)
public boolean hasChildNodes()
hasChildNodes
in interface org.w3c.dom.Node
public org.w3c.dom.Node cloneNode(boolean deep)
cloneNode
in interface org.w3c.dom.Node
deep
- make a deep copy (no effect, since namespace nodes
don't have children).public void normalize()
This method has no effect, since namespace nodes have no descendants.
normalize
in interface org.w3c.dom.Node
public boolean isSupported(java.lang.String feature, java.lang.String version)
isSupported
in interface org.w3c.dom.Node
feature
- the feature nameversion
- the feature versionpublic java.lang.String getNamespaceURI()
Namespace declarations are not themselves Namespace-qualified.
getNamespaceURI
in interface org.w3c.dom.Node
public java.lang.String getPrefix()
Namespace declarations are not themselves namespace-qualified.
getPrefix
in interface org.w3c.dom.Node
getLocalName()
public void setPrefix(java.lang.String prefix) throws org.w3c.dom.DOMException
setPrefix
in interface org.w3c.dom.Node
prefix
- the new prefixorg.w3c.dom.DOMException
- always thrownpublic java.lang.String getLocalName()
getLocalName
in interface org.w3c.dom.Node
public boolean hasAttributes()
hasAttributes
in interface org.w3c.dom.Node
private void disallowModification() throws org.w3c.dom.DOMException
org.w3c.dom.DOMException
- always thrownpublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
Two Namespace nodes are considered equivalent if their parents, names, and values are equal.
equals
in class java.lang.Object
o
- the object to test for equalityprivate int hashCode(java.lang.Object o)
o
- the object for generating a hash code (possibly null)Object.hashCode()
private boolean equals(java.lang.Object a, java.lang.Object b)
a
- the first object to compare (possibly null)b
- the second object to compare (possibly null)Object.equals(java.lang.Object)
public java.lang.String getBaseURI()
getBaseURI
in interface org.w3c.dom.Node
public short compareDocumentPosition(org.w3c.dom.Node other) throws org.w3c.dom.DOMException
compareDocumentPosition
in interface org.w3c.dom.Node
other
- the node to compare toorg.w3c.dom.DOMException
- NOT_SUPPORTED_ERRpublic java.lang.String getTextContent()
getTextContent
in interface org.w3c.dom.Node
getNodeValue()
public void setTextContent(java.lang.String textContent) throws org.w3c.dom.DOMException
setTextContent
in interface org.w3c.dom.Node
textContent
- the new contentorg.w3c.dom.DOMException
- alwayspublic boolean isSameNode(org.w3c.dom.Node other)
isSameNode
in interface org.w3c.dom.Node
other
- the node to compare topublic java.lang.String lookupPrefix(java.lang.String namespaceURI)
lookupPrefix
in interface org.w3c.dom.Node
namespaceURI
- the URI to find a prefix binding forjava.lang.UnsupportedOperationException
- in DOM 2public boolean isDefaultNamespace(java.lang.String namespaceURI)
isDefaultNamespace
in interface org.w3c.dom.Node
namespaceURI
- the URI to checkjava.lang.UnsupportedOperationException
- alwayspublic java.lang.String lookupNamespaceURI(java.lang.String prefix)
lookupNamespaceURI
in interface org.w3c.dom.Node
prefix
- the prefix to search forjava.lang.UnsupportedOperationException
- in DOM 2public boolean isEqualNode(org.w3c.dom.Node arg)
isEqualNode
in interface org.w3c.dom.Node
arg
- the node to compare topublic java.lang.Object getFeature(java.lang.String feature, java.lang.String version)
getFeature
in interface org.w3c.dom.Node
public java.lang.Object setUserData(java.lang.String key, java.lang.Object data, UserDataHandler handler)
setUserData
in interface org.w3c.dom.Node
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 renamedpublic java.lang.Object getUserData(java.lang.String key)
getUserData
in interface org.w3c.dom.Node
key
- the lookup key