|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.saxon.om.NamePool
public class NamePool
A NamePool holds a collection of expanded names, each containing a namespace URI, a namespace prefix, and a local name; plus a collection of namespaces, each consisting of a prefix/URI pair.
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 betweem 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
Internally the NamePool is organized as a fixed number of hash chains. The selection of a hash chain is based on hashing the local name, because it is unusual to have many names that share the same local name but use different URIs. There are 1024 hash chains and the identifier of the hash chain forms the bottom ten bits of the namecode. The next ten bits represent the sequential position of an entry within the hash chain. The upper bits represent the selection of prefix, from among the list of prefixes that have been used with a given URI. A prefix part of zero means no prefix; if the two prefixes used with a particular namespace are "xs" and "xsd", say, then these will be prefix codes 1 and 2.
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
.
Operations that update the NamePool, or that have the potential to update it, are synchronized. Read-only operations are done without synchronization. Although technically unsafe, this has not led to any problems in practice. Performance problems due to excessive contention on the NamePool have occasionally been observed: if this happens, the best strategy is to consider splitting the workload to use multiple Configurations each with a separate NamePool.
The NamePool holds two kinds of entry: name entries, representing expanded names (local name + prefix + URI), identified by a name code, and namespace entries (prefix + URI) identified by a namespace code.
The data structure of the name table is as follows.
There is a fixed size hash table; names are allocated to slots in this table by hashing on the local name. Each entry in the table is the head of a chain of NameEntry objects representing names that have the same hash code.
Each NameEntry represents a distinct name (same URI and local name). It contains the local name as a string, plus a short integer representing the URI (as an offset into the array uris[] - this is known as the URIcode).
The fingerprint of a name consists of the hash slot number (in the bottom 10 bits) concatenated with the depth of the entry down the chain of hash synonyms (in the next 10 bits). Fingerprints with depth 0 (i.e., in the range 0-1023) are reserved for predefined names (names of XSLT elements and attributes, and of built-in types). These names are not stored in the name pool, but are accessible as if they were.
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.
Nested Class Summary | |
---|---|
static class |
NamePool.NamePoolLimitException
Uncaught Exception raised when some limit in the design of the name pool is exceeded |
Field Summary | |
---|---|
static int |
FP_MASK
FP_MASK is a mask used to obtain a fingerprint from a nameCode. |
static int |
MAX_PREFIXES_PER_URI
|
static int |
USER_DEFINED_MASK
|
Constructor Summary | |
---|---|
NamePool()
Create a NamePool |
Method Summary | |
---|---|
int |
allocate(String prefix,
String uri,
String localName)
Allocate a name from the pool, or a new Name if there is not a matching one there |
int |
allocateClarkName(String expandedName)
Allocate a fingerprint given a Clark Name |
short |
allocateCodeForURI(String uri)
Allocate the uri code for a given URI; create one if not found |
int |
allocateLexicalQName(CharSequence qname,
boolean useDefault,
NamespaceResolver resolver,
NameChecker checker)
Get the nameCode for a lexical QName, given a namespace resolver. |
int |
allocateNamespaceCode(String prefix,
String uri)
Allocate the namespace code for a namespace prefix/URI pair. |
void |
diagnosticDump()
Diagnostic print of the namepool contents. |
String |
getClarkName(int nameCode)
Get the Clark form of a name, given its name code or fingerprint |
Object |
getClientData(Class key)
Retrieve client data on behalf of a user of the namepool |
short |
getCodeForPrefix(String prefix)
Get the prefix code for a given Prefix |
short |
getCodeForURI(String uri)
Get the uri code for a given URI |
String |
getDisplayName(int nameCode)
Get the display form of a name (the QName), 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 |
int |
getNamespaceCode(int namecode)
Get the namespace code allocated to a given namecode. |
int |
getNamespaceCode(String prefix,
String uri)
Get the existing namespace code for a namespace prefix/URI pair. |
String |
getPrefix(int nameCode)
Get the prefix part of a name, given its name code |
String |
getPrefixFromNamespaceCode(int code)
Get the namespace prefix from a namespace code. |
static int |
getPrefixIndex(int nameCode)
Get the prefix index from a namecode |
String |
getURI(int nameCode)
Get the namespace-URI of a name, given its name code or fingerprint |
short |
getURICode(int nameCode)
Get the URI code of a name, given its name code or fingerprint |
String |
getURIFromNamespaceCode(int code)
Get the namespace URI from a namespace code. |
String |
getURIFromURICode(short code)
Get the namespace URI from a URI code. |
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 |
static String[] |
parseClarkName(String expandedName)
Parse a Clark-format expanded name, returning the URI and local name |
void |
setClientData(Class key,
Object value)
Save client data on behalf of a user of the namepool |
void |
statistics()
Statistics summarizing the namepool contents. |
String |
suggestPrefixForURI(String URI)
Suggest a prefix for a given URI. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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 static final int MAX_PREFIXES_PER_URI
Constructor Detail |
---|
public NamePool()
Method Detail |
---|
public int allocateNamespaceCode(String prefix, String uri)
prefix
- the namespace prefixuri
- the namespace URI
public int getNamespaceCode(String prefix, String uri)
prefix
- the namespace prefix. May be "" for the default namespaceuri
- the namespace URI. May be "" for the "null namespace"
public int getNamespaceCode(int namecode)
namecode
- a code identifying an expanded QName, e.g. of an element or attribute
Return -1 if no namespace code has been allocated. This should not happen for a legitimate namecode, since a namespace code is always allocated at the time the namecode is created.
public static int getPrefixIndex(int nameCode)
nameCode
- the name code
public static boolean isPrefixed(int nameCode)
nameCode
- the name code to be tested
public short allocateCodeForURI(String uri)
uri
- The namespace URI. Supply "" or null for the "null namespace"
public short getCodeForURI(String uri)
uri
- the URI whose code is required
public short getCodeForPrefix(String prefix)
prefix
- the prefix. Supply "" for the null prefix representing the default namespace.
public String suggestPrefixForURI(String URI)
URI
- the namespace URI
public 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 name
public String getURI(int nameCode)
nameCode
- the name code or fingerprint of a name
IllegalArgumentException
- if the nameCode is not known to the NamePool.public short getURICode(int nameCode)
nameCode
- the name code or fingerprint of a name in the name pool
public String getLocalName(int nameCode)
nameCode
- the integer name code or fingerprint of the name
public String getPrefix(int nameCode)
nameCode
- the integer name code of a name in the name pool
public String getDisplayName(int nameCode)
nameCode
- the integer name code or fingerprint of a name in the name pool
public String getClarkName(int nameCode)
nameCode
- the integer name code or fingerprint of a name in the name pool
public int allocateClarkName(String expandedName)
expandedName
- the name in Clark notation, that is "localname" or "{uri}localName"
public static String[] parseClarkName(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 QName
public String getURIFromNamespaceCode(int code)
code
- a namespace code, representing the binding of a prefix to a namespace URI
public String getURIFromURICode(short code)
code
- a code that identifies the URI within the name pool
public String getPrefixFromNamespaceCode(int code)
code
- a namespace code representing the binding of a prefix to a URI)
public int allocateLexicalQName(CharSequence qname, boolean useDefault, NamespaceResolver resolver, NameChecker checker) throws XPathException
qname
- the lexical QName (with leading and trailing whitespace allowed).useDefault
- if true, an absent prefix is resolved by the NamespaceResolver
to the namespace URI assigned to the prefix "". If false, an absent prefix is
interpreted as meaning the name is in no namespace.resolver
- NamespaceResolver used to resolve the namespace prefix to a namespace URIchecker
- NameChecker used to check names against the XML 1.0 or 1.1 specification
XPathException
- if the string is not a valid lexical QName or
if the namespace prefix has not been declaredpublic void setClientData(Class key, Object value)
key
- the class that is maintaining private data in the name poolvalue
- the private data maintained in the name pool on behalf of this classpublic Object getClientData(Class key)
key
- the class that is maintaining private data in the name pool
public void diagnosticDump()
public void statistics()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |