com.blackbear.flatworm
Class FileParser

java.lang.Object
  extended by com.blackbear.flatworm.FileParser

public class FileParser
extends java.lang.Object

Used to read a flatfile. Encapsulates parser setup and callback mechanism. This class wraps the functionality that used to be in the main() of the examples. This way, the client knows less about the internal workings of FlatWorm.


Constructor Summary
FileParser(java.lang.String config, java.lang.String file)
          Constructor for FileParser
 
Method Summary
 void close()
          Close the input file
 void open()
          Open the buffered reader for the input file
 void read()
          Read the entire input file.
 void setBeanHandler(java.lang.String recordName, java.lang.Object obj, java.lang.String methodName)
          Let's the parser know which object and method to call when a record has been successfully parsed and needs handling
 void setExceptionHandler(java.lang.Object obj, java.lang.String methodName)
          Let's the parser know which object and method to call when an exception occurs during record processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileParser

public FileParser(java.lang.String config,
                  java.lang.String file)
           throws FlatwormParserException
Constructor for FileParser

Parameters:
String - full path to the FlatWorm XML configuration file
String - full path to input file
Throws:
FlatwormParserException - - wraps FlatwormConfigurationValueException & FlatwormUnsetFieldValueException (to reduce number of exceptions clients have to be aware of)
Method Detail

setBeanHandler

public void setBeanHandler(java.lang.String recordName,
                           java.lang.Object obj,
                           java.lang.String methodName)
                    throws java.lang.NoSuchMethodException
Let's the parser know which object and method to call when a record has been successfully parsed and needs handling

Parameters:
String - recordname from your FlatWorm XML file
Object - handler object which will responding to parse events
String - name of handler method from the handler class (passing this prevents java.reflection code in client)
Throws:
java.lang.NoSuchMethodException - - This will most likely be caused by a oversight on your part (i.e. not yet implemented this class in your handler or mispelled the method name when passing it to this method)

setExceptionHandler

public void setExceptionHandler(java.lang.Object obj,
                                java.lang.String methodName)
                         throws java.lang.NoSuchMethodException
Let's the parser know which object and method to call when an exception occurs during record processing.

Parameters:
String - recordname from your FlatWorm XML file
Object - handler object which will responding to parse events
String - name of handler method from the handler class (passing this prevents java.reflection code in client)
Throws:
java.lang.NoSuchMethodException - - This will most likely be caused by a oversight on your part (i.e. not yet implemented this class in your handler or mispelled the method name when passing it to this method)

open

public void open()
          throws java.io.FileNotFoundException
Open the buffered reader for the input file

Throws:
java.io.FileNotFoundException - - If the file you supplied does not happen to exist.

close

public void close()
           throws java.io.IOException
Close the input file

Throws:
java.io.IOException - - Should the filesystem choose to complain about closing an existing file opened for reading.

read

public void read()
Read the entire input file. This method will call your handler methods, if defeined, to handle Records it parses.

NOTE: All exceptions are consumed and passed to the exception handler method you defined (The offending line is provided just in case you want to do something with it.