net.sf.saxon.om
Class NamePool

java.lang.Object
  extended by net.sf.saxon.om.NamePool
All Implemented Interfaces:
Serializable

public class NamePool
extends Object
implements 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:
Serialized Form

Nested Class Summary
 class NamePool.NamePoolLimitException
          The following code is used to create a list of Java declarations for the fingerprints of standard names used in a stylesheet.
 
Field Summary
(package private)  net.sf.saxon.om.NamePool.NameEntry[] hashslots
           
(package private)  String[] prefixes
           
(package private)  String[] prefixesForUri
           
(package private)  short prefixesUsed
           
(package private)  String[] uris
           
(package private)  short urisUsed
           
 
Constructor Summary
NamePool()
           
 
Method Summary
 void addAttributeDeclaration(int fingerprint, SchemaComponentMarker attribute)
          Add an attribute declaration to the name pool This method is used only in the schema-aware product.
 void addElementDeclaration(int fingerprint, SchemaComponentMarker element)
          Add an element declaration to the name pool This method is used only in the schema-aware product.
 void addSchemaType(int fingerprint, SchemaType type)
          Add a SchemaType to the name pool
 int allocate(String prefix, short uriCode, String localName)
          Allocate a name from the pool, or a new Name if there is not a matching one there
 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 allocateCodeForPrefix(String prefix)
          Allocate the prefix code for a given Prefix; create one if not found
 short allocateCodeForURI(String uri)
          Allocate the uri code for a given URI; create one if not found
 int allocateDocumentNumber(DocumentInfo doc)
          Add a document to the pool, and allocate a document number
 int allocateNamespaceCode(int namecode)
          Allocate a namespace code for the prefix/URI of a given namecode
 int allocateNamespaceCode(String prefix, String uri)
          Allocate the namespace code for a namespace prefix/URI pair.
 void diagnosticDump()
          Diagnostic print of the namepool contents.
 SchemaComponentMarker getAttributeDeclaration(int fingerprint)
          Get a global attribute declaration
 String getClarkName(int nameCode)
          Get the Clark form of a name, given its name code or fingerprint
 short getCodeForPrefix(String prefix)
          Get the prefix code for a given Prefix
 short getCodeForURI(String uri)
          Get the uri code for a given URI
static NamePool getDefaultNamePool()
          Get the singular default NamePool
 String getDisplayName(int nameCode)
          Get the display form of a name (the QName), given its name code or fingerprint
 SchemaComponentMarker getElementDeclaration(int fingerprint)
          Get a global element declaration
 int getFingerprint(String uri, String localName)
          Get a fingerprint for the name with a given uri and local name.
 int getFingerprintForExpandedName(String expandedName)
          Get fingerprint for expanded name in {uri}local format
 String getLocalName(int nameCode)
          Get the local part of a name, given its name code or fingerprint
 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 or fingerprint
 String getPrefixFromNamespaceCode(int code)
          Get the namespace prefix from a namespace code.
 String getPrefixWithIndex(short uriCode, int index)
          Get a prefix among all the prefixes used with a given URI, given its index
 SchemaType getSchemaType(int fingerprint)
          Get the schema type with a given name.
 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.
 void removeAttributeDeclaration(int fingerprint)
          Remove an attribute declaration from the name pool.
 void removeElementDeclaration(int fingerprint)
          Remove an element declaration from the name pool.
 void removeSchemaType(int fingerprint)
          Remove a SchemaType from the name pool
static void setDefaultNamePool(NamePool pool)
          Set the default NamePool (used after loading a compiled stylesheet)
 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

hashslots

net.sf.saxon.om.NamePool.NameEntry[] hashslots

prefixes

String[] prefixes

prefixesUsed

short prefixesUsed

uris

String[] uris

prefixesForUri

String[] prefixesForUri

urisUsed

short urisUsed
Constructor Detail

NamePool

public NamePool()
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)


allocateDocumentNumber

public int allocateDocumentNumber(DocumentInfo doc)
Add a document to the pool, and allocate a document number

Parameters:
doc - The DocumentInfo for the document in question
Returns:
the document number, unique within this document pool

allocateNamespaceCode

public int allocateNamespaceCode(String prefix,
                                 String uri)
Allocate the namespace code for a namespace prefix/URI pair. Create it if not already present

