001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, 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: * ReportDoneHandler.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.states.process;
030:
031: import org.jfree.report.ReportProcessingException;
032: import org.jfree.report.event.ReportEvent;
033: import org.jfree.report.function.Expression;
034: import org.jfree.report.states.FunctionStorageKey;
035: import org.jfree.report.states.ReportState;
036: import org.jfree.report.states.ReportStateKey;
037: import org.jfree.report.states.datarow.DefaultFlowController;
038: import org.jfree.report.states.datarow.ExpressionDataRow;
039: import org.jfree.report.states.datarow.GlobalMasterRow;
040:
041: /**
042: * Creation-Date: 03.07.2007, 13:57:49
043: *
044: * @author Thomas Morgner
045: */
046: public class ReportDoneHandler implements AdvanceHandler {
047: public static final AdvanceHandler HANDLER = new ReportDoneHandler();
048:
049: private ReportDoneHandler() {
050: }
051:
052: public int getEventCode() {
053: return ReportEvent.REPORT_DONE;
054: }
055:
056: public ProcessState advance(final ProcessState state)
057: throws ReportProcessingException {
058: final ProcessState next = state.deriveForAdvance();
059: next.firePrepareEvent();
060: next.fireReportEvent();
061: return next;
062: }
063:
064: public ProcessState commit(final ProcessState state)
065: throws ReportProcessingException {
066: // better clone twice than to face the subtle errors that crawl out here..
067: final ProcessState next = state.deriveForAdvance();
068: final DefaultFlowController flowController = next
069: .getFlowController();
070: final GlobalMasterRow masterRow = flowController.getMasterRow();
071: final ExpressionDataRow expressionDataRow = masterRow
072: .getExpressionDataRow();
073: final Expression[] expressions = expressionDataRow
074: .getExpressions();
075:
076: if (next.isDeepTraversing()) {
077: next.setAdvanceHandler(EndSubReportHandler.HANDLER);
078: } else {
079: next.setAdvanceHandler(EndReportHandler.HANDLER);
080: }
081: final ReportStateKey parentStateKey;
082: final ReportState parentState = next.getParentSubReportState();
083: if (parentState == null) {
084: parentStateKey = null;
085: } else {
086: parentStateKey = parentState.getProcessKey();
087: }
088: next.getFunctionStorage().store(
089: new FunctionStorageKey(parentStateKey, next
090: .getCurrentSubReport()), expressions,
091: expressionDataRow.getColumnCount());
092:
093: final DefaultFlowController pfc = flowController
094: .performClearExportedParameters();
095: final DefaultFlowController efc = pfc.deactivateExpressions();
096: final DefaultFlowController qfc = efc.performReturnFromQuery();
097: next.setFlowController(qfc);
098: return next;
099: }
100:
101: public boolean isFinish() {
102: return false;
103: }
104: }
|