public final class Namespace
extends java.lang.Object
Namespace
defines both a factory for
creating XML namespaces, and a namespace itself. This class
represents an XML namespace in Java.
Elements and Attributes containing Namespaces can be serialized;
however the Namespace class itself does not implement
java.io.Serializable
. This works because the Element and
Attribute classes handle serialization of their Namespaces manually.
The classes use the getNamespace() method on deserialization to ensure
there may be only one unique Namespace object for any unique
prefix/uri pair, something needed for efficiency reasons.
Modifier and Type | Field and Description |
---|---|
static Namespace |
NO_NAMESPACE
Define a
Namespace for when not in a namespace |
static Namespace |
XML_NAMESPACE |
Modifier and Type | Method and Description |
---|---|
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. |
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. |
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. |
java.lang.String |
getPrefix()
This returns the prefix mapped to this
Namespace . |
java.lang.String |
getURI()
This returns the namespace URI for this
Namespace . |
int |
hashCode()
This returns a probably unique hash code for the
Namespace . |
java.lang.String |
toString()
This returns a
String representation of this
Namespace , suitable for use in debugging. |
public static final Namespace NO_NAMESPACE
Namespace
for when not in a namespacepublic static final Namespace XML_NAMESPACE
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.
prefix
- String
prefix to map to
Namespace
.uri
- String
URI of new Namespace
.Namespace
- ready to use namespace.IllegalNameException
- if the given prefix and uri make up
an illegal namespace name.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.
uri
- String
URI of new Namespace
.Namespace
- ready to use namespace.public java.lang.String getPrefix()
This returns the prefix mapped to this Namespace
.
String
- prefix for this Namespace
.public java.lang.String getURI()
This returns the namespace URI for this Namespace
.
String
- URI for this Namespace
.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.
equals
in class java.lang.Object
ob
- Object
to compare to this Namespace
.boolean
- whether the supplied object is equal to
this Namespace
.public java.lang.String toString()
This returns a String
representation of this
Namespace
, suitable for use in debugging.
toString
in class java.lang.Object
String
- information about this instance.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.
hashCode
in class java.lang.Object
int
- hash code for this Namespace
.Copyright (c) 2015 Software AG. All Rights Reserved.