Class NamePool
Each expanded name is allocated a unique 20-bit fingerprint. The fingerprint enables the URI and the local name to be determined. Some subsystems (notably the Tinytree) use the top 10 bits to represent the prefix, but the NamePool is no longer concerned with managing prefixes, and prefixes do not have global codes.
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
.
The fingerprint -1 is reserved to mean "not known" or inapplicable.
Modified in 9.4 to remove namespace codes.
Modified in 9.7 to remove URI codes.
Modified in 9.8 to remove namecodes and all handling of prefixes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Unchecked Exception raised when some limit in the design of the name pool is exceeded -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
FP_MASK is a mask used to obtain a fingerprint from a nameCode.static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
allocateClarkName
(String expandedName) Allocate a fingerprint given a Clark Nameint
allocateFingerprint
(NamespaceUri uri, String local) Allocate a fingerprint from the pool, or a new Name if there is not a matching one theregetClarkName
(int nameCode) Get the Clark form of a name, given its name code or fingerprintgetDisplayName
(int nameCode) Get the display form of a name (the QName), given its name code or fingerprintgetEQName
(int nameCode) Get the EQName form of a name, given its name code or fingerprintint
getFingerprint
(NamespaceUri uri, String localName) Get a fingerprint for the name with a given uri and local name.getLocalName
(int nameCode) Get the local part of a name, given its name code or fingerprintgetStructuredQName
(int fingerprint) Get a QName for a given fingerprint.getUnprefixedQName
(int nameCode) Get a QName for a given namecode.getURI
(int nameCode) Get the namespace-URI of a name, given its name code or fingerprintstatic 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 namespacevoid
suggestPrefix
(String prefix, NamespaceUri uri) Suggest a preferred prefix to be used with a given URISuggest a prefix for a given URI.
-
Field Details
-
FP_MASK
public static final int FP_MASKFP_MASK is a mask used to obtain a fingerprint from a nameCode. Given a nameCode nc, the fingerprint isnc & 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.
- See Also:
-
USER_DEFINED_MASK
public static final int USER_DEFINED_MASK- See Also:
-
-
Constructor Details
-
NamePool
public NamePool()Create a NamePool
-
-
Method Details
-
suggestPrefix
Suggest a preferred prefix to be used with a given URI- Parameters:
prefix
- the suggested prefixuri
- the URI
-
getUnprefixedQName
Get a QName for a given namecode.- Parameters:
nameCode
- a code identifying an expanded QName, e.g. of an element or attribute- Returns:
- a qName containing the URI and local name corresponding to the supplied name code. The prefix will be set to an empty string.
-
getStructuredQName
Get a QName for a given fingerprint.- Parameters:
fingerprint
- a code identifying an expanded QName, e.g. of an element or attribute- Returns:
- a qName containing the URI and local name corresponding to the supplied fingerprint. There will be no prefix
-
isPrefixed
public 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- Parameters:
nameCode
- the name code to be tested- Returns:
- true if the name has a non-empty prefix
-
suggestPrefixForURI
Suggest a prefix for a given URI. If there are several, it's undefined which one is returned. If there are no prefixes registered for this URI, return null.- Parameters:
uri
- the namespace URI- Returns:
- a prefix that has previously been associated with this URI, if available; otherwise null
-
allocateFingerprint
Allocate a fingerprint from the pool, or a new Name if there is not a matching one there- Parameters:
uri
- the namespace URI. Use "" or null for the non-namespace.local
- the local part of the name- Returns:
- an integer (the "fingerprint") identifying the name within the namepool. The fingerprint omits information about the prefix, and is the same as the nameCode for the same name with a prefix equal to "".
-
getURI
Get the namespace-URI of a name, given its name code or fingerprint- Parameters:
nameCode
- the name code or fingerprint of a name- Returns:
- the namespace URI corresponding to this name code. Returns "" for the no-namespace.
- Throws:
IllegalArgumentException
- if the nameCode is not known to the NamePool.
-
getLocalName
Get the local part of a name, given its name code or fingerprint- Parameters:
nameCode
- the integer name code or fingerprint of the name- Returns:
- the local part of the name represented by this name code or fingerprint
-
getDisplayName
Get the display form of a name (the QName), given its name code or fingerprint- Parameters:
nameCode
- the integer name code or fingerprint of a name in the name pool- Returns:
- the corresponding lexical QName (if a fingerprint was supplied, this will simply be the local name)
-
getClarkName
Get the Clark form of a name, given its name code or fingerprint- Parameters:
nameCode
- the integer name code or fingerprint of a name in the name pool- Returns:
- the local name if the name is in the null namespace, or "{uri}local" otherwise. The name is always interned.
-
getEQName
Get the EQName form of a name, given its name code or fingerprint- Parameters:
nameCode
- the integer name code or fingerprint of a name in the name pool- Returns:
- the name in the form Q{}local for a name in no namespace, or Q{uri}local for a name in a namespace
-
allocateClarkName
Allocate a fingerprint given a Clark Name- Parameters:
expandedName
- the name in Clark notation, that is "localname" or "{uri}localName"- Returns:
- the fingerprint of the name, which need not previously exist in the name pool
-
getFingerprint
Get a fingerprint for the name with a given uri and local name. These must be present in the NamePool. The fingerprint has the property that if two fingerprint are the same, the names are the same (ie. same local name and same URI).- Parameters:
uri
- the namespace URI of the required QNamelocalName
- the local part of the required QName- Returns:
- the integer fingerprint, or -1 if this is not found in the name pool
-