com.ricebridge.xmlman
Class BeanRecordListener

java.lang.Object
  extended bycom.ricebridge.xmlman.RecordListenerSupport
      extended bycom.ricebridge.xmlman.BeanRecordListener
All Implemented Interfaces:
RecordListener
Direct Known Subclasses:
PerformanceTest.MeasureBeanRecordListener

public class BeanRecordListener
extends RecordListenerSupport

Implementation of RecordListener that stores data records as a List of Java Beans.

This class is used to implement the loadBeans(*,RecordSpec,BeanSpec) methods in XmlManager. Data records are stored in new instances of Java Bean objects by calling the property set 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.

BeanRecordListener is designed to be subclassed. You can change the default implementation by calling the setBeanRecordListenerClass method of XmlManagerStore, and providing a subclass of BeanRecordListener. XmlManagerStore can be accessed using XmlManager.getXmlManagerStore().

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


Field Summary
protected  ArrayList iBeans
          List of beans loaded.
protected  BeanSpec iBeanSpec
          BeanSpec specification object defining the properties of the beans to load.
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_useDefault
          Specify that empty data fields have the default value for their data type (name for XmlSpec.setProperty: Bean.useDefault).
 
Fields inherited from class com.ricebridge.xmlman.RecordListenerSupport
iFieldNames
 
Constructor Summary
BeanRecordListener()
          Constructor with no parameters required for creating new objects in XmlManagerStore.newBeanRecordListener.
 
Method Summary
 List getBeans()
          Get the data records as List of Java Bean objects.
protected  BadRecord handleBean(Object pBean)
          Store a bean object in the list of beans.
protected  BadRecord handleRecordImpl(String[] pRecord, long pRecordNumber)
          Store the data record String[].
protected  Object makeBean(String[] pRecord)
          Create a new instance of the bean specified by the BeanSpec and sets the bean properties data from the record String[] array.
 void setBeanSpec(BeanSpec pBeanSpec)
          Set the BeanSpec object that defines the beans to load.
protected  void setXmlSpecImpl(XmlSpec pXmlSpec)
          Handle property settings for loading Java Bean.
protected  void startProcessImpl()
          Start the load process.
 String toString()
          Return a textual description suitable for debugging.
 
Methods inherited from class com.ricebridge.xmlman.RecordListenerSupport
endProcess, endProcessImpl, handleRecord, setFieldNames, setFieldNamesImpl, setXmlSpec, startProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_Bean_useDefault

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

See Also:
Constant Field Values

iBeans

protected ArrayList iBeans
List of beans loaded.


iBeanSpec

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


iUseDefault

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

Constructor Detail

BeanRecordListener

public BeanRecordListener()
Constructor with no parameters required for creating new objects in XmlManagerStore.newBeanRecordListener.

Method Detail

setBeanSpec

public void setBeanSpec(BeanSpec pBeanSpec)
Set the 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.

Parameters:
pBeanSpec - BeanSpec definition of beans to load

getBeans

public List getBeans()
Get the data records as List of Java Bean objects.

Returns:
List of beans

toString

public String toString()
Return a textual description suitable for debugging.


setXmlSpecImpl

protected void setXmlSpecImpl(XmlSpec pXmlSpec)
Handle property settings for loading Java Bean.

You can change these using XmlSpec.

Overrides:
setXmlSpecImpl in class RecordListenerSupport
Parameters:
pXmlSpec - XML specification
See Also:
RecordListener.setXmlSpec(com.ricebridge.xmlman.XmlSpec), PROP_Bean_useDefault

startProcessImpl

protected void startProcessImpl()
Start the load process.

Performs some sanity checks on the loading setup.

Overrides:
startProcessImpl in class RecordListenerSupport
See Also:
RecordListenerSupport.startProcess(), RecordListener.startProcess()

handleRecordImpl

protected BadRecord handleRecordImpl(String[] pRecord,
                                     long pRecordNumber)
                              throws Exception
Store the data record String[].

Specified by:
handleRecordImpl in class RecordListenerSupport
Parameters:
pRecord - record data as a String[]
pRecordNumber - current count of records
Throws:
Exception
See Also:
RecordListener.handleRecord(java.lang.String[], long)

handleBean

protected BadRecord handleBean(Object pBean)
Store a bean object in the list of beans.

Parameters:
pBean - bean object

makeBean

protected Object makeBean(String[] pRecord)
Create a new instance of the bean specified by the BeanSpec and sets the bean properties data from the record String[] array.

Parameters:
pRecord - record data


Copyright © 2004-2005 Ricebridge