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: FlowReportProcessor.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.flowing;
031:
032: import org.jfree.layouting.ChainingLayoutProcess;
033: import org.jfree.layouting.DefaultLayoutProcess;
034: import org.jfree.layouting.LayoutProcess;
035: import org.jfree.layouting.output.OutputProcessor;
036: import org.jfree.report.DataSourceException;
037: import org.jfree.report.ReportDataFactoryException;
038: import org.jfree.report.ReportProcessingException;
039: import org.jfree.report.flow.AbstractReportProcessor;
040: import org.jfree.report.flow.LibLayoutReportTarget;
041: import org.jfree.report.flow.ReportJob;
042: import org.jfree.resourceloader.ResourceKey;
043: import org.jfree.resourceloader.ResourceManager;
044:
045: /**
046: * This is written to use LibLayout. It will never work with other report
047: * targets.
048: *
049: * @author Thomas Morgner
050: */
051: public class FlowReportProcessor extends AbstractReportProcessor {
052: private OutputProcessor outputProcessor;
053:
054: public FlowReportProcessor() {
055: }
056:
057: public OutputProcessor getOutputProcessor() {
058: return outputProcessor;
059: }
060:
061: public void setOutputProcessor(final OutputProcessor outputProcessor) {
062: this .outputProcessor = outputProcessor;
063: }
064:
065: protected LibLayoutReportTarget createTarget(final ReportJob job) {
066: if (outputProcessor == null) {
067: throw new IllegalStateException(
068: "OutputProcessor is invalid.");
069: }
070: final LayoutProcess layoutProcess = new ChainingLayoutProcess(
071: new DefaultLayoutProcess(outputProcessor));
072: final ResourceManager resourceManager = job
073: .getReportStructureRoot().getResourceManager();
074: final ResourceKey resourceKey = job.getReportStructureRoot()
075: .getBaseResource();
076:
077: return new LibLayoutReportTarget(job, resourceKey,
078: resourceManager, layoutProcess);
079: }
080:
081: /**
082: * Bootstraps the local report processing. This way of executing the report
083: * must be supported by *all* report processor implementations. It should
084: * fully process the complete report.
085: *
086: * @param job
087: * @throws ReportDataFactoryException
088: */
089: public void processReport(final ReportJob job)
090: throws ReportDataFactoryException, DataSourceException,
091: ReportProcessingException {
092: if (job == null) {
093: throw new NullPointerException();
094: }
095:
096: synchronized (job) {
097: // first, compute the globals
098: processReportRun(job, createTarget(job));
099: // second, paginate (this splits the stream into flows)
100: processReportRun(job, createTarget(job));
101: // third, generate the content.
102: processReportRun(job, createTarget(job));
103: }
104: }
105:
106: }
|