ST-Developer Java Reference

com.steptools.stdev.p21
Class Part21Parser

java.lang.Object
  extended by com.steptools.stdev.p21.Part21Parser
Direct Known Subclasses:
Part21LoggingParser

public class Part21Parser
extends Object

Provides the facilities to read a Part 21 file and populate a model from the instance data contained in the file. No state information is kept in the Part21Parser, so it is possible to use the same parser to read multiple files at the same time from different threads.


Nested Class Summary
 class Part21Parser.State
           
 
Field Summary
 boolean convert
          If true, attempt to perform a type conversion before throwing an error.
 boolean fail_fast
          If true, error recovery is disabled, and will result in an exception getting thrown on any errors in the Part 21 file.
 boolean keep_partial
          If true, does not attempt to clean up when statusUpdate() throws a CanceledException.
 int status_freq
          Set the frequency at which the statusUpdate method is called.
 
Constructor Summary
Part21Parser()
          Create a Part 21 file Reader.
 
Method Summary
 SchemaBase getSchema(String name)
          Find the schema for a given name.
 Model parse(File src)
          Read a Part 21 file into a new Model.
 Model parse(File src, String fname)
          Read a Part 21 file into a new Model.
 void parse(File src, String fname, long flen, Model mod, EntityIDTable eids, boolean set_header, boolean one_sect)
          Read a Part 21 file into an existing Model.
 Model parse(InputStream in, String fname, long flen)
          Read a Part 21 file into a new Model.
 void parse(InputStream in, String fname, long flen, Model mod, EntityIDTable eids, boolean set_header, boolean one_sect)
          Read a Part 21 file into an existing Model.
 Model parse(String fname)
          Read a Part 21 file into a new Model.
 void reportError(String fname, int lineno, String message)
          Report an error in the input file.
 void statusUpdate(Part21Parser.State st)
          The method is called periodically as the parser parses its input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fail_fast

public boolean fail_fast
If true, error recovery is disabled, and will result in an exception getting thrown on any errors in the Part 21 file.


convert

public boolean convert
If true, attempt to perform a type conversion before throwing an error.


status_freq

public int status_freq
Set the frequency at which the statusUpdate method is called. If this value is 0 (the default) the statusUpdate() method will never be called. Otherwise, it will be called after status_freq instances are read in.


keep_partial

public boolean keep_partial
If true, does not attempt to clean up when statusUpdate() throws a CanceledException. If this is false, the CanceledException will be propogated to the called of parse(), and the partially read model will be reclained by the garbage collector. If true the incomplete model will be returned from the parse() method.

Constructor Detail

Part21Parser

public Part21Parser()
             throws STDevException
Create a Part 21 file Reader.

Throws:
STDevException
Method Detail

getSchema

public SchemaBase getSchema(String name)
                     throws SchemaNotFoundException
Find the schema for a given name. This method can be overridden in subclasses to control which schema is used, based on the specified file name

Parameters:
name - The name of the schema as specified in Part 21
Returns:
The schema to to use for the given name.
Throws:
SchemaNotFoundException - the schema could not be found.

reportError

public void reportError(String fname,
                        int lineno,
                        String message)
Report an error in the input file. This method can be overridden in subclasses to report the errors as needed for the application. The default implementation does nothing.

Parameters:
fname - The Part21 file.
lineno - The line number where the error occurred.
message - The error message to be reported.

statusUpdate

public void statusUpdate(Part21Parser.State st)
                  throws CanceledException
The method is called periodically as the parser parses its input. It can be overridden in subtypes so that status information can be provided to the user about progress of the reader, and to give the use a way to cancel reading a file. Frequency that this function is called is determined by the status_freq instance variable. The read will be aborted if this method throws an exception.

Parameters:
st - The parser state information. This can be queried to obtain the number of bytes in the file, the number of bytes ready by the parser, and the number is insteances read.
Throws:
CanceledException - to signal the parser to stop parsing the file. If the exception's keepPartial() flag is true, then the partially read model is return from the parse method. Otherwise, the exception is propogated, and the data that was read will be reclained by the garabge collecto.r

parse

public Model parse(String fname)
            throws STDevException,
                   IOException
Read a Part 21 file into a new Model.

Parameters:
fname - The file name.
Returns:
The model that contains the instances in the file
Throws:
STDevException - There was some problem parsing the file
IOException - An I/O exception occurred getting the input

parse

public Model parse(File src)
            throws STDevException,
                   IOException
Read a Part 21 file into a new Model.

Parameters:
src - The file to read.
Returns:
The model that contains the instances in the file
Throws:
STDevException - There was some problem parsing the file
IOException - An I/O exception occurred getting the input

parse

public Model parse(File src,
                   String fname)
            throws STDevException,
                   IOException
Read a Part 21 file into a new Model.

Parameters:
src - The file to read.
fname - The file name for error reporting purposes. If null, src.toString() will be used.
Returns:
The model that contains the instances in the file
Throws:
STDevException - There was some problem parsing the file
IOException - An I/O exception occurred getting the input

parse

public Model parse(InputStream in,
                   String fname,
                   long flen)
            throws STDevException,
                   IOException
Read a Part 21 file into a new Model.

Parameters:
in - The reader to read
fname - The file name for error reporting purposes.
flen - The length of the input stream in bytes. This is used for status reporting.
Returns:
The model that contains the instances in the file
Throws:
STDevException - There was some problem parsing the file
IOException - An I/O exception occurred getting the input

parse

public void parse(File src,
                  String fname,
                  long flen,
                  Model mod,
                  EntityIDTable eids,
                  boolean set_header,
                  boolean one_sect)
           throws STDevException,
                  IOException
Read a Part 21 file into an existing Model.

Parameters:
src - The Part 21 file to read
fname - The file name for error reporting purposes.
flen - The length of the input stream in bytes. This is used for status reporting.
mod - The model to populate
eids - The entity ID table to populate
set_header - Add the file header as a section to the model.
one_sect - Force everything into one data population
Throws:
STDevException - There was some problem parsing the file
IOException - An I/O exception occurred getting the input

parse

public void parse(InputStream in,
                  String fname,
                  long flen,
                  Model mod,
                  EntityIDTable eids,
                  boolean set_header,
                  boolean one_sect)
           throws STDevException,
                  IOException
Read a Part 21 file into an existing Model.

Parameters:
in - The reader to read
fname - The file name for error reporting purposes.
flen - The length of the input stream in bytes. This is used for status reporting.
mod - The model to populate
eids - The entity ID table to populate
set_header - Add the file header as a section to the model.
one_sect - Force everything into one data population
Throws:
STDevException - There was some problem parsing the file
IOException - An I/O exception occurred getting the input

ST-Developer Java Reference