001: /**
002: * ========================================
003: * JFreeReport : a free Java report library
004: * ========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either 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, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * $Id: AbstractReportProcessor.java 3048 2007-07-28 18:02:42Z tmorgner $
027: * ------------
028: * (C) Copyright 2000-2005, by Object Refinery Limited.
029: * (C) Copyright 2005-2007, by Pentaho Corporation.
030: */package org.jfree.report.flow;
031:
032: import org.jfree.formula.DefaultFormulaContext;
033: import org.jfree.report.DataSourceException;
034: import org.jfree.report.ReportDataFactoryException;
035: import org.jfree.report.ReportProcessingException;
036: import org.jfree.report.data.ReportContextImpl;
037: import org.jfree.report.flow.layoutprocessor.DefaultLayoutControllerFactory;
038: import org.jfree.report.flow.layoutprocessor.LayoutController;
039: import org.jfree.report.flow.layoutprocessor.LayoutControllerFactory;
040:
041: /**
042: * Creation-Date: 10.11.2006, 16:07:26
043: *
044: * @author Thomas Morgner
045: */
046: public abstract class AbstractReportProcessor implements
047: ReportProcessor {
048: protected AbstractReportProcessor() {
049: }
050:
051: protected void processReportRun(final ReportJob job,
052: final ReportTarget target)
053: throws ReportDataFactoryException, DataSourceException,
054: ReportProcessingException {
055: synchronized (job) {
056: final ReportContext context = createReportContext(job,
057: target);
058: final LayoutControllerFactory layoutFactory = context
059: .getLayoutControllerFactory();
060: // we have the data and we have our position inside the report.
061: // lets generate something ...
062: final FlowController flowController = createFlowControler(
063: context, job);
064:
065: LayoutController layoutController = layoutFactory.create(
066: flowController, job.getReportStructureRoot(), null);
067:
068: while (layoutController.isAdvanceable()) {
069: layoutController = layoutController.advance(target);
070: while (layoutController.isAdvanceable() == false
071: && layoutController.getParent() != null) {
072: final LayoutController parent = layoutController
073: .getParent();
074: target.commit();
075: layoutController = parent.join(layoutController
076: .getFlowController());
077: }
078: }
079: target.commit();
080: }
081: }
082:
083: protected ReportContext createReportContext(final ReportJob job,
084: final ReportTarget target) {
085: final ReportContextImpl context = new ReportContextImpl();
086: context.setExportDescriptor(target.getExportDescriptor());
087: final DefaultLayoutControllerFactory lcf = new DefaultLayoutControllerFactory();
088: lcf.initialize(job);
089: context.setLayoutControllerFactory(lcf);
090:
091: final DefaultFormulaContext formulaContext = new DefaultFormulaContext();
092: context.setFormulaContext(formulaContext);
093: context
094: .setResourceBundleFactory(job
095: .getResourceBundleFactory());
096: context.setReportStructureRoot(job.getReportStructureRoot());
097: return context;
098: }
099:
100: protected FlowController createFlowControler(
101: final ReportContext context, final ReportJob job)
102: throws DataSourceException {
103: return new DefaultFlowController(context, job);
104: }
105:
106: }
|