Package net.sf.saxon.om
Class StructuredQName
java.lang.Object
net.sf.saxon.om.StructuredQName
- All Implemented Interfaces:
IdentityComparable
This class provides an economical representation of a QName triple (prefix, URI, and localname).
The value is stored internally as a character array containing the concatenation of URI, localname,
and prefix (in that order) with two integers giving the start positions of the localname and prefix.
Instances of this class are immutable.
-
Constructor Summary
ConstructorsConstructorDescriptionStructuredQName
(String prefix, String uri, String localName) Construct a StructuredQName from a prefix, URI, and local name.StructuredQName
(String prefix, NamespaceUri uri, String localName) Construct a StructuredQName from a prefix, URI, and local name. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
computeHashCode
(NamespaceUri uri, String local) Expose the hashCode algorithm so that other implementations of QNames can construct a compatible hashcodeboolean
Compare two StructuredQName values for equality.static StructuredQName
fromClarkName
(String expandedName) Make a structuredQName from a Clark namestatic StructuredQName
fromEQName
(String eqName) Make a structured QName from an EQName inQ{uri}local
format.static StructuredQName
fromLexicalQName
(String lexicalName, boolean useDefault, boolean allowEQName, NamespaceResolver resolver) Make a structured QName from a lexical QName, using a supplied NamespaceResolver to resolve the prefixGet the expanded QName in Clark format, that is "{uri}local" if it is in a namespace, or just "local" otherwise.Get the display name, that is the lexical QName in the form [prefix:]local-partGet the expanded QName as an EQName, that is "Q{uri}local" for a name in a namespace, or "Q{}local" otherwiseGet the local part of the QNameGet the NamespaceBinding (prefix/uri pair) corresponding to this nameGet the namespace URI of the QName.Get the prefix of the QName.Get the name as a StructuredQName (which it already is; but this satisfies the NodeName interface)getURI()
Get the namespace URI of the QName as a string.int
hashCode()
Get a hashcode to reflect the equals() method.boolean
hasURI
(NamespaceUri uri) Test whether the URI is equal to some constantint
Get a hashCode that offers the guarantee that if A.isIdentical(B), then A.identityHashCode() == B.identityHashCode()boolean
isIdentical
(IdentityComparable other) Determine whether two IdentityComparable objects are identical.Convert the StructuredQName to a javax.xml.namespace.QNametoString()
The toString() method displays the QName as a lexical QName, that is prefix:local
-
Constructor Details
-
StructuredQName
Construct a StructuredQName from a prefix, URI, and local name. This method performs no validation.- Parameters:
prefix
- The prefix. Use an empty string to represent the null prefix.uri
- The namespace URI. UseNamespaceUri.NULL
to represent the no-namespacelocalName
- The local part of the name
-
StructuredQName
Construct a StructuredQName from a prefix, URI, and local name. This method performs no validation.- Parameters:
prefix
- The prefix. Use an empty string to represent the null prefix.uri
- The namespace URI. Use an empty string or null to represent the no-namespacelocalName
- The local part of the name
-
-
Method Details
-
fromClarkName
Make a structuredQName from a Clark name- Parameters:
expandedName
- the name in Clark notation "{uri}local" if in a namespace, or "local" otherwise. The format "{}local" is also accepted for a name in no namespace. The EQName syntax (Q{uri}local) is also accepted.- Returns:
- the constructed StructuredQName
- Throws:
IllegalArgumentException
- if the Clark name is malformed
-
fromLexicalQName
public static StructuredQName fromLexicalQName(String lexicalName, boolean useDefault, boolean allowEQName, NamespaceResolver resolver) throws XPathException Make a structured QName from a lexical QName, using a supplied NamespaceResolver to resolve the prefix- Parameters:
lexicalName
- the QName as a lexical name (prefix:local), or (Q{uri}local) if allowEQName is set to true. Leading and trailing whitespace is ignored.useDefault
- set to true if an absent prefix implies use of the default namespace; set to false if an absent prefix implies no namespaceallowEQName
- true if the EQName syntax Q{uri}local is acceptableresolver
- NamespaceResolver used to look up a URI for the prefix- Returns:
- the StructuredQName object corresponding to this lexical QName
- Throws:
XPathException
- if the namespace prefix is not in scope or if the value is lexically invalid. Error code FONS0004 is set if the namespace prefix has not been declared; error code FOCA0002 is set if the name is lexically invalid. These may need to be changed on return depending on the caller's requirements.
-
fromEQName
Make a structured QName from an EQName inQ{uri}local
format.- Parameters:
eqName
- the QName as an EQName (Q{uri}local
), or an unqualified local name. The format of the local name is not checked.- Returns:
- the StructuredQName object corresponding to this EQName
- Throws:
IllegalArgumentException
- if the eqName syntax is invalid (but the format of the URI and local name parts are not checked)
-
getPrefix
Get the prefix of the QName.- Returns:
- the prefix. Returns the empty string if the name is unprefixed.
-
getNamespaceUri
Get the namespace URI of the QName.- Returns:
- the URI. Returns
NamespaceUri.NULL
to represent the no-namespace
-
getURI
Get the namespace URI of the QName as a string.This method is retained for backwards compatibility, but
getNamespaceUri()
should be used in preference.- Returns:
- the URI. Returns the empty string to represent the no-namespace
-
hasURI
Test whether the URI is equal to some constant- Parameters:
uri
- the namespace URI to be tested- Returns:
- true if the namespace URI of this QName is equal to the supplied URI
-
getLocalPart
Get the local part of the QName- Returns:
- the local part of the QName
-
getDisplayName
Get the display name, that is the lexical QName in the form [prefix:]local-part- Returns:
- the lexical QName
-
getStructuredQName
Get the name as a StructuredQName (which it already is; but this satisfies the NodeName interface)- Returns:
- the name as a StructuredQName
-
getClarkName
Get the expanded QName in Clark format, that is "{uri}local" if it is in a namespace, or just "local" otherwise.- Returns:
- the QName in Clark notation
-
getEQName
Get the expanded QName as an EQName, that is "Q{uri}local" for a name in a namespace, or "Q{}local" otherwise- Returns:
- the QName in EQName notation
-
toString
The toString() method displays the QName as a lexical QName, that is prefix:local -
equals
Compare two StructuredQName values for equality. This compares the URI and local name parts, excluding any prefix -
hashCode
public int hashCode()Get a hashcode to reflect the equals() method.The hashcode is based on the URI and local part only, ignoring the prefix. In fact the URI plays little part in computing the hashcode:
NamespaceUri
objects are pooled, so the hashcode is simply the object identifier. -
computeHashCode
Expose the hashCode algorithm so that other implementations of QNames can construct a compatible hashcode- Parameters:
uri
- the namespace URIlocal
- the local name- Returns:
- a hash code computed from the URI and local name
-
toJaxpQName
Convert the StructuredQName to a javax.xml.namespace.QName- Returns:
- an object of class javax.xml.namespace.QName representing this qualified name
-
getNamespaceBinding
Get the NamespaceBinding (prefix/uri pair) corresponding to this name- Returns:
- a NamespaceBinding containing the prefix and URI present in this QName
-
isIdentical
Determine whether two IdentityComparable objects are identical. This is a stronger test than equality (even schema-equality); for example two dateTime values are not identical unless they are in the same timezone. In the case of a StructuredQName, the identity test compares prefixes as well as the namespace URI and local name.- Specified by:
isIdentical
in interfaceIdentityComparable
- Parameters:
other
- the value to be compared with- Returns:
- true if the two values are identical, false otherwise
-
identityHashCode
public int identityHashCode()Get a hashCode that offers the guarantee that if A.isIdentical(B), then A.identityHashCode() == B.identityHashCode()- Specified by:
identityHashCode
in interfaceIdentityComparable
- Returns:
- a hashCode suitable for use when testing for identity.
-