Package net.sf.saxon.om
Class NamePool
- java.lang.Object
-
- net.sf.saxon.om.NamePool
-
- All Implemented Interfaces:
java.io.Serializable
public class NamePool extends java.lang.Object implements java.io.Serializable
An object representing a collection of XML 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.
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.
The NamePool eliminates duplicate names if they have the same prefix, uri, and local part. It retains duplicates if they have different prefixes
- Author:
- Michael H. Kay
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NamePool.NamePoolLimitException
-
Field Summary
Fields Modifier and Type Field Description static int
FP_MASK
FP_MASK is a mask used to obtain a fingerprint from a nameCode.(package private) net.sf.saxon.om.NamePool.NameEntry[]
hashslots
static int
MAX_PREFIXES_PER_URI
(package private) java.lang.String[]
prefixes
(package private) java.lang.String[][]
prefixesForUri
(package private) short
prefixesUsed
(package private) java.lang.String[]
uris
(package private) short
urisUsed
static int
USER_DEFINED_MASK
-
Constructor Summary
Constructors Constructor Description NamePool()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
allocate(java.lang.String prefix, short uriCode, java.lang.String localName)
Allocate a name from the pool, or a new Name if there is not a matching one thereint
allocate(java.lang.String prefix, java.lang.String uri, java.lang.String localName)
Allocate a name from the pool, or a new Name if there is not a matching one thereint
allocateClarkName(java.lang.String expandedName)
Allocate a fingerprint given a Clark Nameshort
allocateCodeForURI(java.lang.String uri)
Allocate the uri code for a given URI; create one if not foundint
allocateLexicalQName(java.lang.CharSequence qname, boolean useDefault, NamespaceResolver resolver, NameChecker checker)
Get the nameCode for a lexical QName, given a namespace resolver.int
allocateNamespaceCode(int namecode)
Allocate a namespace code for the prefix/URI of a given namecodeint
allocateNamespaceCode(java.lang.String prefix, java.lang.String uri)
Allocate the namespace code for a namespace prefix/URI pair.void
diagnosticDump()
Diagnostic print of the namepool contents.java.lang.String
getClarkName(int nameCode)
Get the Clark form of a name, given its name code or fingerprintjava.lang.Object
getClientData(java.lang.Class key)
Retrieve client data on behalf of a user of the namepoolshort
getCodeForPrefix(java.lang.String prefix)
Get the prefix code for a given Prefixshort
getCodeForURI(java.lang.String uri)
Get the uri code for a given URIstatic NamePool
getDefaultNamePool()
Get the singular default NamePooljava.lang.String
getDisplayName(int nameCode)
Get the display form of a name (the QName), given its name code or fingerprintint
getFingerprint(java.lang.String uri, java.lang.String localName)
Get a fingerprint for the name with a given uri and local name.int
getFingerprintForExpandedName(java.lang.String expandedName)
Get fingerprint for expanded name in {uri}local formatjava.lang.String
getLocalName(int nameCode)
Get the local part of a name, given its name code or fingerprintint
getNamespaceCode(int namecode)
Allocate a namespace code for a given namecodeint
getNamespaceCode(java.lang.String prefix, java.lang.String uri)
Get the existing namespace code for a namespace prefix/URI pair.java.lang.String
getPrefix(int nameCode)
Get the prefix part of a name, given its name code or fingerprintjava.lang.String
getPrefixFromNamespaceCode(int code)
Get the namespace prefix from a namespace code.static int
getPrefixIndex(int nameCode)
Get the prefix index from a namecodejava.lang.String
getPrefixWithIndex(short uriCode, int index)
Get a prefix among all the prefixes used with a given URI, given its indexjava.lang.String
getURI(int nameCode)
Get the namespace-URI of a name, given its name code or fingerprintshort
getURICode(int nameCode)
Get the URI code of a name, given its name code or fingerprintjava.lang.String
getURIFromNamespaceCode(int code)
Get the namespace URI from a namespace code.java.lang.String
getURIFromURICode(short code)
Get the namespace URI from a URI code.static java.lang.String[]
parseClarkName(java.lang.String expandedName)
Parse a Clark-format expanded name, returning the URI and local namevoid
setClientData(java.lang.Class key, java.lang.Object value)
Save client data on behalf of a user of the namepoolstatic void
setDefaultNamePool(NamePool pool)
Set the default NamePool (used after loading a compiled stylesheet)void
statistics()
Statistics summarizing the namepool contents.java.lang.String
suggestPrefixForURI(java.lang.String URI)
Suggest a prefix for a given URI.
-
-
-
Field Detail
-
FP_MASK
public static final int FP_MASK
FP_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.) The difference between 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:
- Constant Field Values
-
USER_DEFINED_MASK
public static final int USER_DEFINED_MASK
- See Also:
- Constant Field Values
-
MAX_PREFIXES_PER_URI
public static final int MAX_PREFIXES_PER_URI
- See Also:
- Constant Field Values
-
hashslots
net.sf.saxon.om.NamePool.NameEntry[] hashslots
-
prefixes
java.lang.String[] prefixes
-
prefixesUsed
short prefixesUsed
-
uris
java.lang.String[] uris
-
prefixesForUri
java.lang.String[][] prefixesForUri
-
urisUsed
short urisUsed
-
-
Method Detail
-
getDefaultNamePool
public static NamePool getDefaultNamePool()
Get the singular default NamePool
-
setDefaultNamePool
public static void setDefaultNamePool(NamePool pool)
Set the default NamePool (used after loading a compiled stylesheet)
-
allocateNamespaceCode
public int allocateNamespaceCode(java.lang.String prefix, java.lang.String uri)
Allocate the namespace code for a namespace prefix/URI pair. Create it if not already present- Parameters:
prefix
- the namespace prefixuri
- the namespace URI- Returns:
- an integer code identifying the namespace. The namespace code identifies both the prefix and the URI.
-
getNamespaceCode
public int getNamespaceCode(java.lang.String prefix, java.lang.String uri)
Get the existing namespace code for a namespace prefix/URI pair.- Returns:
- -1 if there is none present
-
getNamespaceCode
public int getNamespaceCode(int namecode)
Allocate a namespace code for a given namecode- Parameters:
namecode
- a code identifying an expanded QName, e.g. of an element or attribute- Returns:
- a code identifying the namespace used in the given name. The namespace code identifies both the prefix and the URI. Return -1 if no namespace code has been allocated (in this case the caller should call allocateNamespaceCode() to get one).
-
getPrefixIndex
public static int getPrefixIndex(int nameCode)
Get the prefix index from a namecode- Parameters:
nameCode
- the name code- Returns:
- the prefix index. A value of zero means the name is unprefixed (which in the case of an attribute, means that it is in the null namespace)
-
allocateCodeForURI
public short allocateCodeForURI(java.lang.String uri)
Allocate the uri code for a given URI; create one if not found
-
getCodeForURI
public short getCodeForURI(java.lang.String uri)
Get the uri code for a given URI- Returns:
- -1 if not present in the name pool
-
getCodeForPrefix
public short getCodeForPrefix(java.lang.String prefix)
Get the prefix code for a given Prefix- Returns:
- -1 if not found
-
suggestPrefixForURI
public java.lang.String suggestPrefixForURI(java.lang.String URI)
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.
-
getPrefixWithIndex
public java.lang.String getPrefixWithIndex(short uriCode, int index)
Get a prefix among all the prefixes used with a given URI, given its index- Returns:
- the prefix with the given index. If the index is 0, the prefix is always "".
-
allocate
public int allocate(java.lang.String prefix, java.lang.String uri, java.lang.String localName)
Allocate a name from the pool, or a new Name if there is not a matching one there- Parameters:
prefix
-uri
- - the namespace URI. The null URI is represented as an empty string.localName
-- Returns:
- an integer (the "namecode") identifying the name within the namepool. The Name itself may be retrieved using the getName(int) method
-
allocate
public int allocate(java.lang.String prefix, short uriCode, java.lang.String localName)
Allocate a name from the pool, or a new Name if there is not a matching one there- Parameters:
prefix
- - the namespace prefixuriCode
- - the code of the URIlocalName
- - the local part of the QName- Returns:
- an integer (the "namecode") identifying the name within the namepool.
-
allocateNamespaceCode
public int allocateNamespaceCode(int namecode)
Allocate a namespace code for the prefix/URI of a given namecode- Parameters:
namecode
- a code identifying an expanded QName, e.g. of an element or attribute- Returns:
- a code identifying the namespace used in the given name. The namespace code identifies both the prefix and the URI.
-
getURI
public java.lang.String getURI(int nameCode)
Get the namespace-URI of a name, given its name code or fingerprint- Returns:
- the namespace URI corresponding to this name code. Returns "" for the null namespace.
- Throws:
java.lang.IllegalArgumentException
- if the nameCode is not known to the NamePool.
-
getURICode
public short getURICode(int nameCode)
Get the URI code of a name, given its name code or fingerprint
-
getLocalName
public java.lang.String getLocalName(int nameCode)
Get the local part of a name, given its name code or fingerprint
-
getPrefix
public java.lang.String getPrefix(int nameCode)
Get the prefix part of a name, given its name code or fingerprint
-
getDisplayName
public java.lang.String getDisplayName(int nameCode)
Get the display form of a name (the QName), given its name code or fingerprint
-
getClarkName
public java.lang.String getClarkName(int nameCode)
Get the Clark form of a name, given its name code or fingerprint- Returns:
- the local name if the name is in the null namespace, or "{uri}local" otherwise. The name is always interned.
-
allocateClarkName
public int allocateClarkName(java.lang.String expandedName)
Allocate a fingerprint given a Clark Name
-
parseClarkName
public static java.lang.String[] parseClarkName(java.lang.String expandedName)
Parse a Clark-format expanded name, returning the URI and local name
-
getFingerprint
public int getFingerprint(java.lang.String uri, java.lang.String localName)
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).- Returns:
- -1 if not found
-
getURIFromNamespaceCode
public java.lang.String getURIFromNamespaceCode(int code)
Get the namespace URI from a namespace code.
-
getURIFromURICode
public java.lang.String getURIFromURICode(short code)
Get the namespace URI from a URI code.
-
getPrefixFromNamespaceCode
public java.lang.String getPrefixFromNamespaceCode(int code)
Get the namespace prefix from a namespace code.
-
allocateLexicalQName
public int allocateLexicalQName(java.lang.CharSequence qname, boolean useDefault, NamespaceResolver resolver, NameChecker checker) throws DynamicError
Get the nameCode for a lexical QName, given a namespace resolver.- Parameters:
qname
- the lexical QName.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.checker
- NameChecker used to check names against the XML 1.0 or 1.1 specification- Returns:
- the corresponding nameCode
- Throws:
DynamicError
- if the string is not a valid lexical QName or if the namespace prefix has not been declared*
-
getFingerprintForExpandedName
public int getFingerprintForExpandedName(java.lang.String expandedName)
Get fingerprint for expanded name in {uri}local format
-
setClientData
public void setClientData(java.lang.Class key, java.lang.Object value)
Save client data on behalf of a user of the namepool
-
getClientData
public java.lang.Object getClientData(java.lang.Class key)
Retrieve client data on behalf of a user of the namepool
-
diagnosticDump
public void diagnosticDump()
Diagnostic print of the namepool contents.
-
statistics
public void statistics()
Statistics summarizing the namepool contents. This method outputs summary statistical information to System.err
-
-