|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.ricebridge.csvman.LineListenerSupportImpl
com.ricebridge.csvman.CustomLineListener
com.ricebridge.csvman.BeanLineListener
Implementation of LineListener that stores data records as
a List of Java Beans.
This class is used to implement the
loadBeans(Object,LineSpec,BeanSpec)
method in CsvManager.
Data records are stored in new instances of Java Bean objects by calling the
set property 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.
BeanLineListener is designed to be subclassed. You can change
the default implementation by calling the
CsvManagerStore.setBeanLineListenerClass
method, and providing a subclass of
BeanLineListener. CsvManagerStore can be accessed
using CsvManager.getCsvManagerStore().
The Source Code of this Java class is available under a BSD-style license.
LineListener,
CustomLineListener,
ResultSetLineListener,
AsListsLineListener,
TableModelLineListener,
ResultSetLineListener| Field Summary | |
static boolean |
DEFAULT_Bean_firstLineFieldsAsNeeded
Default value of Bean.firstLineFieldsAsNeeded). |
static boolean |
DEFAULT_Bean_useDefault
Default value of Bean.useDefault (false). |
protected ArrayList |
iBeans
List of beans loaded. |
protected BeanSpec |
iBeanSpec
BeanSpec specification object defining the properties of the beans to load. |
protected String[] |
iFieldNames
The names of the data fields, corresponding to the names of the Java Bean property methods. |
protected boolean |
iFirstLineFieldsAsNeeded
Specify that the first line of the CSV file contains the Java Bean field names. |
protected LineSpec |
iLineSpec
Description of the data fields. |
protected boolean |
iUseDefault
If a data field is empty, use the default value of the property for that field data type. |
static String |
PROP_Bean_firstLineFieldsAsNeeded
Specify that the first line of the CSV file contains the Java Bean field names. |
static String |
PROP_Bean_useDefault
Specify that empty data fields have the default value for their data type (name for CsvSpec.setProperty: Bean.useDefault). |
| Constructor Summary | |
BeanLineListener()
|
|
| Method Summary | |
List |
getBeans()
Get the data records as List of Java Bean objects. |
protected BadLine |
handleBean(Object pBean)
Store a bean object in the list of beans. |
BadLine |
handleLineImpl(String[] pLine,
int pNumFields,
long pLineNumber,
String pOriginalLine)
Convert the data line String[] in a Java Bean instance and store it in a list. |
protected Object |
makeBean(String[] pLine)
Create a new instance of the bean specified by the BeanSpec
and set the bean properties data from the data line String[] array. |
protected String[] |
makeFieldNames(String[] pLine,
int pNumFields)
Interpret the first line of data as the property field names. |
protected Object |
newBean(Class pBeanClass,
String[] pLine)
Create a new instance of the Java Bean object. |
void |
setBeanSpec(BeanSpec pBeanSpec)
Set the BeanSpec object that defines the beans to load. |
protected void |
setCsvSpecImpl(CsvSpec pCsvSpec)
Handle property settings for loading Java Beans. |
protected void |
setLineSpecImpl(LineSpec pLineSpec)
Use the LineSpec to map data fields to Java Bean methods. |
protected void |
startProcessImpl()
Start the load process. |
String |
toString()
Return a textual description suitable for debugging. |
| Methods inherited from class com.ricebridge.csvman.CustomLineListener |
endProcessImpl, handleBadLineImpl |
| 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, wait, wait, wait |
| Field Detail |
public static final String PROP_Bean_useDefault
CsvSpec.setProperty: Bean.useDefault).
public static final boolean DEFAULT_Bean_useDefault
Bean.useDefault (false).
public static final String PROP_Bean_firstLineFieldsAsNeeded
This is only used when no LineSpec has been provided. If a LineSpec has been
provided, this setting is ignored and the first line is assumed to be normal data.
CsvSpec.setProperty: Bean.firstLineFieldsAsNeeded).
public static final boolean DEFAULT_Bean_firstLineFieldsAsNeeded
Bean.firstLineFieldsAsNeeded).
protected ArrayList iBeans
protected BeanSpec iBeanSpec
BeanSpec specification object defining the properties of the beans to load.
protected boolean iUseDefault
protected boolean iFirstLineFieldsAsNeeded
protected LineSpec iLineSpec
protected String[] iFieldNames
| Constructor Detail |
public BeanLineListener()
| Method Detail |
public void setBeanSpec(BeanSpec pBeanSpec)
BeanSpec object that defines the beans to load.
The BeanSpec object contains the definitions of the
bean properties and performs the conversion from String values to internal Java data types.
pBeanSpec - BeanSpec definition of beans to loadpublic List getBeans()
List of Java Bean objects.
List of beanspublic String toString()
protected void setCsvSpecImpl(CsvSpec pCsvSpec)
throws Exception
You can change these using CsvSpec.
The properties you can use here are: PROP_Bean_useDefault and
PROP_Bean_firstLineFieldsAsNeeded.
setCsvSpecImpl in class CustomLineListenerpCsvSpec - CsvSpec object
ExceptionLineListener.setCsvSpec(com.ricebridge.csvman.CsvSpec),
PROP_Bean_useDefault
protected void setLineSpecImpl(LineSpec pLineSpec)
throws Exception
LineSpec to map data fields to Java Bean methods.
setLineSpecImpl in class CustomLineListenerpLineSpec - LineSpec object
ExceptionLineListener.setLineSpec(com.ricebridge.csvman.LineSpec)
protected void startProcessImpl()
throws Exception
Performs some sanity checks on the loading setup.
startProcessImpl in class CustomLineListenerExceptionendProcessImpl
public BadLine handleLineImpl(String[] pLine,
int pNumFields,
long pLineNumber,
String pOriginalLine)
throws Exception
String[] in a Java Bean instance and store it in a list.
handleLineImpl in class CustomLineListenerpLine - String values of data fields in linepNumFields - Number of data fields actually found on the current linepLineNumber - Count of lines processed so far.pOriginalLine - Text of original data line from data source
null if line is OK, BadLine object if line was bad in some way
ExceptionLineListener.handleLine(java.lang.String[], int, long, java.lang.String)protected BadLine handleBean(Object pBean)
pBean - bean objectprotected Object makeBean(String[] pLine)
BeanSpec
and set the bean properties data from the data line String[] array.
pLine - record data
protected Object newBean(Class pBeanClass,
String[] pLine)
pBeanClass - class of bean to createpLine - current data line
protected String[] makeFieldNames(String[] pLine,
int pNumFields)
These names will be used to identify the get and set method names for each data field. The names will be capitalised if necessary.
pLine - header line of data, containing field namespNumFields - number of actual fields, may be less than pLine.length
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||