org.basex.build
Class Builder

java.lang.Object
  extended by org.basex.core.Progress
      extended by org.basex.build.Builder
Direct Known Subclasses:
DiskBuilder, MemBuilder

public abstract class Builder
extends Progress

This class provides an interface for building database instances. The specified Parser send events to this class whenever nodes are to be added or closed. The builder implementation decides whether the nodes are stored on disk or kept in memory.

Author:
Workgroup DBIS, University of Konstanz 2005-08, ISC License, Christian Gruen

Field Summary
 int elms
          Element counter.
 MetaData meta
          Meta data on built database.
 int size
          Table size.
 
Method Summary
abstract  void addAttr(int n, int s, byte[] v, int d)
          Adds an attribute to the database.
abstract  void addDoc(byte[] tok)
          Adds a document node to the database.
abstract  void addElem(int tok, int tns, int dis, int as, boolean n)
          Adds an element node to the database.
abstract  void addText(byte[] tok, int dis, byte kind)
          Adds a text node to the database.
 Data build(Parser p, java.lang.String db)
          Builds the database by running the specified parser.
abstract  void close()
          Closes open references.
 void comment(TokenBuilder com)
          Stores a comment.
 java.lang.String det()
          Returns short information on this process.
 void emptyElem(byte[] tag, Atts att)
          Stores an empty element.
 void encoding(java.lang.String enc)
          Sets the document encoding.
 void endDoc()
          Closes a document node.
 void endElem(byte[] tag)
          Closes an element.
abstract  Data finish()
          Finishes the build process and returns a database reference.
abstract  Builder init(java.lang.String db)
          Initializes the database construction.
 void nodeAndText(byte[] tag, Atts att, byte[] txt)
          Convenience method for adding an element and text node.
 void pi(TokenBuilder pi)
          Stores a processing instruction.
 double prog()
          Returns progress information.
abstract  void setAttValue(int pre, byte[] val)
          Stores an attribute value to the specified table position.
abstract  void setSize(int pre, int val)
          Stores a size value to the specified table position.
 void startDoc(byte[] doc)
          Opens a document node.
 int startElem(byte[] tag, Atts att)
          Opens a new element node.
 void startNS(byte[] name, byte[] val)
          Adds a new namespace; called by the building instance.
 void text(TokenBuilder t, boolean w)
          Stores a text node.
 java.lang.String tit()
          Returns short information on this process.
 
Methods inherited from class org.basex.core.Progress
checkStop, detail, progress, progress, stop, title
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

meta

public MetaData meta
Meta data on built database.


size

public int size
Table size.


elms

public int elms
Element counter.

Method Detail

init

public abstract Builder init(java.lang.String db)
                      throws java.io.IOException
Initializes the database construction.

Parameters:
db - name of database
Returns:
builder instance
Throws:
java.io.IOException - in case of parsing or writing problems

finish

public abstract Data finish()
                     throws java.io.IOException
Finishes the build process and returns a database reference.

Returns:
data database instance
Throws:
java.io.IOException - in case of parsing or writing problems

close

public abstract void close()
                    throws java.io.IOException
Closes open references.

Throws:
java.io.IOException - in case of parsing or writing problems

addDoc

public abstract void addDoc(byte[] tok)
                     throws java.io.IOException
Adds a document node to the database.

Parameters:
tok - the token to be added (tag name or content)
Throws:
java.io.IOException - in case of parsing or writing problems

addElem

public abstract void addElem(int tok,
                             int tns,
                             int dis,
                             int as,
                             boolean n)
                      throws java.io.IOException
Adds an element node to the database. This method stores a preliminary size value; if this node has further descendants, setSize(int, int) has to be called with the final size value.

Parameters:
tok - the tag name reference
tns - the tag namespace
dis - distance (relative parent reference)
as - number of attributes
n - element has namespaces
Throws:
java.io.IOException - in case of parsing or writing problems

addAttr

public abstract void addAttr(int n,
                             int s,
                             byte[] v,
                             int d)
                      throws java.io.IOException
