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: StreamingReportProcessor.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 */ 031 package org.jfree.report.flow.streaming; 032 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 StreamingReportProcessor extends AbstractReportProcessor 052 { 053 private OutputProcessor outputProcessor; 054 055 public StreamingReportProcessor() 056 { 057 } 058 059 public OutputProcessor getOutputProcessor() 060 { 061 return outputProcessor; 062 } 063 064 public void setOutputProcessor(final OutputProcessor outputProcessor) 065 { 066 this.outputProcessor = outputProcessor; 067 } 068 069 public void processReport(final ReportJob job) 070 throws ReportDataFactoryException, DataSourceException, ReportProcessingException 071 { 072 if (job == null) 073 { 074 throw new NullPointerException(); 075 } 076 077 synchronized (job) 078 { 079 // first, compute the globals 080 processReportRun(job, createTarget(job)); 081 // second, paginate (this splits the stream into flows) 082 processReportRun(job, createTarget(job)); 083 // third, generate the content. 084 processReportRun(job, createTarget(job)); 085 } 086 } 087 088 protected LibLayoutReportTarget createTarget(final ReportJob job) 089 throws ReportProcessingException 090 { 091 if (outputProcessor == null) 092 { 093 throw new IllegalStateException( 094 "OutputProcessor is invalid."); 095 } 096 final LayoutProcess layoutProcess = 097 new DefaultLayoutProcess(outputProcessor); 098 final ResourceManager resourceManager = job.getReportStructureRoot().getResourceManager(); 099 final ResourceKey resourceKey = job.getReportStructureRoot().getBaseResource(); 100 101 return new LibLayoutReportTarget 102 (job, resourceKey, resourceManager, layoutProcess); 103 } 104 }