net.sf.flatpack
Class AbstractParser

java.lang.Object
  extended by net.sf.flatpack.AbstractParser
All Implemented Interfaces:
Parser
Direct Known Subclasses:
AbstractDelimiterParser, AbstractFixedLengthParser

public abstract class AbstractParser
extends java.lang.Object
implements Parser

Author:
xhensevb, zepernick

Constructor Summary
protected AbstractParser(java.io.Reader dataSourceReader)
           
protected AbstractParser(java.io.Reader dataSourceReader, java.lang.String dataDefinition)
           
 
Method Summary
protected  void addError(DefaultDataSet ds, java.lang.String errorDesc, int lineNo, int errorLevel)
          Adds a new error to this DataSet.
protected  void addError(DefaultDataSet ds, java.lang.String errorDesc, int lineNo, int errorLevel, java.lang.String lineData)
          Adds a new error to this DataSet.
protected  void addToCloseReaderList(java.io.Reader r)
           
protected  void addToMetaData(java.util.List columns)
           
protected  void closeReaders()
           
protected abstract  DataSet doParse()
           
protected  java.lang.String getDataDefinition()
           
 java.lang.String getDataFileTable()
          Returns the table name that will be used to read the MetaData from the db.
protected  java.io.Reader getDataSourceReader()
           
 java.lang.String getDataStructureTable()
          Returns the table name that will be used to read the MetaData from the db.
 MetaData getPzMetaData()
           
protected abstract  void init()
           
 boolean isColumnNamesCaseSensitive()
          Default is false
 boolean isFlagEmptyRows()
           
 boolean isHandlingShortLines()
           
 boolean isIgnoreExtraColumns()
           
 boolean isIgnoreParseWarnings()
          Default is false
protected  boolean isInitialised()
           
 boolean isNullEmptyStrings()
           
 boolean isStoreRawDataToDataError()
           
 boolean isStoreRawDataToDataSet()
           
 DataSet parse()
          Start the parsing.
 void setColumnNamesCaseSensitive(boolean columnNamesCaseSensitive)
          Default is false
protected  void setDataDefinition(java.lang.String dataDefinition)
           
 void setDataFileTable(java.lang.String dataFileTable)
          Sets the table name that will be used to read the MetaData from the db.
protected  void setDataSourceReader(java.io.Reader dataSourceReader)
           
 void setDataStructureTable(java.lang.String dataStructureTable)
          Sets the table name that will be used to read the MetaData from the db.
 void setFlagEmptyRows(boolean flagEmptyRows)
          when true, will analyze the row to see if all elements are empty and place a flag on the DataSet indicating if the row is empty.
 void setHandlingShortLines(boolean handleShortLines)
           
 void setIgnoreExtraColumns(boolean ignoreExtraColumns)
           
 void setIgnoreParseWarnings(boolean ignoreParseWarnings)
           
protected  void setInitialised(boolean initialised)
           
 void setNullEmptyStrings(boolean nullEmptyStrings)
           
 void setPzMetaData(MetaData pzMap)
           
 void setStoreRawDataToDataError(boolean storeRawDataToDataError)
          when true, the parser will place the data of the line which failed the parse and place it into the DataError object.
 void setStoreRawDataToDataSet(boolean storeRawDataToDataSet)
          WARNING!!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParser

protected AbstractParser(java.io.Reader dataSourceReader)

AbstractParser

protected AbstractParser(java.io.Reader dataSourceReader,
                         java.lang.String dataDefinition)
Method Detail

isHandlingShortLines

public boolean isHandlingShortLines()
Specified by:
isHandlingShortLines in interface Parser
Returns:
true, lines with less columns then the amount of column headers will be added as empty's instead of producing an error

setHandlingShortLines

public void setHandlingShortLines(boolean handleShortLines)
Specified by:
setHandlingShortLines in interface Parser
Parameters:
handleShortLines - - when flagged as true, lines with less columns then the amount of column headers will be added as empty's instead of producing an error

isIgnoreExtraColumns

