javax.xml.namespace
Class QName

java.lang.Object
  extended by javax.xml.namespace.QName
All Implemented Interfaces:
java.io.Serializable

public class QName
extends java.lang.Object
implements java.io.Serializable

A QName is a qualified name, as specified by XML Schema Part2: Datatypes specification, Namespaces in XML, Namespaces in XML Errata. A qualified name is made up of a namespace URI, a local part, and a prefix. The prefix is not really a part of the QName and remains only to provide lexical information. It is not used in the equals(Object) or hashCode() methods.

Namespace URI and prefix may be omitted, in which case the default value "" (empty string) is used.

Instances of QName are immutable. You may safely store references.

See Also:
Serialized Form

Constructor Summary
QName(java.lang.String pLocalPart)
          Creates a new QName with the given pLocalPart, the namespace URI "" (empty string), and the prefix "" (empty string).
QName(java.lang.String pNamespaceURI, java.lang.String pLocalPart)
          Creates a new QName with the given pNamespaceURI and pLocalPart.
QName(java.lang.String pNamespaceURI, java.lang.String pLocalPart, java.lang.String pPrefix)
          Creates a new QName with the given pNamespaceURI, pLocalPart, and pPrefix.
 
Method Summary
 boolean equals(java.lang.Object pOther)
          Returns true, if pOther instanceof QName getNamespaceURI().equals(pOther.getNamespaceURI()) getLocalPart().equals(pOther.getLocalPart()) Note: The prefix is ignored.
 java.lang.String getLocalPart()
          Returns the local part of the QName.
 java.lang.String getNamespaceURI()
          Returns the namespace URI.
 java.lang.String getPrefix()
          Returns the namespace prefix.
 int hashCode()
          Returns the QName's hash code.
 java.lang.String toString()
          Converts the QName into a string representation.
static QName valueOf(java.lang.String pQName)
          Parses the given string representation of a pQName.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QName

public QName(java.lang.String pNamespaceURI,
             java.lang.String pLocalPart)

Creates a new QName with the given pNamespaceURI and pLocalPart. The prefix is set to "" (empty string).

Parameters:
pNamespaceURI - The namespace URI; may be null, in which case the default value "" (empty string) is used.
pLocalPart - The local part.
Throws:
java.lang.IllegalArgumentException - The local part was null.

QName

public QName(java.lang.String pNamespaceURI,
             java.lang.String pLocalPart,
             java.lang.String pPrefix)

Creates a new QName with the given pNamespaceURI, pLocalPart, and pPrefix.

Parameters:
pNamespaceURI - The namespace URI; may be null, in which case the default value "" (empty string) is used.
pLocalPart - The local part.
pPrefix - The prefix. Must not be null. Use "" (empty string) to indicate that no namespace URI is present or the namespace URI is not relevant.
Throws:
java.lang.IllegalArgumentException - The local part or the prefix was null.

QName

public QName(java.lang.String pLocalPart)

Creates a new QName with the given pLocalPart, the namespace URI "" (empty string), and the prefix "" (empty string).

Parameters:
pLocalPart - The local part.
Throws:
java.lang.IllegalArgumentException - The local part or the prefix was null.
Method Detail

getNamespaceURI

public java.lang.String getNamespaceURI()

Returns the namespace URI.

Returns:
Namespace URI or "" (empty string) to indicate the absence of a namespace.

getLocalPart

public java.lang.String getLocalPart()

Returns the local part of the QName.

Returns:
The local part.

getPrefix

public java.lang.String getPrefix()

Returns the namespace prefix.

Returns:
The namespace prefix or "" (empty string) to indicate the default namespace

equals

public boolean equals(java.lang.Object pOther)

Returns true, if

Note: The prefix is ignored.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Returns the QName's hash code. The prefix is ignored when calculating the hash code.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()

Converts the QName into a string representation. The current implementation returns the local part, if the namespace URI is "" (empty string). Otherwise returns "{" + namespaceURI + "}" + localPart. The prefix is ignored.

The representation is subject to changes, as there is currently no standard representation for a QName. You should use this method for debugging or logging purposes only.

Overrides:
toString in class java.lang.Object

valueOf

public static QName valueOf(java.lang.String pQName)

Parses the given string representation of a pQName. The QName is expected to have the same representation than returned by toString().

It is not possible to specify a prefix. The returned QName will always have the prefix "" (empty string).

Parameters:
pQName - String representation of a QName, as generated by toString().
Returns:
QName with the prefix "" (empty string)
Throws:
java.lang.IllegalArgumentException - The given pQName was null or empty.