Package org.jdom2

Class Namespace

java.lang.Object
org.jdom2.Namespace
All Implemented Interfaces:
Serializable

public final class Namespace extends Object implements Serializable
An XML namespace representation, as well as a factory for creating XML namespace objects. All methods on Namespace (including getNamespace(String) and getNamespace(String, String)) are thread-safe.

See NamespaceAware for 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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Namespace
    Define a Namespace for when not in a namespace
    static final Namespace
    Define a Namespace for the standard xml prefix.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    This tests for equality - Two Namespaces are equal if and only if their URIs are byte-for-byte equals.
    static Namespace
    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(String prefix, String uri)
    This will retrieve (if in existence) or create (if not) a Namespace for the supplied prefix and uri.
    This returns the prefix mapped to this Namespace.
    This returns the namespace URI for this Namespace.
    int
    This returns the hash code for the Namespace that conforms to the 'equals()' contract.
    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 Details

    • 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.
  • Method Details

    • getNamespace

      public static Namespace getNamespace(String prefix, String uri)
      This will retrieve (if in existence) or create (if not) a Namespace for the supplied prefix and uri. This method is thread-safe.
      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.
      See Also:
    • getNamespace

      public static Namespace getNamespace(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. This method is thread-safe.
      Parameters:
      uri - String URI of new Namespace.
      Returns:
      Namespace - ready to use namespace.
    • getPrefix

      public String getPrefix()
      This returns the prefix mapped to this Namespace.
      Returns:
      String - prefix for this Namespace.
    • getURI

      public String getURI()
      This returns the namespace URI for this Namespace.
      Returns:
      String - URI for this Namespace.
    • equals

      public boolean equals(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 Object
      Parameters:
      ob - Object to compare to this Namespace.
      Returns:
      boolean - whether the supplied object is equal to this Namespace.
    • toString

      public String toString()
      This returns a String representation of this Namespace, suitable for use in debugging.
      Overrides:
      toString in class Object
      Returns:
      String - information about this instance.
    • hashCode

      public int hashCode()
      This returns the hash code for the Namespace that 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:
      hashCode in class Object
      Returns:
      int - hash code for this Namespace.