01: /**
02: * ========================================
03: * JFreeReport : a free Java report library
04: * ========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
09: *
10: * This library is free software; you can redistribute it and/or modify it under the terms
11: * of the GNU Lesser General Public License as published by the Free Software Foundation;
12: * either version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16: * See the GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License along with this
19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: *
22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23: * in the United States and other countries.]
24: *
25: * ------------
26: * $Id: StreamingReportProcessor.java 3048 2007-07-28 18:02:42Z tmorgner $
27: * ------------
28: * (C) Copyright 2000-2005, by Object Refinery Limited.
29: * (C) Copyright 2005-2007, by Pentaho Corporation.
30: */package org.jfree.report.flow.streaming;
31:
32: import org.jfree.layouting.DefaultLayoutProcess;
33: import org.jfree.layouting.LayoutProcess;
34: import org.jfree.layouting.output.OutputProcessor;
35: import org.jfree.report.DataSourceException;
36: import org.jfree.report.ReportDataFactoryException;
37: import org.jfree.report.ReportProcessingException;
38: import org.jfree.report.flow.AbstractReportProcessor;
39: import org.jfree.report.flow.LibLayoutReportTarget;
40: import org.jfree.report.flow.ReportJob;
41: import org.jfree.resourceloader.ResourceKey;
42: import org.jfree.resourceloader.ResourceManager;
43:
44: /**
45: * This is written to use LibLayout. It will never work with other report
46: * targets.
47: *
48: * @author Thomas Morgner
49: */
50: public class StreamingReportProcessor extends AbstractReportProcessor {
51: private OutputProcessor outputProcessor;
52:
53: public StreamingReportProcessor() {
54: }
55:
56: public OutputProcessor getOutputProcessor() {
57: return outputProcessor;
58: }
59:
60: public void setOutputProcessor(final OutputProcessor outputProcessor) {
61: this .outputProcessor = outputProcessor;
62: }
63:
64: public void processReport(final ReportJob job)
65: throws ReportDataFactoryException, DataSourceException,
66: ReportProcessingException {
67: if (job == null) {
68: throw new NullPointerException();
69: }
70:
71: synchronized (job) {
72: // first, compute the globals
73: processReportRun(job, createTarget(job));
74: // second, paginate (this splits the stream into flows)
75: processReportRun(job, createTarget(job));
76: // third, generate the content.
77: processReportRun(job, createTarget(job));
78: }
79: }
80:
81: protected LibLayoutReportTarget createTarget(final ReportJob job)
82: throws ReportProcessingException {
83: if (outputProcessor == null) {
84: throw new IllegalStateException(
85: "OutputProcessor is invalid.");
86: }
87: final LayoutProcess layoutProcess = new DefaultLayoutProcess(
88: outputProcessor);
89: final ResourceManager resourceManager = job
90: .getReportStructureRoot().getResourceManager();
91: final ResourceKey resourceKey = job.getReportStructureRoot()
92: .getBaseResource();
93:
94: return new LibLayoutReportTarget(job, resourceKey,
95: resourceManager, layoutProcess);
96: }
97: }
|