Class Namespace

java.lang.Object
  extended by Namespace
public final class Namespace
extends java.lang.Object

An XML namespace representation, as well as a factory for creating XML namespace objects. Namespaces are not Serializable, however objects that use namespaces have special logic to handle serialization manually. These classes call the getNamespace() method on deserialization to ensure there is one unique Namespace object for any unique prefix/uri pair.

Field Summary
private static java.lang.StringCVS_ID
           
private static java.util.HashMapnamespaces
          Factory list of namespaces.
static NamespaceNO_NAMESPACE
          Define a Namespace for when not in a namespace
private  java.lang.Stringprefix
          The prefix mapped to this namespace
private  java.lang.Stringuri
          The URI for this namespace
static NamespaceXML_NAMESPACE
          Define a Namespace for the standard xml prefix.
 
Constructor Summary
private Namespace(java.lang.String prefix, java.lang.String uri)
          This constructor handles creation of a Namespace object with a prefix and URI; it is intentionally left private so that it cannot be invoked by external programs/code.
 
Method Summary
 booleanequals(java.lang.Object ob)
          This tests for equality - Two Namespaces are equal if and only if their URIs are byte-for-byte equals.
static NamespacegetNamespace(java.lang.String uri)
          This will retrieve (if in existence) or create (if not) a Namespace for the supplied URI, and make it usable as a default namespace, as no prefix is supplied.
static NamespacegetNamespace(java.lang.String prefix, java.lang.String uri)
          This will retrieve (if in existence) or create (if not) a Namespace for the supplied prefix and URI.
 java.lang.StringgetPrefix()
          This returns the prefix mapped to this Namespace.
 java.lang.StringgetURI()
          This returns the namespace URI for this Namespace.
 inthashCode()
          This returns a probably unique hash code for the Namespace.
 java.lang.StringtoString()
          This returns a String representation of this Namespace, suitable for use in debugging.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CVS_ID

private static final java.lang.String CVS_ID
See Also:
Constant Field Values

namespaces

private static java.util.HashMap namespaces
Factory list of namespaces. Keys are prefix&URI. Values are Namespace objects

NO_NAMESPACE

public static final Namespace NO_NAMESPACE
Define a Namespace for when not in a namespace

XML_NAMESPACE

public static final Namespace XML_NAMESPACE
Define a Namespace for the standard xml prefix.

prefix

private java.lang.String prefix
The prefix mapped to this namespace

uri

private java.lang.String uri
The URI for this namespace

Constructor Detail

Namespace

private Namespace(java.lang.String prefix,
                  java.lang.String uri)
This constructor handles creation of a Namespace object with a prefix and URI; it is intentionally left private so that it cannot be invoked by external programs/code.

Parameters:
prefix - String prefix to map to this namespace.
uri - String URI for namespace.
Method Detail

getNamespace

public static Namespace getNamespace(java.lang.String prefix,
                                     java.lang.String uri)
This will retrieve (if in existence) or create (if not) a Namespace for the supplied prefix and URI.

Parameters:
prefix - String prefix to map to Namespace.
uri - String URI of new Namespace.
Returns:
Namespace - ready to use namespace.
Throws:
IllegalNameException - if the given prefix and uri make up an illegal namespace name.

getNamespace

public static Namespace getNamespace(java.lang.String uri)
This will retrieve (if in existence) or create (if not) a Namespace for the supplied URI, and make it usable as a default namespace, as no prefix is supplied.

Parameters:
uri - String URI of new Namespace.
Returns:
Namespace - ready to use namespace.

getPrefix

public java.lang.String getPrefix()
This returns the prefix mapped to this Namespace.

Returns:
String - prefix for this Namespace.

getURI

public java.lang.String getURI()
This returns the namespace URI for this Namespace.

Returns:
String - URI for this Namespace.

equals

public boolean equals(java.lang.Object ob)
This tests for equality - Two Namespaces are equal if and only if their URIs are byte-for-byte equals.

Overrides:
equals in class java.lang.Object
Parameters:
ob - Object to compare to this Namespace.
Returns:
boolean - whether the supplied object is equal to this Namespace.

toString

public java.lang.String toString()
This returns a String representation of this Namespace, suitable for use in debugging.

Overrides:
toString in class java.lang.Object
Returns:
String - information about this instance.

hashCode

public int hashCode()
This returns a probably unique hash code for the Namespace. If two namespaces have the same URI, they are equal and have the same hash code, even if they have different prefixes.

Overrides:
hashCode in class java.lang.Object
Returns:
int - hash code for this Namespace.