Class JRBeanCollectionDataSource

java.lang.Object
net.sf.jasperreports.engine.data.JRAbstractBeanDataSource
net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
All Implemented Interfaces:
JRDataSource, JRRewindableDataSource

public class JRBeanCollectionDataSource extends JRAbstractBeanDataSource
A data source implementation that wraps a collection of JavaBean objects.

It is common to access application data through object persistence layers like EJB, Hibernate, or JDO. Such applications may need to generate reports using data they already have available as arrays or collections of in-memory JavaBean objects.

This JavaBean-compliant data source can be used when data comes in a java.util.Collection of JavaBean objects.

Author:
Teodor Danciu (teodord@users.sourceforge.net)
  • Constructor Details

    • JRBeanCollectionDataSource

      public JRBeanCollectionDataSource(Collection<?> beanCollection)
    • JRBeanCollectionDataSource

      public JRBeanCollectionDataSource(Collection<?> beanCollection, boolean isUseFieldDescription)
  • Method Details

    • next

      public boolean next()
      Description copied from interface: JRDataSource
      Tries to position the cursor on the next element in the data source.
      Returns:
      true if there is a next record, false otherwise
    • getFieldValue

      public Object getFieldValue(JRField field) throws JRException
      Description copied from interface: JRDataSource
      Gets the field value for the current position.
      Returns:
      an object containing the field value. The object type must be the field object type.
      Throws:
      JRException
    • moveFirst

      public void moveFirst()
      Description copied from interface: JRRewindableDataSource
      Moves back to the first element in the data source.
    • getData

      public Collection<?> getData()
      Returns the underlying bean collection used by this data source.
      Returns:
      the underlying bean collection
    • getRecordCount

      public int getRecordCount()
      Returns the total number of records/beans that this data source contains.
      Returns:
      the total number of records of this data source
    • cloneDataSource

      public JRBeanCollectionDataSource cloneDataSource()
      Clones this data source by creating a new instance that reuses the same underlying bean collection.
      Returns:
      a clone of this data source