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: AbstractLayoutController.java 3525 2007-10-16 11:43:48Z tmorgner $
027: * ------------
028: * (C) Copyright 2000-2005, by Object Refinery Limited.
029: * (C) Copyright 2005-2007, by Pentaho Corporation.
030: */package org.jfree.report.flow.layoutprocessor;
031:
032: import org.jfree.report.flow.FlowController;
033: import org.jfree.report.DataSourceException;
034: import org.jfree.report.ReportDataFactoryException;
035: import org.jfree.report.ReportProcessingException;
036: import org.jfree.util.Log;
037:
038: /**
039: * Todo: Document me!
040: *
041: * @author Thomas Morgner
042: * @since 05.03.2007
043: */
044: public abstract class AbstractLayoutController implements
045: LayoutController {
046: private FlowController flowController;
047: private LayoutController parent;
048: private Object node;
049: private boolean initialized;
050:
051: protected AbstractLayoutController() {
052: }
053:
054: /**
055: * Retrieves the parent of this layout controller. This allows childs to query
056: * their context.
057: *
058: * @return the layout controller's parent to <code>null</code> if there is no
059: * parent.
060: */
061: public LayoutController getParent() {
062: return parent;
063: }
064:
065: /**
066: * Initializes the layout controller. This method is called exactly once. It
067: * is the creators responsibility to call this method.
068: * <p/>
069: * Calling initialize after the first advance must result in a
070: * IllegalStateException.
071: *
072: * @param node the currently processed object or layout node.
073: * @param flowController the current flow controller.
074: * @param parent the parent layout controller that was responsible for
075: * instantiating this controller.
076: * @throws DataSourceException if there was a problem reading data from
077: * the datasource.
078: * @throws ReportProcessingException if there was a general problem during
079: * the report processing.
080: * @throws ReportDataFactoryException if a query failed.
081: */
082: public void initialize(final Object node,
083: final FlowController flowController,
084: final LayoutController parent) throws DataSourceException,
085: ReportDataFactoryException, ReportProcessingException {
086: if (initialized == true) {
087: throw new IllegalStateException();
088: }
089:
090: this .initialized = true;
091: this .node = node;
092: this .flowController = flowController;
093: this .parent = parent;
094: }
095:
096: public Object clone() {
097: try {
098: return super .clone();
099: } catch (CloneNotSupportedException e) {
100: Log.error("Clone failed where it shouldn't.", e);
101: throw new IllegalStateException("Clone failed?");
102: }
103: }
104:
105: public FlowController getFlowController() {
106: return flowController;
107: }
108:
109: public Object getNode() {
110: return node;
111: }
112:
113: public boolean isInitialized() {
114: return initialized;
115: }
116:
117: /**
118: * Derives a copy of this controller that is suitable to perform a
119: * precomputation.
120: *
121: * @param fc
122: * @return
123: */
124: public LayoutController createPrecomputeInstance(
125: final FlowController fc) {
126: final AbstractLayoutController lc = (AbstractLayoutController) clone();
127: lc.flowController = fc;
128: return lc;
129: }
130: }
|