Source for org.jfree.report.flow.layoutprocessor.AbstractLayoutController

   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: AbstractLayoutController.java 3525 2007-10-16 11:43:48Z tmorgner $
  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.layoutprocessor;
  33: 
  34: import org.jfree.report.flow.FlowController;
  35: import org.jfree.report.DataSourceException;
  36: import org.jfree.report.ReportDataFactoryException;
  37: import org.jfree.report.ReportProcessingException;
  38: import org.jfree.util.Log;
  39: 
  40: /**
  41:  * Todo: Document me!
  42:  *
  43:  * @author Thomas Morgner
  44:  * @since 05.03.2007
  45:  */
  46: public abstract class AbstractLayoutController implements LayoutController
  47: {
  48:   private FlowController flowController;
  49:   private LayoutController parent;
  50:   private Object node;
  51:   private boolean initialized;
  52: 
  53:   protected AbstractLayoutController()
  54:   {
  55:   }
  56: 
  57:   /**
  58:    * Retrieves the parent of this layout controller. This allows childs to query
  59:    * their context.
  60:    *
  61:    * @return the layout controller's parent to <code>null</code> if there is no
  62:    * parent.
  63:    */
  64:   public LayoutController getParent()
  65:   {
  66:     return parent;
  67:   }
  68: 
  69: 
  70:   /**
  71:    * Initializes the layout controller. This method is called exactly once. It
  72:    * is the creators responsibility to call this method.
  73:    * <p/>
  74:    * Calling initialize after the first advance must result in a
  75:    * IllegalStateException.
  76:    *
  77:    * @param node           the currently processed object or layout node.
  78:    * @param flowController the current flow controller.
  79:    * @param parent         the parent layout controller that was responsible for
  80:    *                       instantiating this controller.
  81:    * @throws DataSourceException        if there was a problem reading data from
  82:    *                                    the datasource.
  83:    * @throws ReportProcessingException  if there was a general problem during
  84:    *                                    the report processing.
  85:    * @throws ReportDataFactoryException if a query failed.
  86:    */
  87:   public void initialize(final Object node, final FlowController flowController,
  88:                          final LayoutController parent)
  89:       throws DataSourceException, ReportDataFactoryException,
  90:       ReportProcessingException
  91:   {
  92:     if (initialized == true)
  93:     {
  94:       throw new IllegalStateException();
  95:     }
  96: 
  97:     this.initialized = true;
  98:     this.node = node;
  99:     this.flowController = flowController;
 100:     this.parent = parent;
 101:   }
 102: 
 103:   public Object clone()
 104:   {
 105:     try
 106:     {
 107:       return super.clone();
 108:     }
 109:     catch (CloneNotSupportedException e)
 110:     {
 111:       Log.error ("Clone failed where it shouldn't.", e);
 112:       throw new IllegalStateException("Clone failed?");
 113:     }
 114:   }
 115: 
 116: 
 117:   public FlowController getFlowController()
 118:   {
 119:     return flowController;
 120:   }
 121: 
 122: 
 123:   public Object getNode()
 124:   {
 125:     return node;
 126:   }
 127: 
 128: 
 129:   public boolean isInitialized()
 130:   {
 131:     return initialized;
 132:   }
 133: 
 134:   /**
 135:    * Derives a copy of this controller that is suitable to perform a
 136:    * precomputation.
 137:    *
 138:    * @param fc
 139:    * @return
 140:    */
 141:   public LayoutController createPrecomputeInstance(final FlowController fc)
 142:   {
 143:     final AbstractLayoutController lc = (AbstractLayoutController) clone();
 144:     lc.flowController = fc;
 145:     return lc;
 146:   }
 147: }