public boolean isIgnoreExtraColumns()
Specified by:
isIgnoreExtraColumns in interface Parser
Returns:
true, detail lines with a length or column count > the mapping definition will be truncated and the reader will NOT register these lines as errors in the DataError collection.

setIgnoreExtraColumns

public void setIgnoreExtraColumns(boolean ignoreExtraColumns)
Specified by:
setIgnoreExtraColumns in interface Parser
Parameters:
ignoreExtraColumns - when true, detail lines with a length or column count > the mapping definition will be truncated and the reader will NOT register these lines as errors in the DataError collection.

parse

public final DataSet parse()
Description copied from interface: Parser
Start the parsing. Will return "null" if the parse fails and the DataSet cannot be created

Specified by:
parse in interface Parser
Returns:
the data set resulting from parsing

doParse

protected abstract DataSet doParse()

init

protected abstract void init()

closeReaders

protected void closeReaders()
                     throws java.io.IOException
Throws:
java.io.IOException

addToCloseReaderList

protected void addToCloseReaderList(java.io.Reader r)

addToMetaData

protected void addToMetaData(java.util.List columns)

isInitialised

protected boolean isInitialised()

setInitialised

protected void setInitialised(boolean initialised)

getDataDefinition

protected java.lang.String getDataDefinition()

setDataDefinition

protected void setDataDefinition(java.lang.String dataDefinition)

addError

protected void addError(DefaultDataSet ds,
                        java.lang.String errorDesc,
                        int lineNo,
                        int errorLevel)
Adds a new error to this DataSet. These can be collected, and retrieved after processing

Parameters:
errorDesc - String description of error
lineNo - line number error occurred on
errorLevel - errorLevel 1,2,3 1=warning 2=error 3= severe error

addError

protected void addError(DefaultDataSet ds,
                        java.lang.String errorDesc,
                        int lineNo,
                        int errorLevel,
                        java.lang.String lineData)
Adds a new error to this DataSet. These can be collected, and retrieved after processing

Parameters:
errorDesc - String description of error
lineNo - line number error occurred on
errorLevel - errorLevel 1,2,3 1=warning 2=error 3= severe error'
lineData - Data of the line which failed the parse

getDataSourceReader

protected java.io.Reader getDataSourceReader()
Returns:
the dataSourceReader

setDataSourceReader

protected void setDataSourceReader(java.io.Reader dataSourceReader)
Parameters:
dataSourceReader - the dataSourceReader to set

isColumnNamesCaseSensitive

public boolean isColumnNamesCaseSensitive()
Description copied from interface: Parser
Default is false

Specified by:
isColumnNamesCaseSensitive in interface Parser
Returns:
true, column names will have to be an exact match when retrieving the value of a column. Example when true: Column name = AColumnName ; getString("acolumnname") would fail Example when false: Column name = AColumnName ; getString("acolumnname") would pass

setColumnNamesCaseSensitive

public void setColumnNamesCaseSensitive(boolean columnNamesCaseSensitive)
Description copied from interface: Parser
Default is false

Specified by:
setColumnNamesCaseSensitive in interface Parser
Parameters:
columnNamesCaseSensitive - when true, column names will have to be an exact match when retrieving the value of a column. Example when true: Column name = AColumnName ; getString("acolumnname") would fail Example when false: Column name = AColumnName ; getString("acolumnname") would pass

isIgnoreParseWarnings

public boolean isIgnoreParseWarnings()
Description copied from interface: Parser
Default is false

Specified by:
isIgnoreParseWarnings in interface Parser
Returns:
true, warnings encountered during parsing will not be included in the DataSet errors

setIgnoreParseWarnings

public void setIgnoreParseWarnings(boolean ignoreParseWarnings)
Specified by:
setIgnoreParseWarnings in interface Parser
Parameters:
ignoreParseWarnings - when true, warnings encountered during parsing will not be included in the DataSet errors

isNullEmptyStrings

public boolean isNullEmptyStrings()
Specified by:
isNullEmptyStrings in interface Parser
Returns:
true, empty Strings will get returned as NULL when calling DataSet.getString()

setNullEmptyStrings

