org.cdlib.xtf.lazyTree
Class LazyKeyManager

Object
  extended by KeyManager
      extended by LazyKeyManager
All Implemented Interfaces:
Serializable

public class LazyKeyManager
extends KeyManager

LazyKeyManager wraps a Saxon KeyManager, but stores keys on disk instead of keeping them in RAM. If the same index is accessed later, it need not be recomputed.

Author:
Martin Haye
See Also:
Serialized Form

Field Summary
private  int nKeysStored
          Count of keys actually stored on disk
 
Fields inherited from class KeyManager
keyList
 
Constructor Summary
LazyKeyManager(Configuration config, KeyManager prevMgr)
          Construct and initialize the manager, grabbing existing key definitions from the previous key manager.
 
Method Summary
 Map buildIndex(int keyNameFingerprint, BuiltInAtomicType itemType, Set foundItemTypes, DocumentInfo doc, XPathContext context)
          Build the index for a particular document for a named key
private  String calcIndexName(NamePool pool, String fingerName, List definitions, Configuration config)
          Calculates a string name for a given set of xsl:key definitions.
protected  void constructIndex(DocumentInfo doc, Map index, KeyDefinition keydef, BuiltInAtomicType soughtItemType, Set foundItemTypes, XPathContext context, boolean isFirst)
          Optimized to use node test directly when possible, for speed.
 int createAllKeys(LazyDocument doc, XPathContext context)
          Called after creation of a lazy tree during the index process.
static LazyDocument getDocumentImpl(DocumentInfo doc)
          Retrieve the lazy document for the given doc, if possible.
 boolean isEmpty()
          Tells whether any keys have been registered.
 
Methods inherited from class KeyManager
addKeyDefinition, explainKeys, getKeyDefinitions, selectByKey
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nKeysStored

private int nKeysStored
Count of keys actually stored on disk

Constructor Detail

LazyKeyManager

public LazyKeyManager(Configuration config,
                      KeyManager prevMgr)
Construct and initialize the manager, grabbing existing key definitions from the previous key manager.

Method Detail

buildIndex

public Map buildIndex(int keyNameFingerprint,
                      BuiltInAtomicType itemType,
                      Set foundItemTypes,
                      DocumentInfo doc,
                      XPathContext context)
               throws XPathException
Description copied from class: KeyManager
Build the index for a particular document for a named key

Overrides:
buildIndex in class KeyManager
Parameters:
keyNameFingerprint - The fingerprint of the name of the required key
itemType - the type of the values to be indexed.
doc - The source document in question
context - The dynamic context
Returns:
the index in question, as a Map mapping a key value onto a ArrayList of nodes
Throws:
XPathException

constructIndex

protected void constructIndex(DocumentInfo doc,
                              Map index,
                              KeyDefinition keydef,
                              BuiltInAtomicType soughtItemType,
                              Set foundItemTypes,
                              XPathContext context,
                              boolean isFirst)
                       throws XPathException
Optimized to use node test directly when possible, for speed.

Overrides:
constructIndex in class KeyManager
Throws:
XPathException

isEmpty

public boolean isEmpty()
Tells whether any keys have been registered.


createAllKeys

public int createAllKeys(LazyDocument doc,
                         XPathContext context)
                  throws XPathException
Called after creation of a lazy tree during the index process. Iterates through all registered keys, and builds the associated disk-based key indexes on the given tree.

Parameters:
doc - The LazyTree to work on.
context - Context used for name pool, etc.
Returns:
int The number of keys created
Throws:
XPathException

getDocumentImpl

public static LazyDocument getDocumentImpl(DocumentInfo doc)
Retrieve the lazy document for the given doc, if possible.


calcIndexName

private String calcIndexName(NamePool pool,
                             String fingerName,
                             List definitions,
                             Configuration config)
Calculates a string name for a given set of xsl:key definitions. This is done very carefully to ensure that the same key will generate the same name, regardless of ephemeral things like particular name codes or other variables that might be different on a different run.

Parameters:
pool - Name pool used to look up names
fingerName - Fingerprint of the key
definitions - List of key definitions
config - Associated Saxon configuration
Returns:
A unique string for this xsl:key