com.ricebridge.csvman
Class BeanLineProvider

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

public class BeanLineProvider
extends CustomLineProvider

Simple implementation of LineProvider that provides data records for saving a List of Java Beans.

This class is used to implement the saveBeans(Object,LineSpec,BeanSpec,List) methods in CsvManager. Data records are created from Java Bean objects by calling the property get methods of the objects in accordance with the Java Beans specification. Ordinary, boolean and indexed properties are supported. See the BeanSpec documentation for more information.

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

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


Field Summary
static boolean DEFAULT_Bean_saveHeaders
          Default value of Bean.saveHeaders).
static boolean DEFAULT_Bean_useDefault
          Default value of Bean.useDefault).
protected  int iBeanIndex
          Index of current bean in List.
protected  List iBeans
          List of Beans.
protected  BeanSpec iBeanSpec
          BeanSpec specification object defining the properties of the beans to save.
protected  String[] iFieldNames
          The names of the data fields, corresponding to the names of the Java Bean property methods.
protected  LineSpec iLineSpec
          Description of the data fields.
protected  boolean iSaveHeaders
          Output headers as first data line.
protected  boolean iUseDefault
          If a data field is invalid, use the default value of the property for that field data type.
static String PROP_Bean_saveHeaders
          Output headers as first data line (name for CsvSpec.setProperty: Bean.saveHeaders).
static String PROP_Bean_useDefault
          Specify that invalid data fields have the default value for their data type (name for CsvSpec.setProperty: Bean.useDefault).
 
Constructor Summary
BeanLineProvider()
          Create uninitialised for use with setBeans(java.util.List).
BeanLineProvider(List pData)
          Create using a List of Java Beans to save.
 
Method Summary
protected  boolean hasNextLineImpl()
          Check if there are any beans left.
protected  String[] nextLineImpl()
          Return data fields of next bean as a String[] array.
 void setBeans(List pBeans)
          Set the Java Beans to save.
 void setBeanSpec(BeanSpec pBeanSpec)
          Set the BeanSpec object that defines the beans to save.
protected  void setCsvSpecImpl(CsvSpec pCsvSpec)
          Handle property settings for saving Java Beans.
protected  void setLineSpecImpl(LineSpec pLineSpec)
          Set the current LineSpec used for interpreting CSV data fields.
protected  void startProcessImpl()
          Start the load process.
 
Methods inherited from class com.ricebridge.csvman.CustomLineProvider
endProcessImpl
 
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

PROP_Bean_useDefault

public static final String PROP_Bean_useDefault
Specify that invalid data fields have the default value for their data type (name for CsvSpec.setProperty: Bean.useDefault).

See Also:
Constant Field Values

DEFAULT_Bean_useDefault

public static final boolean DEFAULT_Bean_useDefault
Default value of Bean.useDefault).

See Also:
Constant Field Values

PROP_Bean_saveHeaders

public static final String PROP_Bean_saveHeaders
Output headers as first data line (name for CsvSpec.setProperty: Bean.saveHeaders).

See Also:
Constant Field Values

DEFAULT_Bean_saveHeaders

public static final boolean DEFAULT_Bean_saveHeaders
Default value of Bean.saveHeaders).

See Also:
Constant Field Values

iBeans

protected List iBeans
List of Beans.


iBeanIndex

protected int iBeanIndex
Index of current bean in List.


iBeanSpec

protected BeanSpec iBeanSpec
BeanSpec specification object defining the properties of the beans to save.


iUseDefault

protected boolean iUseDefault
If a data field is invalid, use the default value of the property for that field data type.


iSaveHeaders

protected boolean iSaveHeaders
Output headers as first data line.


iLineSpec

protected LineSpec iLineSpec
Description of the data fields.


iFieldNames

protected String[] iFieldNames
The names of the data fields, corresponding to the names of the Java Bean property methods.

Constructor Detail

BeanLineProvider

public BeanLineProvider()
Create uninitialised for use with setBeans(java.util.List).


BeanLineProvider

public BeanLineProvider(List pData)
Create using a List of Java Beans to save.

Method Detail

setBeans

public void setBeans(List pBeans)
Set the Java Beans to save.


setBeanSpec

public void setBeanSpec(BeanSpec pBeanSpec)
Set the BeanSpec object that defines the beans to save.

The BeanSpec object contains the definitions of the bean properties and performs the conversion from internal Java data types to String values.

Parameters:
pBeanSpec - BeanSpec definition of beans to save

setLineSpecImpl

protected void setLineSpecImpl(LineSpec pLineSpec)
                        throws Exception
Description copied from class: CustomLineProvider
Set the current LineSpec used for interpreting CSV data fields.

You can implement this method when you extend CustomLineProvider, but it is not required.

The LineSpec controls the conversion of internal data into individual CSV data fields. Whereas CsvSpec controls the entire process, LineSpec only applies to each data field. In the current version of CSV Manager (1.2), LineSpec is used to load and save Java Beans, by providing the get and set method names for each data field. See BeanLineProvider for more details.

You can subclass LineSpec to add your own data field specific information for your own custom LineProviders. You can then access these settings inside your own LineProvider using the LineSpec object passed into this method.

This method is called after setCsvSpecImpl is called.

Overrides:
setLineSpecImpl in class CustomLineProvider
Parameters:
pLineSpec - LineSpec object
Throws:
Exception
See Also:
LineSpec, setCsvSpecImpl, BeanLineProvider

setCsvSpecImpl

protected void setCsvSpecImpl(CsvSpec pCsvSpec)
                       throws Exception
Handle property settings for saving Java Beans.

You can change these using CsvSpec.

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

startProcessImpl

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

Performs some sanity checks on the saving setup.

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

hasNextLineImpl

protected boolean hasNextLineImpl()
                           throws Exception
Check if there are any beans left.

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

nextLineImpl

protected String[] nextLineImpl()
                         throws Exception
Return data fields of next bean as a String[] array.

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


Copyright © 2003-2006 Ricebridge