Package org.jdom2
Class Namespace
- java.lang.Object
-
- org.jdom2.Namespace
-
- All Implemented Interfaces:
java.io.Serializable
public final class Namespace extends java.lang.Object implements java.io.SerializableAn XML namespace representation, as well as a factory for creating XML namespace objects. All methods on Namespace (includinggetNamespace(String)andgetNamespace(String, String)) are thread-safe.See
NamespaceAwarefor additional notes on how Namespaces are 'in-scope' in JDOM content, and how those in-scope Namespaces are accessed.- Author:
- Brett McLaughlin, Elliotte Rusty Harold, Jason Hunter, Wesley Biggs, Rolf Lear
- See Also:
NamespaceAware, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static NamespaceNO_NAMESPACEDefine aNamespacefor when not in a namespacestatic NamespaceXML_NAMESPACEDefine aNamespacefor the standard xml prefix.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object ob)This tests for equality - TwoNamespacesare 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) aNamespacefor 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) aNamespacefor the supplied prefix and uri.java.lang.StringgetPrefix()This returns the prefix mapped to thisNamespace.java.lang.StringgetURI()This returns the namespace URI for thisNamespace.inthashCode()This returns the hash code for theNamespacethat conforms to the 'equals()' contract.java.lang.StringtoString()This returns aStringrepresentation of thisNamespace, suitable for use in debugging.
-
-
-
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) aNamespacefor the supplied prefix and uri. This method is thread-safe.- Parameters:
prefix-Stringprefix to map toNamespace.uri-StringURI of newNamespace.- Returns:
Namespace- ready to use namespace.- Throws:
IllegalNameException- if the given prefix and uri make up an illegal namespace name.- See Also:
Verifier.checkNamespacePrefix(String),Verifier.checkNamespaceURI(String)
-
getNamespace
public static Namespace getNamespace(java.lang.String uri)
This will retrieve (if in existence) or create (if not) aNamespacefor the supplied URI, and make it usable as a default namespace, as no prefix is supplied. This method is thread-safe.- Parameters:
uri-StringURI of newNamespace.- Returns:
Namespace- ready to use namespace.
-
getPrefix
public java.lang.String getPrefix()
This returns the prefix mapped to thisNamespace.- Returns:
String- prefix for thisNamespace.
-
getURI
public java.lang.String getURI()
This returns the namespace URI for thisNamespace.- Returns:
String- URI for thisNamespace.
-
equals
public boolean equals(java.lang.Object ob)
This tests for equality - TwoNamespacesare equal if and only if their URIs are byte-for-byte equals.- Overrides:
equalsin classjava.lang.Object- Parameters:
ob-Objectto compare to thisNamespace.- Returns:
boolean- whether the supplied object is equal to thisNamespace.
-
toString
public java.lang.String toString()
This returns aStringrepresentation of thisNamespace, suitable for use in debugging.- Overrides:
toStringin classjava.lang.Object- Returns:
String- information about this instance.
-
hashCode
public int hashCode()
This returns the hash code for theNamespacethat conforms to the 'equals()' contract.If two namespaces have the same URI, they are equal and have the same hash code, even if they have different prefixes.
- Overrides:
hashCodein classjava.lang.Object- Returns:
int- hash code for thisNamespace.
-
-