org.cdlib.xtf.lazyTree
Class LazyTreeBuilder

Object
  extended by LazyTreeBuilder

public class LazyTreeBuilder
extends Object

Creates and/or loads a disk-based representation of an XML tree. Once created, the persistent version can be quickly and incrementally loaded into memory.

To build a tree, call the begin(StructuredStore) method to start the process. Using the Receiver it returns, pass all the SAX events gathered from parsing the document. Finally, finish(Receiver, boolean) will complete the process.

To load a tree that was built previously, use either load method: load(StructuredStore) or load(StructuredStore, LazyDocument).

Author:
Martin Haye

Field Summary
private  Configuration config
          Saxon configuration used for tree loading
static String CURRENT_VERSION
          File version stored in the persistent file.
private  NamePool namePool
          Name pool used to map namecodes
private  ConsecutiveMap names
          Mapping of names found to our internal name numbers
private  PipelineConfiguration pipe
          Pipeline configuration
static String REQUIRED_VERSION
          Minimum version we can read.
private  TinyTree tree
          The Saxon 'tiny' document, used to load the input tree
 
Constructor Summary
LazyTreeBuilder(Configuration config)
          Default constructor -- sets up the configuration
 
Method Summary
 void abort(Receiver inBuilder)
          Like finish() above, but aborts the tree building process and removes the file.
 Receiver begin(StructuredStore treeStore)
          Alternate way of constructing a lazy tree.
private  void checkSupport()
          Checks that the tree doesn't use features we don't support.
 void finish(Receiver inBuilder, boolean closeStore)
          Completes writing out a disk-based file.
 int getNodeNum(Receiver inBuilder)
          Retrieves the current node number in the build.
 NodeInfo load(StructuredStore treeStore)
          Load a persistent document using the default loader.
 void load(StructuredStore treeStore, LazyDocument emptyDoc)
          Load a pre-existing persistent tree and load it into an empty in-memory document.
 void setNamePool(NamePool pool)
          Establishes the name pool used to resolve namecodes
private  void writeAttrs(SubStoreWriter out)
          Build and write out all the attributes in the tree.
private  void writeNames(SubStoreWriter out)
          Build and write out the table of names referenced by the tree.
private  void writeNodes(SubStoreWriter out)
          Build and write out all the nodes in the tree.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tree

private TinyTree tree
The Saxon 'tiny' document, used to load the input tree


namePool

private NamePool namePool
Name pool used to map namecodes


names

private ConsecutiveMap names
Mapping of names found to our internal name numbers


config

private Configuration config
Saxon configuration used for tree loading


pipe

private PipelineConfiguration pipe
Pipeline configuration


CURRENT_VERSION

public static final String CURRENT_VERSION
File version stored in the persistent file.

See Also:
Constant Field Values

REQUIRED_VERSION

public static final String REQUIRED_VERSION
Minimum version we can read.

See Also:
Constant Field Values
Constructor Detail

LazyTreeBuilder

public LazyTreeBuilder(Configuration config)
Default constructor -- sets up the configuration

Method Detail

setNamePool

public void setNamePool(NamePool pool)
Establishes the name pool used to resolve namecodes


load

public NodeInfo load(StructuredStore treeStore)
              throws FileNotFoundException,
                     IOException
Load a persistent document using the default loader.

Parameters:
treeStore - The store to load from
Returns:
The root node of the document (which implements DocumentInfo)
Throws:
FileNotFoundException
IOException

load

public void load(StructuredStore treeStore,
                 LazyDocument emptyDoc)
          throws FileNotFoundException,
                 IOException
Load a pre-existing persistent tree and load it into an empty in-memory document.

Parameters:
treeStore - The store to load from
emptyDoc - An empty document object to initialize
Throws:
FileNotFoundException
IOException

begin

public Receiver begin(StructuredStore treeStore)
               throws IOException
Alternate way of constructing a lazy tree. First, begin() is called, returning a Receiver that should receive all the SAX events from the input. When all events have been sent, then call finish(Receiver, boolean).

Throws:
IOException

getNodeNum

public int getNodeNum(Receiver inBuilder)
Retrieves the current node number in the build. Indexer uses this to record node numbers in text chunks.

Parameters:
inBuilder - The builder gotten from begin()
Returns:
The current node number.

finish

public void finish(Receiver inBuilder,
                   boolean closeStore)
            throws IOException
Completes writing out a disk-based file. Assumes that the receiver (which must come from begin()) has been sent all the SAX events for the input document.

Throws:
IOException

abort

public void abort(Receiver inBuilder)
Like finish() above, but aborts the tree building process and removes the file. Should be called if normal processing cannot complete.


writeNames

private void writeNames(SubStoreWriter out)
                 throws IOException
Build and write out the table of names referenced by the tree. Also includes the namespaces.

Parameters:
out - SubStore to write to.
Throws:
IOException

writeNodes

private void writeNodes(SubStoreWriter out)
                 throws IOException
Build and write out all the nodes in the tree. The resulting table has fixed-sized entries, sized to fit the largest node.

Parameters:
out - SubStore to write to.
Throws:
IOException

writeAttrs

private void writeAttrs(SubStoreWriter out)
                 throws IOException
Build and write out all the attributes in the tree. The resulting table has variable-sized entries.

Parameters:
out - SubStore to write to.
Throws:
IOException

checkSupport

private void checkSupport()
                   throws IOException
Checks that the tree doesn't use features we don't support. If it does, we throw an exception.

Throws:
IOException