org.jaxen.dom
Class NamespaceNode

java.lang.Object
  |
  +--org.jaxen.dom.NamespaceNode
All Implemented Interfaces:
Node

public class NamespaceNode
extends Object
implements Node

Extension DOM2 node type for a Namespace Declaration.

This class implements the DOM2 Node interface to allow Namespace declarations to be included in the result set of an XPath selectNodes operation, even though DOM2 does not model Namespace declarations as separate nodes.

While all of the 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.

All attempts to modify a NamespaceNode will fail with a DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR).

This class has only protected constructors, so that it can be instantiated only by DocumentNavigator.

Author:
David Megginson
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(Node parent, String name, String value)
          Constructor.
 
Method Summary
 Node appendChild(Node newChild)
          Append a new child node (always fails).
 Node cloneNode(boolean deep)
          Create a copy of this node.
 boolean equals(Object o)
          Test for equivalence with another object.
 NamedNodeMap getAttributes()
          Get the attribute nodes.
 NodeList getChildNodes()
          Get the list of child nodes.
 Node getFirstChild()
          Get the first child node.
 Node getLastChild()
          Get the last child node.
 String getLocalName()
          Get the local name for this node.
 String getNamespaceURI()
          Get the Namespace URI for this node.
 Node getNextSibling()
          Get the next sibling node.
 String getNodeName()
          Get the Namespace prefix.
 short getNodeType()
          Get the node type.
 String getNodeValue()
          Get the Namespace URI.
 Document getOwnerDocument()
          Get the owner document.
 Node getParentNode()
          Get the parent node.
 String getPrefix()
          Get the Namespace prefix for this node.
 Node getPreviousSibling()
          Get the previous sibling node.
 boolean hasAttributes()
          Test if this node has attributes.
 boolean hasChildNodes()
          Test for child nodes.
 int hashCode()
          Generate a hash code for a Namespace node.
 Node insertBefore(Node newChild, Node refChild)
          Insert a new child node (always fails).
 boolean isSupported(String feature, String version)
          Test if a DOM2 feature is supported.
 void normalize()
          Normalize the text descendants of this node.
 Node removeChild(Node oldChild)
          Remove a child node (always fails).
 Node replaceChild(Node newChild, Node oldChild)
          Replace a child node (always fails).
 void setNodeValue(String value)
          Change the Namespace URI (always fails).
 void setPrefix(String prefix)
          Change the Namespace prefix for this node (always fails).
 
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()
Constructor Detail

NamespaceNode

public NamespaceNode(Node parent,
                     String name,
                     String value)
Constructor.
Parameters:
parent - The DOM node to which the Namespace is attached.
uri - The Namespace URI as a string.
Method Detail

getNodeName

public String getNodeName()
Get the Namespace prefix.
Specified by:
getNodeName in interface Node
Returns:
The Namespace prefix, or "" for the default Namespace.

getNodeValue

public String getNodeValue()
Get the Namespace URI.
Specified by:
getNodeValue in interface Node
Returns:
The Namespace URI.

setNodeValue

public void setNodeValue(String value)
                  throws DOMException
Change the Namespace URI (always fails).
Specified by:
setNodeValue in interface Node
Parameters:
value - The new URI.
Throws:
DOMException - always thrown.

getNodeType

public short getNodeType()
Get the node type.
Specified by:
getNodeType in interface Node
Returns:
Always NAMESPACE_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.

Specified by:
getParentNode in interface Node
Returns:
The parent node (not null).

getChildNodes

public NodeList getChildNodes()
Get the list of child nodes.
Specified by:
getChildNodes in interface Node
Returns:
An empty node list.

getFirstChild

public Node getFirstChild()
Get the first child node.
Specified by:
getFirstChild in interface Node
Returns:
Always null.

getLastChild

public Node getLastChild()
Get the last child node.
Specified by:
getLastChild in interface Node
Returns:
Always null.

getPreviousSibling

public Node getPreviousSibling()
Get the previous sibling node.
Specified by:
getPreviousSibling in interface Node
Returns:
Always null.

getNextSibling

public Node getNextSibling()
Get the next sibling node.
Specified by:
getNextSibling in interface Node
Returns:
Always null.

getAttributes

public NamedNodeMap getAttributes()
Get the attribute nodes.
Specified by:
getAttributes in interface Node
Returns:
Always null.

getOwnerDocument

public Document getOwnerDocument()
Get the owner document.
Specified by:
getOwnerDocument in interface Node
Returns:
The owner document of the parent node.

insertBefore

public Node insertBefore(Node newChild,
                         Node refChild)
                  throws DOMException
Insert a new child node (always fails).
Specified by:
insertBefore in interface Node
Throws:
DOMException - always thrown.
See Also:
Node.insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)

replaceChild

public Node replaceChild(Node newChild,
                         Node oldChild)
                  throws DOMException
Replace a child node (always fails).
Specified by:
replaceChild in interface Node
Throws:
DOMException - always thrown.
See Also:
Node.replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)

removeChild

public Node removeChild(Node oldChild)
                 throws DOMException
Remove a child node (always fails).
Specified by:
removeChild in interface Node
Throws:
DOMException - always thrown.
See Also:
Node.removeChild(org.w3c.dom.Node)

appendChild

public Node appendChild(Node newChild)
                 throws DOMException
Append a new child node (always fails).
Specified by:
appendChild in interface Node
Throws:
DOMException - always thrown.
See Also:
Node.appendChild(org.w3c.dom.Node)

hasChildNodes

public boolean hasChildNodes()
Test for child nodes.
Specified by:
hasChildNodes in interface Node
Returns:
Always false.

cloneNode

public Node cloneNode(boolean deep)
Create a copy of this node.
Specified by:
cloneNode in interface 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 Node

isSupported

public boolean isSupported(String feature,
                           String version)
Test if a DOM2 feature is supported.
Specified by:
isSupported in interface Node
Parameters:
feature - The feature name.
version - The feature version.
Returns:
Always false.

getNamespaceURI

public String getNamespaceURI()
Get the Namespace URI for this node.

Namespace declarations are not themselves Namespace-qualified.

Specified by:
getNamespaceURI in interface Node
Returns:
Always null.

getPrefix

public String getPrefix()
Get the Namespace prefix for this node.

Namespace declarations are not themselves Namespace-qualified.

Specified by:
getPrefix in interface Node
Returns:
Always null.

setPrefix

public void setPrefix(String prefix)
               throws DOMException
Change the Namespace prefix for this node (always fails).
Specified by:
setPrefix in interface Node
Parameters:
prefix - The new prefix.
Throws:
DOMException - always thrown.

getLocalName

public String getLocalName()
Get the local name for this node.
Specified by:
getLocalName in interface Node
Returns:
Always null.

hasAttributes

public boolean hasAttributes()
Test if this node has attributes.
Specified by:
hasAttributes in interface Node
Returns:
Always false.

hashCode

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

The hash code is the sum of the hash codes of the parent node, name, and value.

Overrides:
hashCode in class Object
Returns:
A hash code for this node.

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.

Overrides:
equals in class Object
Parameters:
o - The object to test for equality.
Returns:
true if the object is equivalent to this node, false otherwise.


Copyright © 2002 bob mcwhirter & James Strachan. All Rights Reserved. Hosted by

SourceForge Logo