001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * 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,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.fill;
029:
030: import java.util.TimeZone;
031:
032: import net.sf.jasperreports.engine.JRDatasetRun;
033: import net.sf.jasperreports.engine.JRElementDataset;
034: import net.sf.jasperreports.engine.JRException;
035: import net.sf.jasperreports.engine.JRExpression;
036: import net.sf.jasperreports.engine.JRGroup;
037:
038: /**
039: * @author Teodor Danciu (teodord@users.sourceforge.net)
040: * @version $Id: JRFillElementDataset.java 1533 2006-12-21 17:51:45Z teodord $
041: */
042: public abstract class JRFillElementDataset implements JRElementDataset {
043:
044: /**
045: *
046: */
047: protected JRElementDataset parent = null;
048: private final JRBaseFiller filler;
049:
050: protected JRGroup resetGroup = null;
051: protected JRGroup incrementGroup = null;
052:
053: private boolean isIncremented = true;
054:
055: protected JRFillDatasetRun datasetRun;
056: private boolean increment = false;
057:
058: /**
059: *
060: */
061: protected JRFillElementDataset(JRElementDataset dataset,
062: JRFillObjectFactory factory) {
063: factory.put(dataset, this );
064:
065: parent = dataset;
066: filler = factory.getFiller();
067:
068: resetGroup = factory.getGroup(dataset.getResetGroup());
069: incrementGroup = factory.getGroup(dataset.getIncrementGroup());
070:
071: datasetRun = factory.getDatasetRun(dataset.getDatasetRun());
072: }
073:
074: /**
075: *
076: */
077: public byte getResetType() {
078: return parent.getResetType();
079: }
080:
081: /**
082: *
083: */
084: public byte getIncrementType() {
085: return parent.getIncrementType();
086: }
087:
088: /**
089: *
090: */
091: public JRGroup getResetGroup() {
092: return resetGroup;
093: }
094:
095: /**
096: *
097: */
098: public JRGroup getIncrementGroup() {
099: return incrementGroup;
100: }
101:
102: /**
103: *
104: */
105: protected TimeZone getTimeZone() {
106: return filler.getTimeZone();
107: }
108:
109: /**
110: *
111: */
112: protected void initialize() {
113: customInitialize();
114: isIncremented = false;
115: increment = false;
116: }
117:
118: /**
119: *
120: */
121: protected void evaluate(JRCalculator calculator)
122: throws JRExpressionEvalException {
123: evaluateIncrementWhenExpression(calculator);
124:
125: if (increment) {
126: customEvaluate(calculator);
127: }
128:
129: isIncremented = false;
130: }
131:
132: protected void evaluateIncrementWhenExpression(
133: JRCalculator calculator) throws JRExpressionEvalException {
134: JRExpression incrementWhenExpression = getIncrementWhenExpression();
135: if (incrementWhenExpression == null) {
136: increment = true;
137: } else {
138: Boolean evaluated = (Boolean) calculator
139: .evaluate(incrementWhenExpression);
140: increment = evaluated != null && evaluated.booleanValue();
141: }
142: }
143:
144: /**
145: *
146: */
147: protected void increment() {
148: if (!isIncremented && increment) {
149: customIncrement();
150: }
151: isIncremented = true;
152: }
153:
154: /**
155: *
156: */
157: protected abstract void customInitialize();
158:
159: /**
160: *
161: */
162: protected abstract void customEvaluate(JRCalculator calculator)
163: throws JRExpressionEvalException;
164:
165: /**
166: *
167: */
168: protected abstract void customIncrement();
169:
170: public JRDatasetRun getDatasetRun() {
171: return datasetRun;
172: }
173:
174: public void evaluateDatasetRun(byte evaluation) throws JRException {
175: if (datasetRun != null) {
176: datasetRun.evaluate(this , evaluation);
177: }
178: }
179:
180: public JRFillDataset getInputDataset() {
181: JRFillDataset inputDataset;
182: if (datasetRun != null) {
183: inputDataset = datasetRun.getDataset();
184: } else {
185: inputDataset = filler.mainDataset;
186: }
187:
188: return inputDataset;
189: }
190:
191: public JRExpression getIncrementWhenExpression() {
192: return parent.getIncrementWhenExpression();
193: }
194: }
|