com.icl.saxon.om
Class Name

java.lang.Object
  |
  +--com.icl.saxon.om.Name
All Implemented Interfaces:
NameTest

public class Name
extends java.lang.Object
implements NameTest

An object representing a structured name, containing a Namespace URI, a Namespace prefix, and a local name.

The equivalence betweem names depends only on the URI and the local name. The prefix is retained for documentary purposes only: it is useful when reconstructing a document to use prefixes that the user is familiar with.

We use the term AbsoluteName to mean the concatenation of the URI and the local name (using circumflex as a separator); and DisplayName to mean the concatenation of the prefix and the local name (using colon as a separator).

This class assumes that any validation on names (e.g. that they contain only one colon) has already been done.


Field Summary
static char SEPARATOR
           
 
Constructor Summary
Name()
          Default constructor for internal use only
Name(java.lang.String name)
          Construct a name with no namespace part.
Name(java.lang.String displayName, ElementInfo nsbase, boolean useDefault)
          Construct a name from its display form, given an ElementInfo that provides the context in which to look up any prefix.
Name(java.lang.String prefix, java.lang.String uri, java.lang.String localName)
          Construct a name given a prefix, a uri, and a localName.
 
Method Summary
 boolean equals(Name other)
          Test whether two names are equal.
 java.lang.String getAbsoluteName()
          Get a representation of the absolute name.
 double getDefaultPriority()
          Get the default priority when this Name is used on its own as a pattern
 java.lang.String getDisplayName()
          Get the name in display format.
 short getHashCode()
          Get a hash code for this name.
 java.lang.String getLocalName()
          Get the local part of the name (the name after any ":").
static java.lang.String getLocalPartOfAbsoluteName(java.lang.String absName)
          Extract the local part from an absolute name
 java.lang.String getPrefix()
          Get the prefix of the name, the part before the ":" as used in the original XML
 java.lang.String getURI()
          Get the URI of the namespace to which the name belongs.
static java.lang.String getURIPartOfAbsoluteName(java.lang.String absName)
          Extract the URI part of an absolute name
 boolean isNameOf(NodeInfo node)
          Determine whether this name matches a given node.
static boolean isNCName(java.lang.String name)
          Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces
static boolean isQName(java.lang.String name)
          Validate whether a given string constitutes a valid QName, as defined in XML Namespaces
static Name reconstruct(java.lang.String prefix, java.lang.String uri, java.lang.String localName)
          Reconstruct a name given a prefix, a uri, and a localName.
 java.lang.String toString()
          Convert name to a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

public static final char SEPARATOR
Constructor Detail

Name

public Name()
Default constructor for internal use only

Name

public Name(java.lang.String prefix,
            java.lang.String uri,
            java.lang.String localName)
     throws org.xml.sax.SAXException
Construct a name given a prefix, a uri, and a localName. The prefix and/or the uri may be empty strings: they should not be null.
Parameters:
prefix - The name prefix, as written in source XML, the part before the colon. If there is no prefix, supply the empty string ""
uri - The URI identifying the namespace corresponding to the prefix. If the name is in the default namespace and the default namespace is unnamed, supply the empty string ""
localName - The part of the name after the colon, or the entire name if there is no colon.

Name

public Name(java.lang.String displayName,
            ElementInfo nsbase,
            boolean useDefault)
     throws org.xml.sax.SAXException
Construct a name from its display form, given an ElementInfo that provides the context in which to look up any prefix.
Parameters:
displayName - The name as it appears in source XML, that is (prefix ':')? localName
nsbase - The ElementInfo defining the context for namespace lookup
useDefault - True if the default namespace URI should be used when there is no prefix; false otherwise
Throws:
org.xml.sax.SAXException - if the name is malformed or if the prefix is undeclared.

Name

public Name(java.lang.String name)
Construct a name with no namespace part. This is used primarily for the names of Processing Instructions, which are not namespace-sensitive
Method Detail

reconstruct

public static Name reconstruct(java.lang.String prefix,
                               java.lang.String uri,
                               java.lang.String localName)
Reconstruct a name given a prefix, a uri, and a localName. The prefix and/or the uri may be empty strings: they should not be null. This method should only be used when the names have already been validated: otherwise use the similar constructor.
Parameters:
prefix - The name prefix, as written in source XML, the part before the colon. If there is no prefix, supply the empty string ""
uri - The URI identifying the namespace corresponding to the prefix. If the name is in the default namespace and the default namespace is unnamed, supply the empty string ""
localName - The part of the name after the colon, or the entire name if there is no colon.

getPrefix

public final java.lang.String getPrefix()
Get the prefix of the name, the part before the ":" as used in the original XML
Returns:
the prefix, or "" if there was no prefix. The returned string will always be interned.

getURI

public final java.lang.String getURI()
Get the URI of the namespace to which the name belongs.
Returns:
The URI of the namespace, or "" if the name is in the default. The returned string will always be interned.

getLocalName

public final java.lang.String getLocalName()
Get the local part of the name (the name after any ":").
Returns:
The part of the name after the ":", if there is one; else the full name. The returned string will always be interned.

getDisplayName

public final java.lang.String getDisplayName()
Get the name in display format. This is in the form "[prefix:]localname"
Returns:
The name including the display form of the namespace prefix if there is one. The returned string will always be interned.

getAbsoluteName

public final java.lang.String getAbsoluteName()
Get a representation of the absolute name. This is in the form "[URI^]localname", where the URI and the circumflex are absent if the name is in the default namespace.
Returns:
The absolute name including the URI of the namespace (if there is one) followed by the localname, using a cicumflex as separator. The returned string will always be interned.

getHashCode

public short getHashCode()
Get a hash code for this name. We use characters from the end of the absolute name because the start (the URI) is likely to be the same for many names.

toString

public final java.lang.String toString()
Convert name to a String.
Overrides:
toString in class java.lang.Object
Returns:
the display version of the name

equals

public final boolean equals(Name other)
Test whether two names are equal. According to the XPath rules, they are equal if they have the same local part and the same URI

getLocalPartOfAbsoluteName

public static java.lang.String getLocalPartOfAbsoluteName(java.lang.String absName)
Extract the local part from an absolute name

getURIPartOfAbsoluteName

public static java.lang.String getURIPartOfAbsoluteName(java.lang.String absName)
Extract the URI part of an absolute name

isNCName

public static boolean isNCName(java.lang.String name)
Validate whether a given string constitutes a valid NCName, as defined in XML Namespaces

isQName

public static boolean isQName(java.lang.String name)
Validate whether a given string constitutes a valid QName, as defined in XML Namespaces

isNameOf

public final boolean isNameOf(NodeInfo node)
                       throws org.xml.sax.SAXException
Determine whether this name matches a given node. This method is provided to satisfy the NameTest interface
Specified by:
isNameOf in interface NameTest
Parameters:
node - The node to be tested
Returns:
true if and only if this name is equal to the name of the given node

getDefaultPriority

public double getDefaultPriority()
Get the default priority when this Name is used on its own as a pattern
Specified by:
getDefaultPriority in interface NameTest
Returns:
0.0 (always)