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