com.rhi.architecture.parc.adapter.file
Class AbstractFileInputAdapter

java.lang.Object
  extended bycom.rhi.architecture.parc.adapter.AbstractInputAdapter
      extended bycom.rhi.architecture.parc.adapter.file.AbstractFileInputAdapter
All Implemented Interfaces:
Adapter, InputAdapter
Direct Known Subclasses:
FlatFileInputAdapter

public abstract class AbstractFileInputAdapter
extends AbstractInputAdapter

AbstractFileInputAdapter Should serve as a common base classes that all kinds of file input adapters can share. File input adapters can work with one fixed file or on a directory on polling basis or some other type. This base class should be flexible enough to cater for different file input adapters.

Version:
1.0
Author:
Vaibhav Ranjangaonkar

Constructor Summary
AbstractFileInputAdapter()
          constructor
 
Method Summary
static void closeReader(java.io.Reader reader)
          Convenience method to avoid code duplication in sub-classes.
protected  int getBatchSize()
          Returns batchSize configured through properties, if batch size needs to provided by other means, then this method should be overridden.
protected  java.lang.String getDelimiter()
          Returns delimiter configured through properties, if delimiter needs to provided by other means, then this method should be overridden.
protected abstract  java.io.BufferedReader getFileReader()
          Details of how to obtain a reader to read records are left to the concrete classes to provide flexibility.
 void init(java.util.Properties props)
           Performs any resource initialization.
protected  java.util.Collection loadBatch()
          Reads the file one record at a time using readRecordString(), parses each record into column values and passes this list of colums to the method readRow().
protected  java.lang.String[] parseRecordString(java.lang.String record)
          Hook provided for subclasses to control the way given string is parsed to extract columns.
protected  java.lang.String readRecordString()
          Hook provided for subclasses to change the way a record is read from a file.
protected abstract  Record readRow(java.util.ArrayList al)
          Extract the attributes from the ArrayList and return a Record object.
 
Methods inherited from class com.rhi.architecture.parc.adapter.AbstractInputAdapter
addToErrorChannel, cleanup, getAuditAgent, getErrors, push, setAuditAgent, setErrorChannel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFileInputAdapter

public AbstractFileInputAdapter()
constructor

Method Detail

init

public void init(java.util.Properties props)
          throws InitializationException

Performs any resource initialization.
Initilizes following things:

Specified by:
init in interface Adapter
Overrides:
init in class AbstractInputAdapter
Parameters:
props - Properties Property object, to store the initialization parameters.
Throws:
InitializationException - It throws the initialization exception, if it occurs during any of the above mentioned initialization.
InitializationException
Since:
1.0

loadBatch

protected java.util.Collection loadBatch()
                                  throws ProcessingException
Reads the file one record at a time using readRecordString(), parses each record into column values and passes this list of colums to the method readRow(). Subclasses provide implementation of readRow() that takes this list of columns and return a class implementing Record interface. Although, default behaviour is to treat each line as a record, that may not be true always, subclasses can then extend this class using the hooks provided.

Specified by:
loadBatch in class AbstractInputAdapter
Returns:
Collection contains the list of generic record, read from flat file.
Throws:
ProcessingException - It throws the ProcessingException, if there is a error during the reading of afile.
ProcessingException
Since:
1.0
See Also:
readRecordString( String ), parseRecordString( String ), readRow( ArrayList )

readRecordString

protected java.lang.String readRecordString()
                                     throws java.io.IOException
Hook provided for subclasses to change the way a record is read from a file. Default behaviour is to treat each line as a record and read that line. But, for some cases, multiple lines can form one record, this method should then be overriden by the subclass and appropriate logic should be provided.

Returns:
Throws:
java.io.IOException

parseRecordString

protected java.lang.String[] parseRecordString(java.lang.String record)
Hook provided for subclasses to control the way given string is parsed to extract columns. Default behaviour is to split the string around a delimiter configured or returned by the getDelimiter() method of the subclass. But, this may not suit some classes that have different requirement to extract columns from a given record string. An example for this could be support for comments in the input file. Thus, a subclass can override this method and return null if 'record' string is starting with a comment character ( say, '#' ).

Parameters:
record -
Returns:
parsed record string

getBatchSize

protected int getBatchSize()
Returns batchSize configured through properties, if batch size needs to provided by other means, then this method should be overridden.

Returns:
Returns the batchSize.

getDelimiter

protected java.lang.String getDelimiter()
Returns delimiter configured through properties, if delimiter needs to provided by other means, then this method should be overridden.

Returns:
Returns the delimiter.

getFileReader

protected abstract java.io.BufferedReader getFileReader()
Details of how to obtain a reader to read records are left to the concrete classes to provide flexibility. This reader is used in loadBatch() to read record strings.

Returns:
Returns the fileReader.

readRow

protected abstract Record readRow(java.util.ArrayList al)
                           throws ProcessingException
Extract the attributes from the ArrayList and return a Record object. When overriding this method, create the appropriate Record type for the interface & return it through the generic Record interface.

Returns:
Record
Throws:
SQLException
ProcessingException
Since:
1.0

closeReader

public static void closeReader(java.io.Reader reader)
Convenience method to avoid code duplication in sub-classes. Probably every subclass will have to write its own close reader operation, so this should serve that need and keep it one place. Can be moved to a common file utils kind of class when we have one. Closes the reader instance if one exists. Made protected so that subclasses can reuse this code.



Copyright © 2002-2004 Robert Half International. All Rights Reserved.