public final class NamePool extends Object
Each expanded name is allocated a unique integer namecode. The namecode enables all three parts of the expanded name to be determined, that is, the prefix, the URI, and the local name.
The equivalence between names depends only on the URI and the local name. The namecode is designed so that if two namecodes represent names with the same URI and local name, the two namecodes are the same in the bottom 20 bits. It is therefore possible to compare two names for equivalence by performing an integer comparison of these 20 bits. The bottom 20 bits of a namecode are referred to as a fingerprint.
The NamePool eliminates duplicate names if they have the same prefix, uri, and local part. It retains duplicates if they have different prefixes
The NamePool has been redesigned in Saxon 9.7 to make use of two Java ConcurrentHashMaps, one from QNames to integers, one from integers to QNames. This gives better scaleability in terms of multithreaded concurrency and in terms of the capacity of the NamePool and retention of performance as the size of the vocabulary increases.
Fingerprints in the range 0 to 1023 are reserved for system use, and are allocated as constants
mainly to names in the XSLT and XML Schema namespaces: constants representing these names
are found in StandardNames
.
A nameCode contains the fingerprint in the bottom 20 bits. It also contains a 10-bit prefix index. This distinguishes the prefix used, among all the prefixes that have been used with this namespace URI. If the prefix index is zero, the prefix is null. Otherwise, it indexes an array of prefix Strings associated with the namespace URI. Note that the data structures and algorithms are optimized for the case where URIs usually use the same prefix.
The nameCode -1 is reserved to mean "not known" or inapplicable. The fingerprint -1 has the same meaning. Note that masking the nameCode -1 to extract its bottom 20 bits is incorrect, and will lead to errors.
Modified in 9.4 to remove namespace codes.
Modified in 9.7 to remove URI codes.
Modifier and Type | Class and Description |
---|---|
static class |
NamePool.NamePoolLimitException
Unchecked Exception raised when some limit in the design of the name pool is exceeded
|
Modifier and Type | Field and Description |
---|---|
static int |
FP_MASK
FP_MASK is a mask used to obtain a fingerprint from a nameCode.
|
static int |
USER_DEFINED_MASK |
Constructor and Description |
---|
NamePool()
Create a NamePool
|
Modifier and Type | Method and Description |
---|---|
int |
allocate(String prefix,
String uri,
String localName)
Allocate a name code from the pool, or return an existing one if it already exists
|
int |
allocateClarkName(String expandedName)
Allocate a fingerprint given a Clark Name
|
String |
getClarkName(int nameCode)
Get the Clark form of a name, given its name code or fingerprint
|
String |
getDisplayName(int nameCode)
Get the display form of a name (the QName), given its name code or fingerprint
|
String |
getEQName(int nameCode)
Get the EQName form of a name, given its name code or fingerprint
|
int |
getFingerprint(String uri,
String localName)
Get a fingerprint for the name with a given uri and local name.
|
String |
getLocalName(int nameCode)
Get the local part of a name, given its name code or fingerprint
|
NamespaceBinding |
getNamespaceBinding(int nameCode)
Get a namespace binding for a given namecode.
|
String |
getPrefix(int nameCode)
Get the prefix part of a name, given its name code
|
StructuredQName |
getStructuredQName(int nameCode)
Get a QName for a given namecode.
|
StructuredQName |
getUnprefixedQName(int nameCode)
Get a QName for a given namecode.
|
String |
getURI(int nameCode)
Get the namespace-URI of a name, given its name code or fingerprint
|
static boolean |
isPrefixed(int nameCode)
Determine whether a given namecode has a non-empty prefix (and therefore, in the case of attributes,
whether the name is in a non-null namespace
|
String |
suggestPrefixForURI(String uri)
Suggest a prefix for a given URI.
|
public static final int FP_MASK
nc & NamePool.FP_MASK
.
(In practice, Saxon code often uses the literal constant 0xfffff,
to extract the bottom 20 bits).
The difference between a fingerprint and a nameCode is that a nameCode contains information about the prefix of a name, the fingerprint depends only on the namespace URI and local name. Note that the "null" nameCode (-1) does not produce the "null" fingerprint (also -1) when this mask is applied.
public static final int USER_DEFINED_MASK
public NamespaceBinding getNamespaceBinding(int nameCode)
nameCode
- a code identifying an expanded QName, e.g. of an element or attributepublic StructuredQName getUnprefixedQName(int nameCode)
nameCode
- a code identifying an expanded QName, e.g. of an element or attributepublic StructuredQName getStructuredQName(int nameCode)
nameCode
- a code identifying an expanded QName, e.g. of an element or attributepublic static boolean isPrefixed(int nameCode)
nameCode
- the name code to be testedpublic String suggestPrefixForURI(String uri)
uri
- the namespace URIpublic int allocate(String prefix, String uri, String localName)
prefix
- the namespace prefix. Use "" for the null prefix, representing the absent namespaceuri
- the namespace URI. Use "" or null for the non-namespace.localName
- the local part of the namepublic String getURI(int nameCode)
nameCode
- the name code or fingerprint of a nameIllegalArgumentException
- if the nameCode is not known to the NamePool.public String getLocalName(int nameCode)
nameCode
- the integer name code or fingerprint of the namepublic String getPrefix(int nameCode)
nameCode
- the integer name code of a name in the name poolpublic String getDisplayName(int nameCode)
nameCode
- the integer name code or fingerprint of a name in the name poolpublic String getClarkName(int nameCode)
nameCode
- the integer name code or fingerprint of a name in the name poolpublic String getEQName(int nameCode)
nameCode
- the integer name code or fingerprint of a name in the name poolpublic int allocateClarkName(String expandedName)
expandedName
- the name in Clark notation, that is "localname" or "{uri}localName"public int getFingerprint(String uri, String localName)
uri
- the namespace URI of the required QNamelocalName
- the local part of the required QNameCopyright (c) 2004-2014 Saxonica Limited. All rights reserved.