Adds an attribute to the database.

Parameters:
n - attribute name
s - namespace
v - attribute value
d - distance (relative parent reference)
Throws:
java.io.IOException - in case of parsing or writing problems

addText

public abstract void addText(byte[] tok,
                             int dis,
                             byte kind)
                      throws java.io.IOException
Adds a text node to the database.

Parameters:
tok - the token to be added (tag name or content)
dis - distance (relative parent reference)
kind - the node kind
Throws:
java.io.IOException - in case of parsing or writing problems

setSize

public abstract void setSize(int pre,
                             int val)
                      throws java.io.IOException
Stores a size value to the specified table position.

Parameters:
pre - pre reference
val - value to be stored
Throws:
java.io.IOException - in case of parsing or writing problems

setAttValue

public abstract void setAttValue(int pre,
                                 byte[] val)
                          throws java.io.IOException
Stores an attribute value to the specified table position.

Parameters:
pre - pre reference
val - value to be stored
Throws:
java.io.IOException - in case of parsing or writing problems

build

public final Data build(Parser p,
                        java.lang.String db)
                 throws java.io.IOException
Builds the database by running the specified parser.

Parameters:
p - parser instance
db - name of database
Returns:
data database instance
Throws:
java.io.IOException - in case of parsing or writing problems

startDoc

public final void startDoc(byte[] doc)
                    throws java.io.IOException
Opens a document node.

Parameters:
doc - document name
Throws:
java.io.IOException - in case of parsing or writing problems

endDoc

public final void endDoc()
                  throws java.io.IOException
Closes a document node.

Throws:
java.io.IOException - in case of parsing or writing problems

startNS

public final void startNS(byte[] name,
                          byte[] val)
Adds a new namespace; called by the building instance.

Parameters:
name - the attribute name to be processed
val - attribute value

startElem

public final int startElem(byte[] tag,
                           Atts att)
                    throws java.io.IOException
Opens a new element node.

Parameters:
tag - tag name
att - attributes
Returns:
preValue of the created node
Throws:
java.io.IOException - in case of parsing or writing problems

emptyElem

public final void emptyElem(byte[] tag,
                            Atts att)
                     throws java.io.IOException
Stores an empty element.

Parameters:
tag - tag name
att - attributes
Throws:
java.io.IOException - in case of parsing or writing problems

endElem

public final void endElem(byte[] tag)
                   throws java.io.IOException
Closes an element.

Parameters:
tag - tag name
Throws:
java.io.IOException - in case of parsing or writing problems

text

public final void text(TokenBuilder t,
                       boolean w)
                throws java.io.IOException
Stores a text node.

Parameters:
t - text value
w - whitespace flag
Throws:
java.io.IOException - in case of parsing or writing problems

comment

public final void comment(TokenBuilder com)
                   throws java.io.IOException
Stores a comment.

Parameters:
com - comment text
Throws:
java.io.IOException - in case of parsing or writing problems

pi

public final void pi(TokenBuilder pi)
              throws java.io.IOException
Stores a processing instruction.

Parameters:
pi - processing instruction name and value
Throws:
java.io.IOException - in case of parsing or writing problems

encoding

public final void encoding(java.lang.String enc)
Sets the document encoding.

Parameters:
enc - encoding

nodeAndText

public final void nodeAndText(byte[] tag,
                              Atts att,
                              byte[] txt)
                       throws java.io.IOException
Convenience method for adding an element and text node.

Parameters:
tag - the tag to be processed
att - attributes
txt - text node
Throws:
java.io.IOException - in case of parsing or writing problems

tit

public final java.lang.String tit()
Description copied from class: Progress
Returns short information on this process. Can be overwritten to give more detailed information.

Returns:
header information

det

public final java.lang.String det()
Description copied from class: Progress
Returns short information on this process.

Overrides:
det in class Progress
Returns:
header information

prog

public final double prog()
Description copied from class: Progress
Returns progress information. Can be overwritten to give more detailed information.

Overrides:
prog in class Progress
Returns:
header information