Parameters:
prefix - the namespace prefix
uri - the namespace URI
Returns:
an integer code identifying the namespace. The namespace code identifies both the prefix and the URI.

getNamespaceCode

public int getNamespaceCode(String prefix,
                            String uri)
Get the existing namespace code for a namespace prefix/URI pair.

Returns:
-1 if there is none present

allocateCodeForURI

public short allocateCodeForURI(String uri)
Allocate the uri code for a given URI; create one if not found


getCodeForURI

public short getCodeForURI(String uri)
Get the uri code for a given URI

Returns:
-1 if not present in the name pool

allocateCodeForPrefix

public short allocateCodeForPrefix(String prefix)
Allocate the prefix code for a given Prefix; create one if not found

Parameters:
prefix - the namespace prefix whose code is to be allocated or returned
Returns:
the numeric code for this prefix

getCodeForPrefix

public short getCodeForPrefix(String prefix)
Get the prefix code for a given Prefix

Returns:
-1 if not found

suggestPrefixForURI

public String suggestPrefixForURI(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 String getPrefixWithIndex(short uriCode,
                                 int index)
Get a prefix among all the prefixes used with a given URI, given its index

Returns:
null if not found

allocate

public 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

Parameters:
prefix -
uri - - the namespace URI
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(String prefix,
                    short uriCode,
                    String localName)
Allocate a name from the pool, or a new Name if there is not a matching one there

Parameters:
prefix -
uriCode - - the code of the URI
localName -
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 String getURI(int nameCode)
Get the namespace-URI of a name, given its name code or fingerprint


getURICode

public short getURICode(int nameCode)
Get the URI code of a name, given its name code or fingerprint


getLocalName

public String getLocalName(int nameCode)
Get the local part of a name, given its name code or fingerprint


getPrefix

public String getPrefix(int nameCode)
Get the prefix part of a name, given its name code or fingerprint


getDisplayName

public String getDisplayName(int nameCode)
Get the display form of a name (the QName), given its name code or fingerprint


getClarkName

public 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(String expandedName)
Allocate a fingerprint given a Clark Name


getFingerprint

public int getFingerprint(String uri,
                          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 String getURIFromNamespaceCode(int code)
Get the namespace URI from a namespace code.


getURIFromURICode

public String getURIFromURICode(short code)
Get the namespace URI from a URI code.


getPrefixFromNamespaceCode

public String getPrefixFromNamespaceCode(int code)
Get the namespace prefix from a namespace code.


getFingerprintForExpandedName

public int getFingerprintForExpandedName(String expandedName)
Get fingerprint for expanded name in {uri}local format


addSchemaType

public void addSchemaType(int fingerprint,
                          SchemaType type)
Add a SchemaType to the name pool


removeSchemaType

public void removeSchemaType(int fingerprint)
Remove a SchemaType from the name pool


getSchemaType

public SchemaType getSchemaType(int fingerprint)
Get the schema type with a given name. Return null if there is no known type with this name.


addElementDeclaration

public void addElementDeclaration(int fingerprint,
                                  SchemaComponentMarker element)
Add an element declaration to the name pool This method is used only in the schema-aware product. The SchemaComponent in question must be an element declaration


removeElementDeclaration

public void removeElementDeclaration(int fingerprint)
Remove an element declaration from the name pool. Used during error recovery


getElementDeclaration

public SchemaComponentMarker getElementDeclaration(int fingerprint)
Get a global element declaration

Returns:
the element declaration whose name matches the given fingerprint, or null if no element declaration with this name has been registered.

addAttributeDeclaration

public void addAttributeDeclaration(int fingerprint,
                                    SchemaComponentMarker attribute)
Add an attribute declaration to the name pool This method is used only in the schema-aware product. The schema component in question must be an attribute declaration.


removeAttributeDeclaration

public void removeAttributeDeclaration(int fingerprint)
Remove an attribute declaration from the name pool. Used during error recovery


getAttributeDeclaration

public SchemaComponentMarker getAttributeDeclaration(int fingerprint)
Get a global attribute declaration

Returns:
the attribute declaration whose name matches the given fingerprint, or null if no attribute declaration with this name has been registered.

diagnosticDump

public void diagnosticDump()
Diagnostic print of the namepool contents.