Class StructuredQName

  • Direct Known Subclasses:
    FingerprintedQName

    public class StructuredQName
    extends java.lang.Object
    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

      Constructors 
      Constructor Description
      StructuredQName​(java.lang.String prefix, java.lang.String uri, java.lang.String localName)
      Construct a StructuredQName from a prefix, URI, and local name.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 fromLexicalQName​(java.lang.CharSequence lexicalName, boolean useDefault, NameChecker checker, 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
      int getFingerprint()
      Get the fingerprint of this name if known.
      java.lang.String getLocalPart()
      Get the local part of the QName
      int getNameCode()
      Get the nameCode of this name if known.
      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.
      boolean hasFingerprint()
      Ask whether this node name representation has a known namecode and fingerprint
      int hashCode()
      Get a hashcode to reflect the equals() method
      boolean isInNamespace​(java.lang.String ns)
      Test whether this name is in a given namespace
      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
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • StructuredQName

        public StructuredQName​(java.lang.String prefix,
                               java.lang.String uri,
                               java.lang.String localName)
        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-namespace
        localName - The local part of the name
    • Method Detail

      • fromClarkName

        public static StructuredQName fromClarkName​(java.lang.String expandedName)
        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.
        Returns:
        the constructed StructuredQName
        Throws:
        java.lang.IllegalArgumentException - if the Clark name is malformed
      • fromLexicalQName

        public static StructuredQName fromLexicalQName​(java.lang.CharSequence lexicalName,
                                                       boolean useDefault,
                                                       NameChecker checker,
                                                       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)
        useDefault - set to true if an absent prefix implies use of the default namespace; set to false if an absent prefix implies no namespace
        checker - NameChecker to be used to check conformance against XML 1.0 or 1.1 lexical rules
        resolver - 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.
      • getPrefix

        public java.lang.String getPrefix()
        Get the prefix of the QName.
        Returns:
        the prefix. Returns the empty string if the name is unprefixed.
      • getURI

        public java.lang.String getURI()
        Get the namespace URI of the QName.
        Returns:
        the URI. Returns the empty string to represent the no-namespace
      • getLocalPart

        public java.lang.String getLocalPart()
        Get the local part of the QName
        Returns:
        the local part of the QName
      • getDisplayName

        public java.lang.String getDisplayName()
        Get the display name, that is the lexical QName in the form [prefix:]local-part
        Returns:
        the lexical QName
      • getStructuredQName

        public StructuredQName getStructuredQName()
        Get the name as a StructuredQName (which it already is; but this satisfies the NodeName interface)
      • getClarkName

        public 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.
        Returns:
        the QName in Clark notation
      • toString

        public java.lang.String toString()
        The toString() method displays the QName as a lexical QName, that is prefix:local
        Overrides:
        toString in class java.lang.Object
        Returns:
        the lexical QName
      • equals

        public boolean equals​(java.lang.Object other)
        Compare two StructuredQName values for equality. This compares the URI and local name parts, excluding any prefix
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Get a hashcode to reflect the equals() method
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hashcode based on the URI and local part only, ignoring the prefix.
      • computeHashCode

        public 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
        Parameters:
        uri - the namespace URI
        local - the local name
        Returns:
        a hash code computed from the URI and local name
      • isInSameNamespace

        public boolean isInSameNamespace​(NodeName other)
        Test whether this name is in the same namespace as another name
        Parameters:
        other - the other name
        Returns:
        true if the two names are in the same namespace
      • isInNamespace

        public boolean isInNamespace​(java.lang.String ns)
        Test whether this name is in a given namespace
        Parameters:
        ns - the namespace to be tested against
        Returns:
        true if the name is in the specified namespace
      • toJaxpQName

        public javax.xml.namespace.QName toJaxpQName()
        Convert the StructuredQName to a javax.xml.namespace.QName
        Returns:
        an object of class javax.xml.namespace.QName representing this qualified name
      • getNamespaceBinding

        public NamespaceBinding getNamespaceBinding()
        Get the NamespaceBinding (prefix/uri pair) corresponding to this name
        Returns:
        a NamespaceBinding containing the prefix and URI present in this QName
      • hasFingerprint

        public boolean hasFingerprint()
        Ask whether this node name representation has a known namecode and fingerprint
        Returns:
        true if the methods getFingerprint() and getNameCode() will return a result other than -1
      • getFingerprint

        public int getFingerprint()
        Get the fingerprint of this name if known. This method should not to any work to allocate a fingerprint if none is already available
        Returns:
        the fingerprint if known; otherwise -1
      • getNameCode

        public int getNameCode()
        Get the nameCode of this name if known. This method should not to any work to allocate a nameCode if none is already available
        Returns:
        the fingerprint if known; otherwise -1