public class StructuredQName extends java.lang.Object implements IdentityComparable
Instances of this class are immutable.
Constructor and Description |
---|
StructuredQName(java.lang.String prefix,
java.lang.String uri,
java.lang.String localName)
Construct a StructuredQName from a prefix, URI, and local name.
|
Modifier and Type | Method and Description |
---|---|
StructuredQName |
addPrefix(java.lang.String prefix)
Make a StructuredQName from a StructuredQName holding the local name and URI, plus a new prefix
|
static int |
computeHashCode(java.lang.CharSequence uri,
java.lang.CharSequence local)
Expose the hashCode algorithm so that other implementations of QNames can construct a compatible hashcode
|
boolean |
equals(java.lang.Object other)
Compare two StructuredQName values for equality.
|
static StructuredQName |
fromClarkName(java.lang.String expandedName)
Make a structuredQName from a Clark name
|
static StructuredQName |
fromEQName(java.lang.CharSequence eqName)
Make a structured QName from a lexical QName, using a supplied NamespaceResolver to
resolve the prefix
|
static StructuredQName |
fromLexicalQName(java.lang.CharSequence lexicalName,
boolean useDefault,
boolean allowEQName,
NamespaceResolver resolver)
Make a structured QName from a lexical QName, using a supplied NamespaceResolver to
resolve the prefix
|
java.lang.String |
getClarkName()
Get the expanded QName in Clark format, that is "{uri}local" if it is in a namespace, or just "local"
otherwise.
|
java.lang.String |
getDisplayName()
Get the display name, that is the lexical QName in the form [prefix:]local-part
|
java.lang.String |
getEQName()
Get the expanded QName as an EQName, that is "Q{uri}local" for a name in a namespace,
or "Q{}local" otherwise
|
java.lang.String |
getLocalPart()
Get the local part of the QName
|
NamespaceBinding |
getNamespaceBinding()
Get the NamespaceBinding (prefix/uri pair) corresponding to this name
|
java.lang.String |
getPrefix()
Get the prefix of the QName.
|
StructuredQName |
getStructuredQName()
Get the name as a StructuredQName (which it already is; but this satisfies the NodeName interface)
|
java.lang.String |
getURI()
Get the namespace URI of the QName.
|
int |
hashCode()
Get a hashcode to reflect the equals() method.
|
boolean |
hasURI(java.lang.String uri)
Test whether the URI is equal to some constant
|
int |
identityHashCode()
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.
|
boolean |
isInSameNamespace(NodeName other)
Test whether this name is in the same namespace as another name
|
javax.xml.namespace.QName |
toJaxpQName()
Convert the StructuredQName to a javax.xml.namespace.QName
|
java.lang.String |
toString()
The toString() method displays the QName as a lexical QName, that is prefix:local
|
public StructuredQName(java.lang.String prefix, java.lang.String uri, java.lang.String localName)
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 namepublic StructuredQName addPrefix(java.lang.String prefix)
public static StructuredQName fromClarkName(java.lang.String expandedName)
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.java.lang.IllegalArgumentException
- if the Clark name is malformedpublic static StructuredQName fromLexicalQName(java.lang.CharSequence lexicalName, boolean useDefault, boolean allowEQName, NamespaceResolver resolver) throws XPathException
lexicalName
- the QName as a lexical name (prefix:local)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 prefixXPathException
- 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.public static StructuredQName fromEQName(java.lang.CharSequence eqName)
eqName
- the QName as an EQname (Q{uri}local), or an unqualified local name. The format
of the local name is not checked.java.lang.IllegalArgumentException
- if the eqName syntax is invalid (but the format of the
URI and local name parts are not checked)public java.lang.String getPrefix()
public java.lang.String getURI()
public boolean hasURI(java.lang.String uri)
uri
- the namespace URI to be testedpublic java.lang.String getLocalPart()
public java.lang.String getDisplayName()
public StructuredQName getStructuredQName()
public java.lang.String getClarkName()
public java.lang.String getEQName()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
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, because the URI is often long, and largely redundant: QNames with the same local name will rarely have different URIs, and there are significant performance savings in the NamePool if a cheaper hashcode is used. So the only contribution from the URI is that we take its length into account.
hashCode
in class java.lang.Object
public static int computeHashCode(java.lang.CharSequence uri, java.lang.CharSequence local)
uri
- the namespace URIlocal
- the local namepublic boolean isInSameNamespace(NodeName other)
other
- the other namepublic javax.xml.namespace.QName toJaxpQName()
public NamespaceBinding getNamespaceBinding()
public boolean isIdentical(IdentityComparable other)
isIdentical
in interface IdentityComparable
other
- the value to be compared withpublic int identityHashCode()
identityHashCode
in interface IdentityComparable
Copyright (c) 2004-2018 Saxonica Limited. All rights reserved.