public void setNullEmptyStrings(boolean nullEmptyStrings)
Specified by:
setNullEmptyStrings in interface Parser
Parameters:
nullEmptyStrings - when true, empty Strings will get returned as NULL when calling DataSet.getString()

getPzMetaData

public MetaData getPzMetaData()

setPzMetaData

public void setPzMetaData(MetaData pzMap)

isFlagEmptyRows

public boolean isFlagEmptyRows()
Specified by:
isFlagEmptyRows in interface Parser
Returns:
the flagEmptyRows

setFlagEmptyRows

public void setFlagEmptyRows(boolean flagEmptyRows)
Description copied from interface: Parser
when true, will analyze the row to see if all elements are empty and place a flag on the DataSet indicating if the row is empty. This will slow down the parse and should only be used when necessary. It is off by default.

Specified by:
setFlagEmptyRows in interface Parser
Parameters:
flagEmptyRows - the flagEmptyRows to set

isStoreRawDataToDataError

public boolean isStoreRawDataToDataError()
Specified by:
isStoreRawDataToDataError in interface Parser
Returns:
the storeRawDataToDataError

setStoreRawDataToDataError

public void setStoreRawDataToDataError(boolean storeRawDataToDataError)
Description copied from interface: Parser
when true, the parser will place the data of the line which failed the parse and place it into the DataError object. DataError.getRawData() can be called to retrieve the line.

Specified by:
setStoreRawDataToDataError in interface Parser
Parameters:
storeRawDataToDataError - the storeRawDataToDataError to set

isStoreRawDataToDataSet

public boolean isStoreRawDataToDataSet()
Specified by:
isStoreRawDataToDataSet in interface Parser
Returns:
the storeRawDataToDataSet

setStoreRawDataToDataSet

public void setStoreRawDataToDataSet(boolean storeRawDataToDataSet)
Description copied from interface: Parser
WARNING!! Setting this option has potential to cause high memory usage. when true, the parser will place the data of the line into the DataSet object. DataSet.getRawData() can be called to retrieve the line.

Specified by:
setStoreRawDataToDataSet in interface Parser
Parameters:
storeRawDataToDataSet - the storeRawDataToDataSet to set

getDataFileTable

public java.lang.String getDataFileTable()
Description copied from interface: Parser
Returns the table name that will be used to read the MetaData from the db. The default table name is DATAFILE. This may be problimatic for some who are using case sensistive db table names or who wish to provide a different table name in the db. This is only applicable when using a database for file mappings.

Specified by:
getDataFileTable in interface Parser
Returns:
the DATAFILE table name

setDataFileTable

public void setDataFileTable(java.lang.String dataFileTable)
Description copied from interface: Parser
Sets the table name that will be used to read the MetaData from the db. The default table name is DATAFILE. This may be problimatic for some who are using case sensistive db table names or who wish to provide a different table name in the db. This is only applicable when using a database for file mappings.

Specified by:
setDataFileTable in interface Parser
Parameters:
dataFileTable - Name of the table name to use in place of "DATAFILE"

getDataStructureTable

public java.lang.String getDataStructureTable()
Description copied from interface: Parser
Returns the table name that will be used to read the MetaData from the db. The default table name is DATASTRUCTURE. This may be problimatic for some who are using case sensistive db table names or who wish to provide a different table name in the db. This is only applicable when using a database for file mappings.

Specified by:
getDataStructureTable in interface Parser
Returns:
the DATASTRUCTURE table name

setDataStructureTable

public void setDataStructureTable(java.lang.String dataStructureTable)
Description copied from interface: Parser
Sets the table name that will be used to read the MetaData from the db. The default table name is DATASTRUCTURE. This may be problimatic for some who are using case sensistive db table names or who wish to provide a different table name in the db. This is only applicable when using a database for file mappings.

Specified by:
setDataStructureTable in interface Parser
Parameters:
dataStructureTable - Name of the table name to us in placfe of "DATASTRUCTURE"


Copyright © 2006-2011 Appendium - Portfolio Financing Platform. All Rights Reserved.