Source for org.jfree.report.flow.AbstractReportProcessor

   1: /**
   2:  * ========================================
   3:  * JFreeReport : a free Java report library
   4:  * ========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/
   7:  *
   8:  * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
   9:  *
  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: AbstractReportProcessor.java 2725 2007-04-01 18:49:29Z taqua $
  27:  * ------------
  28:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  29:  * (C) Copyright 2005-2007, by Pentaho Corporation.
  30:  */
  31: 
  32: package org.jfree.report.flow;
  33: 
  34: import org.jfree.formula.DefaultFormulaContext;
  35: import org.jfree.report.DataSourceException;
  36: import org.jfree.report.ReportDataFactoryException;
  37: import org.jfree.report.ReportProcessingException;
  38: import org.jfree.report.data.ReportContextImpl;
  39: import org.jfree.report.flow.layoutprocessor.DefaultLayoutControllerFactory;
  40: import org.jfree.report.flow.layoutprocessor.LayoutController;
  41: import org.jfree.report.flow.layoutprocessor.LayoutControllerFactory;
  42: 
  43: /**
  44:  * Creation-Date: 10.11.2006, 16:07:26
  45:  *
  46:  * @author Thomas Morgner
  47:  */
  48: public abstract class AbstractReportProcessor implements ReportProcessor
  49: {
  50:   protected AbstractReportProcessor()
  51:   {
  52:   }
  53: 
  54:   protected void processReportRun
  55:       (final ReportJob job,
  56:        final ReportTarget target)
  57:       throws ReportDataFactoryException,
  58:       DataSourceException, ReportProcessingException
  59:   {
  60:     synchronized (job)
  61:     {
  62:       final ReportContext context = createReportContext(job, target);
  63:       final LayoutControllerFactory layoutFactory =
  64:           context.getLayoutControllerFactory();
  65:       // we have the data and we have our position inside the report.
  66:       // lets generate something ...
  67:       final FlowController flowController = createFlowControler(context, job);
  68: 
  69:       LayoutController layoutController =
  70:           layoutFactory.create(flowController, job.getReportStructureRoot(), null);
  71: 
  72:       while (layoutController.isAdvanceable())
  73:       {
  74:         layoutController = layoutController.advance(target);
  75:         while (layoutController.isAdvanceable() == false &&
  76:                layoutController.getParent() != null)
  77:         {
  78:           final LayoutController parent = layoutController.getParent();
  79:           target.commit();
  80:           layoutController = parent.join(layoutController.getFlowController());
  81:         }
  82:       }
  83:       target.commit();
  84:     }
  85:   }
  86: 
  87:   protected ReportContext createReportContext (final ReportJob job,
  88:                                                final ReportTarget target)
  89:   {
  90:     final ReportContextImpl context = new ReportContextImpl();
  91:     context.setExportDescriptor(target.getExportDescriptor());
  92:     final DefaultLayoutControllerFactory lcf = new DefaultLayoutControllerFactory();
  93:     lcf.initialize(job);
  94:     context.setLayoutControllerFactory(lcf);
  95: 
  96:     final DefaultFormulaContext formulaContext = new DefaultFormulaContext();
  97:     context.setFormulaContext(formulaContext);
  98:     context.setResourceBundleFactory(job.getResourceBundleFactory());
  99:     context.setReportStructureRoot(job.getReportStructureRoot());
 100:     return context;
 101:   }
 102: 
 103:   protected FlowController createFlowControler(final ReportContext context,
 104:                                                final ReportJob job)
 105:           throws DataSourceException
 106:   {
 107:     return new DefaultFlowController(context, job);
 108:   }
 109: 
 110: }