com.ricebridge.csvman
Class ResultSetLineListener

java.lang.Object
  extended bycom.ricebridge.csvman.LineListenerSupportImpl
      extended bycom.ricebridge.csvman.CustomLineListener
          extended bycom.ricebridge.csvman.HeadersListenerSupport
              extended bycom.ricebridge.csvman.ResultSetLineListener
All Implemented Interfaces:
LineListener

public class ResultSetLineListener
extends HeadersListenerSupport

An implementation of LineListener that inserts loaded data lines into a ResultSet.

You can then use this ResultSet directly to retrieve the data. See CsvResultSet for more details. The easiest way to get a ResultSet of your CSV data is to use the CsvManager.loadResultSet method.

ResultSetLineListener is designed to be subclassed. You can change the default implementation by calling the CsvManagerStore.setResultSetLineListenerClass method, and providing a subclass of ResultSetLineListener. CsvManagerStore can be accessed using CsvManager.getCsvManagerStore().

The Source Code of this Java class is available under a BSD-style license.

See Also:
LineListener, CustomLineListener, BasicLineListener, AsListsLineListener, TableModelLineListener, BeanLineListener

Field Summary
static boolean DEFAULT_ResultSet_dataHasHeaders
          Default value of ResultSet.dataHasHeaders (false).
protected  Class iCsvResultSetClass
          ResultSet implementation class used to create new instances.
protected  ArrayList iData
          List of String[] arrays holding data lines.
protected  boolean iDataHasHeaders
          When true, the first line of CSV data should be a header line specifying the data field names.
protected  int iNumFields
          Number of data fields.
static String PROP_ResultSet_dataHasHeaders
          Specify that the first row of data is a header line containing the names of the data fields.
 
Fields inherited from class com.ricebridge.csvman.HeadersListenerSupport
iHasHeaders
 
Constructor Summary
ResultSetLineListener()
           
 
Method Summary
protected  void endProcessImpl()
          End the loading process.
 ResultSet getResultSet()
          Get a ResultSet instance that presents the CSV data.
protected  BadLine handleLineImpl(String[] pLine, int pNumFields, long pLineNumber, String pOriginalLine)
          Add the data line String[] array to the list of ResultSet rows.
 void setCsvResultSetClass(Class pCsvResultSetClass)
          Use your own subclass of CsvResultSet for loading CSV data.
protected  void setCsvSpecImpl(CsvSpec pCsvSpec)
          Handle property settings for loading data in a ResultSet.
protected  void startProcessImpl()
          Start the loading process.
 
Methods inherited from class com.ricebridge.csvman.HeadersListenerSupport
getHasHeaders, setHasHeaders
 
Methods inherited from class com.ricebridge.csvman.CustomLineListener
handleBadLineImpl, setLineSpecImpl
 
Methods inherited from class com.ricebridge.csvman.LineListenerSupportImpl
endProcess, handleBadLine, handleLine, setCsvSpec, setLineSpec, startProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_ResultSet_dataHasHeaders

public static final String PROP_ResultSet_dataHasHeaders
Specify that the first row of data is a header line containing the names of the data fields. (name for CsvSpec.setProperty: ResultSet.dataHasHeaders).

See Also:
Constant Field Values

DEFAULT_ResultSet_dataHasHeaders

public static final boolean DEFAULT_ResultSet_dataHasHeaders
Default value of ResultSet.dataHasHeaders (false).

See Also:
Constant Field Values

iCsvResultSetClass

protected Class iCsvResultSetClass
ResultSet implementation class used to create new instances.


iData

protected ArrayList iData
List of String[] arrays holding data lines.


iNumFields

protected int iNumFields
Number of data fields.


iDataHasHeaders

protected boolean iDataHasHeaders
When true, the first line of CSV data should be a header line specifying the data field names.

Constructor Detail

ResultSetLineListener

public ResultSetLineListener()
Method Detail

setCsvSpecImpl

protected void setCsvSpecImpl(CsvSpec pCsvSpec)
                       throws Exception
Handle property settings for loading data in a ResultSet.

You can change these using CsvSpec.

Compatibility note: the correct way to change the settings for a LineListener is by using the CsvSpec.setProperty method. CSV Manager 1.1 also allowed you to set certain settings as load method parameters (for example: pHasHeaders in CsvManager.loadResultSet(File, boolean). These parameters will be removed in CSV Manager 2.0, so you should not use them anymore. They are only retained for compatibility with CSV Manager 1.1.

The property you can use here is: PROP_ResultSet_dataHasHeaders.

Overrides:
setCsvSpecImpl in class CustomLineListener
Parameters:
pCsvSpec - CsvSpec object
Throws:
Exception
See Also:
LineListener.setCsvSpec(com.ricebridge.csvman.CsvSpec), PROP_ResultSet_dataHasHeaders

startProcessImpl

protected void startProcessImpl()
                         throws Exception
Start the loading process.

Overrides:
startProcessImpl in class CustomLineListener
Throws:
Exception
See Also:
LineListener.startProcess()

handleLineImpl

protected BadLine handleLineImpl(String[] pLine,
                                 int pNumFields,
                                 long pLineNumber,
                                 String pOriginalLine)
                          throws Exception
Add the data line String[] array to the list of ResultSet rows.

Specified by:
handleLineImpl in class CustomLineListener
Parameters:
pLine - String values of data fields in line
pNumFields - Number of data fields actually found on the current line
pLineNumber - Count of lines processed so far.
pOriginalLine - Text of original data line from data source
Returns:
null if line is OK, BadLine object if line was bad in some way
Throws:
Exception
See Also:
LineListener.handleLine, BadLine, handleBadLineImpl

endProcessImpl

protected void endProcessImpl()
                       throws Exception
End the loading process.

Overrides:
endProcessImpl in class CustomLineListener
Throws:
Exception
See Also:
LineListener.endProcess()

getResultSet

public ResultSet getResultSet()
Get a ResultSet instance that presents the CSV data.


setCsvResultSetClass

public void setCsvResultSetClass(Class pCsvResultSetClass)
Use your own subclass of CsvResultSet for loading CSV data.

You may subclass CsvResultSet so that the CSV data is loaded into your own ResultSet. You will need to provide an empty constructor so that the newInstance method will work. You must also provide, via this method, the class of your ResultSet. Do this like so:

    csvManager.getCsvManagerStore()
      .getResultSetLineListener().setCsvResultSetClass( MyCsvResultSet.class );
  

If subclassing does not fit with your requirements, consider implementing your own variation of CsvResultSet (source) and ResultSetLineListener (source) based on the source code provided as part of this API documentation.

NOTE: this method is deprecated. To provide your own version of CsvResultSet, please subclass ResultSetLineListener directly and set the iCsvResultSetClass member variable to your own subclass of CsvResultSet.

Parameters:
pCsvResultSetClass - class of CsvResultSet subclass
See Also:
CsvResultSet


Copyright © 2003-2006 Ricebridge