13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Data Sources and Query Executers• Finally, you can filter the accepted parameter types by implementing the supportsQueryParameterType method,which returns true if the class name given as an argument is accepted, and false otherwise.In this implementation, you will not return any built-in parameter, and you will accept all types of parameters (actually, yourquery executer factory ignores any $P{} directives in the query).Here is the code:Code Example 11-10 CustomQueryExecuterFactory source codeimport java.io.File;import java.util.Map;import net.sf.jasperreports.engine.JRDataset;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.query.JRQueryExecuter;import net.sf.jasperreports.engine.query.JRQueryExecuterFactory;/**** @version $Id: CustomQueryExecuterFactory.java 0 2009-12-08 11:45:45 CET gtoffoli $* @author Giulio Toffoli (giulio@jaspersoft.com)**/public class CustomQueryExecuterFactory implements JRQueryExecuterFactory {public Object[] getBuiltinParameters() {return new Object[]{};}public JRQueryExecuter createQueryExecuter(JRDataset jrd, Map map)throws JRException {File directory = null;try {directory = new File(jrd.getQuery().getText());} catch (Exception ex){throw new JRException(ex);}}return new CustomQueryExecuter(directory);}public boolean supportsQueryParameterType(String string) {return true;}The only relevant portion of this implementation is the createQueryExecuter method, which looks into the dataset passedas argument for the query string. We assume that the query is a directory path (remember that our data source lists the filescontained in a specified directory path). With the directory path we instance a CustomQueryExecuter, the class that willmake use of the parsed query (or the File object created starting from the query).If you would like to add support for parameters in the query string, this may be the right place to implement the parameters’parsing and replacement. We have everything we need: the query string, the dataset, and the map with the values of the213

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!