001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.fill;
029:
030: import java.sql.Connection;
031: import java.util.Map;
032:
033: import net.sf.jasperreports.engine.JRDataSource;
034: import net.sf.jasperreports.engine.JRException;
035: import net.sf.jasperreports.engine.JRReport;
036: import net.sf.jasperreports.engine.JasperPrint;
037: import net.sf.jasperreports.engine.JasperReport;
038:
039: /**
040: * @author Teodor Danciu (teodord@users.sourceforge.net)
041: * @version $Id: JRFiller.java 1229 2006-04-19 10:27:35Z teodord $
042: */
043: public abstract class JRFiller {
044:
045: /**
046: *
047: */
048: public static JasperPrint fillReport(JasperReport jasperReport,
049: Map parameters, Connection conn) throws JRException {
050: JRBaseFiller filler = createFiller(jasperReport);
051:
052: JasperPrint jasperPrint = null;
053:
054: try {
055: jasperPrint = filler.fill(parameters, conn);
056: } catch (JRFillInterruptedException e) {
057: throw new JRException(
058: "The report filling thread was interrupted.");
059: }
060:
061: return jasperPrint;
062: }
063:
064: /**
065: *
066: */
067: public static JasperPrint fillReport(JasperReport jasperReport,
068: Map parameters, JRDataSource dataSource) throws JRException {
069: JRBaseFiller filler = createFiller(jasperReport);
070:
071: JasperPrint jasperPrint = null;
072:
073: try {
074: jasperPrint = filler.fill(parameters, dataSource);
075: } catch (JRFillInterruptedException e) {
076: throw new JRException(
077: "The report filling thread was interrupted.");
078: }
079:
080: return jasperPrint;
081: }
082:
083: /**
084: * Fills a report.
085: * <p/>
086: * The data source used to fill the report is determined in the following way:
087: * <ul>
088: * <li>If a non-null value of the {@link net.sf.jasperreports.engine.JRParameter#REPORT_DATA_SOURCE REPORT_DATA_SOURCE}
089: * has been specified, it will be used as data source.</li>
090: * <li>Otherwise, if the report has a query then a data source will be created based on the query and connection
091: * parameter values.</li>
092: * <li>Otherwise, the report will be filled without a data source.</li>
093: * </ul>
094: *
095: * @param jasperReport the report
096: * @param parameters the fill parameters
097: * @return the filled report
098: * @throws JRException
099: */
100: public static JasperPrint fillReport(JasperReport jasperReport,
101: Map parameters) throws JRException {
102: JRBaseFiller filler = createFiller(jasperReport);
103:
104: try {
105: JasperPrint jasperPrint = filler.fill(parameters);
106:
107: return jasperPrint;
108: } catch (JRFillInterruptedException e) {
109: throw new JRException(
110: "The report filling thread was interrupted.");
111: }
112: }
113:
114: public static JRBaseFiller createFiller(JasperReport jasperReport)
115: throws JRException {
116: JRBaseFiller filler = null;
117:
118: switch (jasperReport.getPrintOrder()) {
119: case JRReport.PRINT_ORDER_HORIZONTAL: {
120: filler = new JRHorizontalFiller(jasperReport);
121: break;
122: }
123: case JRReport.PRINT_ORDER_VERTICAL: {
124: filler = new JRVerticalFiller(jasperReport);
125: break;
126: }
127: }
128: return filler;
129: }
130: }
|