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: ContentElementLayoutController.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: */package org.jfree.report.flow.layoutprocessor;
031:
032: import org.jfree.report.DataFlags;
033: import org.jfree.report.DataSourceException;
034: import org.jfree.report.ReportDataFactoryException;
035: import org.jfree.report.ReportProcessingException;
036: import org.jfree.report.data.DefaultDataFlags;
037: import org.jfree.report.expressions.Expression;
038: import org.jfree.report.flow.FlowController;
039: import org.jfree.report.flow.LayoutExpressionRuntime;
040: import org.jfree.report.flow.ReportContext;
041: import org.jfree.report.flow.ReportTarget;
042: import org.jfree.report.structure.ContentElement;
043: import org.jfree.report.structure.Node;
044:
045: /**
046: * Creation-Date: 24.11.2006, 15:06:56
047: *
048: * @author Thomas Morgner
049: */
050: public class ContentElementLayoutController extends
051: ElementLayoutController {
052: public ContentElementLayoutController() {
053: }
054:
055: protected LayoutController processContent(final ReportTarget target)
056: throws DataSourceException, ReportProcessingException,
057: ReportDataFactoryException {
058:
059: final Node node = getElement();
060: final FlowController flowController = getFlowController();
061: final LayoutExpressionRuntime er = LayoutControllerUtil
062: .getExpressionRuntime(flowController, node);
063: final ContentElement element = (ContentElement) node;
064: final Expression ex = element.getValueExpression();
065: final Object value;
066:
067: if (ex != null) {
068: try {
069: ex.setRuntime(er);
070: value = ex.computeValue();
071: } finally {
072: ex.setRuntime(null);
073: }
074: } else {
075: value = null;
076: }
077:
078: // This should be a very rare case indeed ..
079: if (value instanceof DataFlags) {
080: target.processContent((DataFlags) value);
081:
082: final ContentElementLayoutController derived = (ContentElementLayoutController) clone();
083: derived
084: .setProcessingState(ElementLayoutController.FINISHING);
085: derived.setFlowController(flowController);
086: return derived;
087: }
088:
089: if (value instanceof Node) {
090: // we explictly allow structural content here.
091: // As this might be a very expensive thing, if we
092: // keep it in a single state, we continue on a separate state.
093: final Node valueNode = (Node) value;
094: valueNode.updateParent(node.getParent());
095: final ReportContext reportContext = flowController
096: .getReportContext();
097: final LayoutControllerFactory layoutControllerFactory = reportContext
098: .getLayoutControllerFactory();
099:
100: // actually, this is the same as if the element were a
101: // child element of a section. The only difference is
102: // that there can be only one child, and that there is no
103: // direct parent-child direction.
104:
105: final ContentElementLayoutController derived = (ContentElementLayoutController) clone();
106: derived
107: .setProcessingState(ElementLayoutController.WAITING_FOR_JOIN);
108: derived.setFlowController(flowController);
109:
110: return layoutControllerFactory.create(flowController,
111: valueNode, derived);
112: }
113:
114: if (ex != null) {
115: target.processContent(new DefaultDataFlags(ex.getName(),
116: value, true));
117: }
118:
119: final ContentElementLayoutController derived = (ContentElementLayoutController) clone();
120: derived.setProcessingState(ElementLayoutController.FINISHING);
121: derived.setFlowController(flowController);
122: return derived;
123: }
124:
125: /**
126: * Joins with a delegated process flow. This is generally called from a child
127: * flow and should *not* (I mean it!) be called from outside. If you do,
128: * you'll suffer.
129: *
130: * @param flowController the flow controller of the parent.
131: * @return the joined layout controller that incorperates all changes from
132: * the delegate.
133: */
134: public LayoutController join(final FlowController flowController) {
135: final ContentElementLayoutController derived = (ContentElementLayoutController) clone();
136: derived.setProcessingState(ElementLayoutController.FINISHING);
137: derived.setFlowController(flowController);
138: return derived;
139: }
140: }
|