| |
|
| net.sf.jasperreports.engine.JRDataSourceProvider
All known Subclasses: net.sf.jasperreports.engine.data.JRCsvDataSourceProvider, net.sf.jasperreports.engine.data.JRAbstractBeanDataSourceProvider,
JRDataSourceProvider | public interface JRDataSourceProvider (Code) | | 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
net.sf.jasperreports.engine.data.JRBeanCollectionDataSource 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
}
}
author: Peter Severin (peter_s@sourceforge.net, contact@jasperassistant.com) version: $Id: JRDataSourceProvider.java 1229 2006-04-19 10:27:35Z teodord $ |
create | public JRDataSource create(JasperReport report) throws JRException(Code) | | 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 | public void dispose(JRDataSource dataSource) throws JRException(Code) | | Disposes the data source previously obtained using the
JRDataSourceProvider.create(JasperReport) 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 JRResultSetDataSource .
Note: The provider must take care of the resource - data source association.
For example in case of the
JRResultSetDataSource 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 |
getFields | public JRField[] getFields(JasperReport report) throws JRException, UnsupportedOperationException(Code) | | 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. a non null fields array. If there are no fields then an empty array must be returned. throws: UnsupportedOperationException - is the method is not supported throws: JRException - if an error occurs. |
supportsGetFieldsOperation | public boolean supportsGetFieldsOperation()(Code) | | Returns true if the provider supports the
JRDataSourceProvider.getFields(JasperReport) 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.
true if the getFields() operation is supported. |
|
|
|