001: /*
002: * Created on 26/07/2005
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2004 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023: package br.com.gfp.reports;
024:
025: import java.sql.Connection;
026: import java.sql.SQLException;
027: import java.util.Map;
028:
029: import javax.swing.table.TableModel;
030:
031: import net.sf.jasperreports.engine.JRException;
032: import net.sf.jasperreports.engine.JasperFillManager;
033: import net.sf.jasperreports.engine.JasperPrint;
034: import net.sf.jasperreports.engine.data.JRTableModelDataSource;
035: import net.sf.jasperreports.view.JasperViewer;
036: import br.com.gfpshare.db.DataBaseManager;
037: import br.com.gfpshare.plugin.core.DynamicClassLoader;
038:
039: /**
040: * Esta classe é responsável por encotnrar e realizar chamadas
041: * para as classes responsáveis por gerar relatórios.
042: * @author Igor Regis da Silva Simoes
043: * @since 26/07/2005 12:02:33
044: */
045: public class ReportFactory {
046:
047: /**
048: *
049: */
050: public ReportFactory() {
051: super ();
052: }
053:
054: /**
055: * Gera um relatório em uma tela de Preview do JasperReport
056: * @param reportName
057: * @param parametros
058: * @throws JRException
059: * @throws SQLException
060: */
061: public static void makeReport(String reportName, Map parametros)
062: throws JRException, SQLException {
063: Connection connection = DataBaseManager.getDataBaseManager()
064: .getFreeConnection();
065:
066: if (parametros == null)
067: parametros = ParameterProvider.getInstance(reportName)
068: .getParameters();
069:
070: Thread.currentThread().setContextClassLoader(
071: DynamicClassLoader.getClassLoader());
072:
073: JasperPrint relatorio = JasperFillManager.fillReport(
074: DynamicClassLoader.getClassLoader()
075: .getResourceAsStream(
076: "reports/" + reportName + ".jasper"),
077: parametros, connection);
078: JasperViewer.viewReport(relatorio, false);
079:
080: DataBaseManager.getDataBaseManager().liberaConexao(connection);
081: }
082:
083: /**
084: * Gera um relatório em uma tela de Preview do JasperReport usando um table model
085: * @param reportName
086: * @param parametros
087: * @param tableModel
088: * @throws JRException
089: * @throws SQLException
090: */
091: public static void makeReport(String reportName, Map parametros,
092: TableModel tableModel) throws JRException, SQLException {
093: Connection connection = DataBaseManager.getDataBaseManager()
094: .getFreeConnection();
095:
096: if (parametros == null)
097: parametros = ParameterProvider.getInstance(reportName)
098: .getParameters();
099:
100: JasperPrint relatorio = JasperFillManager.fillReport(
101: DynamicClassLoader.getClassLoader()
102: .getResourceAsStream(
103: "reports/" + reportName + ".jasper"),
104: parametros, new JRTableModelDataSource(tableModel));
105: JasperViewer.viewReport(relatorio, false);
106:
107: DataBaseManager.getDataBaseManager().liberaConexao(connection);
108: }
109:
110: }
|