org.jaxen.dom
Class NamespaceNode

java.lang.Object
  extended byorg.jaxen.dom.NamespaceNode
All Implemented Interfaces:
org.w3c.dom.Node

public class NamespaceNode
extends java.lang.Object
implements org.w3c.dom.Node

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.

  1. 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.
  2. The getOwnerDocument() method returns the owner document of the parent node, but that owner document will know nothing about the namespace node.

  3. The isSupported(java.lang.String, java.lang.String) method always returns false.
  4. 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).

Author:
David Megginson, Elliotte Rusty Harold
See Also:
DocumentNavigator

Field Summary
static short NAMESPACE_NODE
          Constant: this is a NamespaceNode.
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
NamespaceNode(org.w3c.dom.Node parent, java.lang.String name, java.lang.String value)
          Create a new NamespaceNode.
 
Method Summary
 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.
 boolean equals(java.lang.Object o)
          Test for equivalence with another object.
 org.w3c.dom.NamedNodeMap getAttributes()
          Get the attribute nodes.
 java.lang.String getBaseURI()
          Return the base URI of the document containing this node (always fails).
 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.
 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 (always fails).
 java.lang.String lookupPrefix(java.lang.String namespaceURI)
          Return the prefix bound to this namespace URI within the scope of this node (always fails).
 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, org.w3c.dom.UserDataHandler handler)
          Associates an object with a key.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE_NODE

public static final short NAMESPACE_NODE
Constant: this is a NamespaceNode.

See Also:
getNodeType(), Constant Field Values
Constructor Detail

NamespaceNode

public NamespaceNode(org.w3c.dom.Node parent,
                     java.lang.String name,
                     java.lang.String value)
Create a new NamespaceNode.

Parameters:
parent - the DOM node to which the namespace is attached
name - the namespace prefix
value - the namespace URI
Method Detail

getNodeName

public java.lang.String getNodeName()
Get the namespace prefix.

Specified by:
getNodeName in interface org.w3c.dom.Node
Returns:
the namespace prefix, or "" for the default namespace

getNodeValue

public java.lang.String getNodeValue()
Get the namespace URI.

Specified by:
getNodeValue in interface org.w3c.dom.Node
Returns:
the namespace URI

setNodeValue

public void setNodeValue(java.lang.String value)
                  throws org.w3c.dom.DOMException
Change the namespace URI (always fails).

Specified by:
setNodeValue in interface org.w3c.dom.Node
Parameters:
value - the new URI
Throws:
org.w3c.dom.DOMException - always

getNodeType

public short getNodeType()
Get the node type.

Specified by:
getNodeType in interface org.w3c.dom.Node
Returns:
always NAMESPACE_NODE.

getParentNode

public org.w3c.dom.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.

Specified by:
getParentNode in interface org.w3c.dom.Node
Returns:
the parent node (not null)

getChildNodes

public org.w3c.dom.NodeList getChildNodes()
Get the list of child nodes.

Specified by:
getChildNodes in interface org.w3c.dom.Node
Returns:
an empty node list

getFirstChild

public org.w3c.dom.Node getFirstChild()
Get the first child node.

Specified by:
getFirstChild in interface org.w3c.dom.Node
Returns:
null

getLastChild

public org.w3c.dom.Node getLastChild()
Get the last child node.

Specified by:
getLastChild in interface org.w3c.dom.Node
Returns:
null

getPreviousSibling

public org.w3c.dom.Node getPreviousSibling()
Get the previous sibling node.

Specified by:
getPreviousSibling in interface org.w3c.dom.Node
Returns:
null

getNextSibling

public org.w3c.dom.Node getNextSibling()
Get the next sibling node.

Specified by:
getNextSibling in interface org.w3c.dom.Node
Returns:
null

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()
Get the attribute nodes.

Specified by:
getAttributes in interface org.w3c.dom.Node
Returns:
null

getOwnerDocument

public org.w3c.dom.Document getOwnerDocument()
Get the owner document.

Specified by:
getOwnerDocument in interface org.w3c.dom.Node
Returns:
the owner document of the parent node

insertBefore

public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node refChild)
                              throws org.w3c.dom.DOMException
Insert a new child node (always fails).

Specified by:
insertBefore in interface org.w3c.dom.Node
Parameters:
newChild - the node to add
refChild - ignored
Returns:
never
Throws:
org.w3c.dom.DOMException - always
See Also:
Node.insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)

replaceChild

public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node oldChild)
                              throws org.w3c.dom.DOMException
Replace a child node (always fails).

Specified by:
replaceChild in interface org.w3c.dom.Node
Parameters:
newChild - the node to add
oldChild - the child node to replace
Returns:
never
Throws:
org.w3c.dom.DOMException - always
See Also:
Node.replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)

removeChild

public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
                             throws org.w3c.dom.DOMException
Remove a child node (always fails).

Specified by:
removeChild in interface org.w3c.dom.Node
Parameters:
oldChild - the child node to remove
Returns:
never
Throws:
org.w3c.dom.DOMException - always
See Also:
Node.removeChild(org.w3c.dom.Node)

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
                             throws org.w3c.dom.DOMException
Append a new child node (always fails).

