com.ricebridge.csvman
Class BasicLineProvider

java.lang.Object
  extended bycom.ricebridge.csvman.LineProviderSupportImpl
      extended bycom.ricebridge.csvman.CustomLineProvider
          extended bycom.ricebridge.csvman.BasicLineProvider
All Implemented Interfaces:
LineProvider

public class BasicLineProvider
extends CustomLineProvider

Simple implementation of LineProvider that provides data lines for saving from a List of String[] arrays.

The easiest way to save your CSV data using this format is to use the CsvManager.save method.

This LineProvider is a good one to use as a template for your own custom LineProviders.

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

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

See Also:
LineProvider, CustomLineProvider, ResultSetLineProvider, AsListsLineProvider, TableModelLineProvider, BeanLineProvider

Field Summary
protected  List iData
          List of String[] arrays.
protected  long iLineIndex
          Index of current line in List.
 
Constructor Summary
BasicLineProvider()
          Create uninitialised for use with setData.
BasicLineProvider(List pData)
          Create with data lines as List of String[] arrays.
 
Method Summary
protected  boolean hasNextLineImpl()
          Return true if line index is less than number of data lines in list.
protected  String[] nextLineImpl()
          Implement this method to supply each data line as it is saved.
 void setData(List pData)
          Set data lines to save as List of String[] arrays.
protected  void startProcessImpl()
          Handle start of saving process by reseting line index.
 
Methods inherited from class com.ricebridge.csvman.CustomLineProvider
endProcessImpl, setCsvSpecImpl, setLineSpecImpl
 
Methods inherited from class com.ricebridge.csvman.LineProviderSupportImpl
endProcess, hasNextLine, nextLine, setCsvSpec, setLineSpec, startProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iData

protected List iData
List of String[] arrays.


iLineIndex

protected long iLineIndex
Index of current line in List.

Constructor Detail

BasicLineProvider

public BasicLineProvider()
Create uninitialised for use with setData.


BasicLineProvider

public BasicLineProvider(List pData)
Create with data lines as List of String[] arrays.

Parameters:
pData - list of lines
Method Detail

startProcessImpl

protected void startProcessImpl()
                         throws Exception
Handle start of saving process by reseting line index.

Overrides:
startProcessImpl in class CustomLineProvider
Throws:
Exception
See Also:
endProcessImpl

hasNextLineImpl

protected boolean hasNextLineImpl()
                           throws Exception
Return true if line index is less than number of data lines in list.

Specified by:
hasNextLineImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.hasNextLine, nextLineImpl

nextLineImpl

protected String[] nextLineImpl()
                         throws Exception
Description copied from class: CustomLineProvider
Implement this method to supply each data line as it is saved.

This method must be implemented when you extend CustomLineProvider.

This method is where you will do the main work of providing the CSV data. Each time this method is called you will need to provide a new line of CSV data as a String[] array.

Error Handling: What happens when you cannot provide the line data for some reason? For example your database connection may fail. In this case, all you have to do is throw an Exception to let CSV Manager know about the problem. But note that if the CsvSpec.setIgnoreBadLines setting is true, then CSV Manager will not stop asking you for more data lines until you also return false from CustomLineProvider.hasNextLineImpl().

Specified by:
nextLineImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.nextLine, hasNextLineImpl

setData

public void setData(List pData)
Set data lines to save as List of String[] arrays.



Copyright © 2003-2006 Ricebridge