net.sf.jasperreports.engine
Interface JRDataSourceProvider

All Known Implementing Classes:
JRAbstractBeanDataSourceProvider, JRCsvDataSourceProvider

public interface JRDataSourceProvider

Abstracts the means of creating and disposing a data source. This interface is meant to be the standard way to plug custom data sources into GUI designers. Typically the report developer will implement this interface to create and return a configured data source of the desired type and then configure the designer to use this implementation.
The following example demonstrates a provider for a JRBeanCollectionDataSource.

 public class MyBeansDataSource extends JRAbstractBeanDataSourceProvider {
 
        public MyBeansDataSource() {
                super(PersonBean.class);
        }
 
        public JRDataSource create(JasperReport report) throws JRException {
                ArrayList list = new ArrayList();
                list.add(new PersonBean("Teodor"));
                list.add(new PersonBean("Peter"));
                return new JRBeanCollectionDataSource(list);
        }
        
        public void dispose(JRDataSource dataSource) throws JRException {
                // nothing to dispose
        }
 }
 

Version:
$Id: JRDataSourceProvider.java 5180 2012-03-29 13:23:12Z teodord $
Author:
Peter Severin (peter_s@sourceforge.net, contact@jasperassistant.com)

Method Summary
 JRDataSource create(JasperReport report)
          Creates and returns a new instance of the provided data source.
 void dispose(JRDataSource dataSource)
          Disposes the data source previously obtained using the create method.
 JRField[] getFields(JasperReport report)
          Returns the fields that are available from the data source.
 boolean supportsGetFieldsOperation()
          Returns true if the provider supports the getFields operation.
 

Method Detail

supportsGetFieldsOperation

boolean supportsGetFieldsOperation()
Returns true if the provider supports the getFields operation. By returning true in this method the data source provider indicates that it is able to introspect the data source and discover the available fields.

Returns:
true if the getFields() operation is supported.

getFields

JRField[] getFields(JasperReport report)
                    throws JRException,
                           java.lang.UnsupportedOperationException
Returns the fields that are available from the data source. The provider can use the passed in report to extract some additional configuration information such as report properties.

Parameters:
report - the report that will be filled using the data source created by this provider. The passed in report can be null. That means that no compiled report is available yet.
Returns:
a non null fields array. If there are no fields then an empty array must be returned.
Throws:
java.lang.UnsupportedOperationException - is the method is not supported
JRException - if an error occurs.

create

JRDataSource create(JasperReport report)
                    throws JRException
Creates and returns a new instance of the provided data source. The provider can use the passed in report to extract some additional configuration information such as report properties.

Parameters:
report - the report that will be filled using the created data source.
Throws:
JRException - if the data source creation has failed

dispose

void dispose(JRDataSource dataSource)
             throws JRException
Disposes the data source previously obtained using the create method. This method must close any resources associated with the data source. For instance the database connection should be closed in case of the JRResultSetDataSource.
Note: The provider must take care of the resource - data source association. For example in case of the JRResultSetDataSource a subclass of this data source can be created. This subclass will hold the database connection and the prepared statement that were used to obtain the ResultSet. On the time of the dispose these resources can be retrieved from the data source object and closed.

Parameters:
dataSource - the data source to dispose
Throws:
JRException - if the data source could not be disposed


© 2001-2010 Jaspersoft Corporation www.jaspersoft.com