Specified by:
appendChild in interface org.w3c.dom.Node
Parameters:
newChild - the node to add
Returns:
never
Throws:
org.w3c.dom.DOMException - always
See Also:
Node.appendChild(org.w3c.dom.Node)

hasChildNodes

public boolean hasChildNodes()
Test for child nodes.

Specified by:
hasChildNodes in interface org.w3c.dom.Node
Returns:
false

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)
Create a copy of this node.

Specified by:
cloneNode in interface org.w3c.dom.Node
Parameters:
deep - make a deep copy (no effect, since namespace nodes don't have children).
Returns:
a new copy of this namespace node

normalize

public void normalize()
Normalize the text descendants of this node.

This method has no effect, since namespace nodes have no descendants.

Specified by:
normalize in interface org.w3c.dom.Node

isSupported

public boolean isSupported(java.lang.String feature,
                           java.lang.String version)
Test if a DOM2 feature is supported.

Specified by:
isSupported in interface org.w3c.dom.Node
Parameters:
feature - the feature name
version - the feature version
Returns:
false

getNamespaceURI

public java.lang.String getNamespaceURI()
Get the namespace URI of this node.

Namespace declarations are not themselves Namespace-qualified.

Specified by:
getNamespaceURI in interface org.w3c.dom.Node
Returns:
null

getPrefix

public java.lang.String getPrefix()
Get the namespace prefix of this node.

Namespace declarations are not themselves namespace-qualified.

Specified by:
getPrefix in interface org.w3c.dom.Node
Returns:
null
See Also:
getLocalName()

setPrefix

public void setPrefix(java.lang.String prefix)
               throws org.w3c.dom.DOMException
Change the namespace prefix of this node (always fails).

Specified by:
setPrefix in interface org.w3c.dom.Node
Parameters:
prefix - the new prefix
Throws:
org.w3c.dom.DOMException - always thrown

getLocalName

public java.lang.String getLocalName()
Get the XPath name of the namespace node;; i.e. the namespace prefix.

Specified by:
getLocalName in interface org.w3c.dom.Node
Returns:
the namespace prefix

hasAttributes

public boolean hasAttributes()
Test if this node has attributes.

Specified by:
hasAttributes in interface org.w3c.dom.Node
Returns:
false

hashCode

public int hashCode()
Generate a hash code for a namespace node.

Returns:
a hash code for this node

equals

public boolean equals(java.lang.Object o)
Test for equivalence with another object.

Two Namespace nodes are considered equivalent if their parents, names, and values are equal.

Parameters:
o - the object to test for equality
Returns:
true if the object is equivalent to this node, false otherwise

getBaseURI

public java.lang.String getBaseURI()
Return the base URI of the document containing this node (always fails).

Returns:
null

compareDocumentPosition

public short compareDocumentPosition(org.w3c.dom.Node other)
                              throws org.w3c.dom.DOMException
Compare relative position of this node to another nbode. (Always fails).

Returns:
never
Throws:
org.w3c.dom.DOMException - NOT_SUPPORTED_ERR

getTextContent

public java.lang.String getTextContent()
Return the namespace URI.

Returns:
the namespace URI
See Also:
getNodeValue()

setTextContent

public void setTextContent(java.lang.String textContent)
                    throws org.w3c.dom.DOMException
Change the value of this node (always fails).

Parameters:
textContent - the new content
Throws:
org.w3c.dom.DOMException - always

isSameNode

public 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.

Parameters:
other - the node to compare to
Returns:
true if this object represents the same XPath namespace node as other; false otherwise

lookupPrefix

public java.lang.String lookupPrefix(java.lang.String namespaceURI)
Return the prefix bound to this namespace URI within the scope of this node (always fails).

Returns:
never
Throws:
java.lang.UnsupportedOperationException - always

isDefaultNamespace

public boolean isDefaultNamespace(java.lang.String namespaceURI)
Return true if the specified URI is the default namespace in scope (always fails).

Returns:
never
Throws:
java.lang.UnsupportedOperationException - always

lookupNamespaceURI

public java.lang.String lookupNamespaceURI(java.lang.String prefix)
Return the namespace URI mapped to the specified prefix within the scope of this namespace node (always fails).

Returns:
never
Throws:
java.lang.UnsupportedOperationException - always

isEqualNode

public boolean isEqualNode(org.w3c.dom.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.

Parameters:
arg - the node to compare to
Returns:
true if this object has the same prefix and URI as the argument; false otherwise

getFeature

public java.lang.Object getFeature(java.lang.String feature,
                                   java.lang.String version)
Returns the value of the requested feature. Always returns null.

Returns:
null

setUserData

public java.lang.Object setUserData(java.lang.String key,
                                    java.lang.Object data,
                                    org.w3c.dom.UserDataHandler handler)
Associates an object with a key.

Parameters:
key - the key by which the data will be retrieved
data - the object to store with the key
handler - ignored since nnamespace ndoes cannot be imported, cloned, or renamed
Returns:
the value previously associated with this key; or null if there isn't any such previous value

getUserData

public java.lang.Object getUserData(java.lang.String key)
Returns the user data associated with the given key.

Returns:
the object associated with the key; or null if no such object is available


Copyright © 2001-2005 Codehaus. All Rights Reserved.