## org.dom4j
Class Namespace

    java.lang.Object
      org.dom4j.tree.AbstractNode
          org.dom4j.Namespace

All Implemented Interfaces:
  Cloneable, Node, Serializable

Direct Known Subclasses:
  DefaultNamespace

public class Namespace
extends AbstractNode

`Namespace` is a Flyweight Namespace that can be shared amongst nodes.

Version:
  $Revision: 1.22 $
Author:
  James Strachan
See Also:
  Serialized Form

Field Summary
`protected static NamespaceCache` `CACHE` Cache of Namespace instances
`static Namespace` `NO_NAMESPACE` No Namespace present
`static Namespace` `XML_NAMESPACE` XML Namespace

Fields inherited from class org.dom4j.tree.AbstractNode
`NODE_TYPE_NAMES`

Fields inherited from interface org.dom4j.Node
`ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE`

Constructor Summary
`Namespace(String prefix, String uri)` DOCUMENT ME!

Method Summary
`void` `accept(Visitor visitor)` `accept` is the method used in the Visitor Pattern.
`String` `asXML()` `asXML` returns the textual XML representation of this node.
`protected int` `createHashCode()` Factory method to create the hashcode allowing derived classes to change the behaviour
`protected Node` `createXPathResult(Element parent)`
`boolean` `equals(Object object)` Checks whether this Namespace equals the given Namespace.
`static Namespace` `get(String uri)` A helper method to return the Namespace instance for no prefix and the URI
`static Namespace` `get(String prefix, String uri)` A helper method to return the Namespace instance for the given prefix and URI
`short` `getNodeType()` Returns the code according to the type of node.
`String` `getPath(Element context)` Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c.
`String` `getPrefix()` DOCUMENT ME!
`String` `getStringValue()` Returns the XPath string-value of this node.
`String` `getText()` Returns the text of this node.
`String` `getUniquePath(Element context)` Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node.
`String` `getURI()` DOCUMENT ME!
`String` `getXPathNameStep()`
`int` `hashCode()` DOCUMENT ME!
`String` `toString()`

Methods inherited from class org.dom4j.tree.AbstractNode
`asXPathResult, clone, createPattern, createXPath, createXPathFilter, detach, getDocument, getDocumentFactory, getName, getNodeTypeName, getParent, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setName, setParent, setText, supportsParent, valueOf, write`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### CACHE

    protected static final NamespaceCache CACHE

  Cache of Namespace instances

### XML_NAMESPACE

    public static final Namespace XML_NAMESPACE

  XML Namespace

### NO_NAMESPACE

    public static final Namespace NO_NAMESPACE

  No Namespace present

Constructor Detail

### Namespace

    public Namespace(String prefix,
                     String uri)

  DOCUMENT ME!

Parameters:
  `prefix` - is the prefix for this namespace
  `uri` - is the URI for this namespace

Method Detail

### get

    public static Namespace get(String prefix,
                                String uri)

  A helper method to return the Namespace instance for the given prefix and URI

  Parameters:
    `prefix` - DOCUMENT ME!
    `uri` - DOCUMENT ME!
  Returns:
    an interned Namespace object

### get

    public static Namespace get(String uri)

  A helper method to return the Namespace instance for no prefix and the URI

  Parameters:
    `uri` - DOCUMENT ME!
  Returns:
    an interned Namespace object

### getNodeType

    public short getNodeType()

  Description copied from interface: `Node`
  Returns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.

  Specified by:
    `getNodeType` in interface `Node`
  Overrides:
    `getNodeType` in class `AbstractNode`

### hashCode

    public int hashCode()

  DOCUMENT ME!

  Returns:
    the hash code based on the qualified name and the URI of the namespace.

### createHashCode

    protected int createHashCode()

  Factory method to create the hashcode allowing derived classes to change the behaviour

  Returns:
    DOCUMENT ME!

### equals

    public boolean equals(Object object)

  Checks whether this Namespace equals the given Namespace. Two Namespaces are equals if their URI and prefix are equal.

  Parameters:
    `object` - DOCUMENT ME!
  Returns:
    DOCUMENT ME!

### getText

    public String getText()

  Description copied from interface: `Node`

  Returns the text of this node.

  Specified by:
    `getText` in interface `Node`
  Overrides:
    `getText` in class `AbstractNode`

### getStringValue

    public String getStringValue()

  Description copied from interface: `Node`
  Returns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .

  Specified by:
    `getStringValue` in interface `Node`
  Overrides:
    `getStringValue` in class `AbstractNode`

### getPrefix

    public String getPrefix()

  DOCUMENT ME!

  Returns:
    the prefix for this `Namespace`.

### getURI

    public String getURI()

  DOCUMENT ME!

  Returns:
    the URI for this `Namespace`.

### getXPathNameStep

    public String getXPathNameStep()

### getPath

    public String getPath(Element context)

  Description copied from interface: `Node`
  Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c. No indexing will be used to restrict the path if multiple elements with the same name occur on the path.

  Parameters:
    `context` - is the parent context from which the relative path should start. If the context is null or the context is not an ancestor of this node then the path will be absolute and start from the document and so begin with the '/' character.
  Returns:
    the XPath expression relative to the given context which will return a nodeset containing at least this node.

### getUniquePath

    public String getUniquePath(Element context)

  Description copied from interface: `Node`

  Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.

  Parameters:
    `context` - is the parent context from which the path should start. If the context is null or the context is not an ancestor of this node then the path will start from the document and so begin with the '/' character.
  Returns:
    the XPath expression relative to the given context which will return a nodeset containing just this node.

### toString

    public String toString()

### asXML

    public String asXML()

  Description copied from interface: `Node`

  `asXML` returns the textual XML representation of this node.

  Returns:
    the XML representation of this node

### accept

    public void accept(Visitor visitor)

  Description copied from interface: `Node`

  `accept` is the method used in the Visitor Pattern.

  Parameters:
    `visitor` - is the visitor in the Visitor Pattern

### createXPathResult

    protected Node createXPathResult(Element parent)

  Overrides:
    `createXPathResult` in class `AbstractNode`

Copyright © 2001-2005 MetaStuff Ltd.. All Rights Reserved.