KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JRFillElementDataset


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * 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,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.fill;
29
30 import java.util.TimeZone JavaDoc;
31
32 import net.sf.jasperreports.engine.JRDatasetRun;
33 import net.sf.jasperreports.engine.JRElementDataset;
34 import net.sf.jasperreports.engine.JRException;
35 import net.sf.jasperreports.engine.JRExpression;
36 import net.sf.jasperreports.engine.JRGroup;
37
38
39 /**
40  * @author Teodor Danciu (teodord@users.sourceforge.net)
41  * @version $Id: JRFillElementDataset.java 1533 2006-12-21 19:51:45 +0200 (Thu, 21 Dec 2006) teodord $
42  */

43 public abstract class JRFillElementDataset implements JRElementDataset
44 {
45
46
47     /**
48      *
49      */

50     protected JRElementDataset parent = null;
51     private final JRBaseFiller filler;
52
53     protected JRGroup resetGroup = null;
54     protected JRGroup incrementGroup = null;
55
56     private boolean isIncremented = true;
57
58     protected JRFillDatasetRun datasetRun;
59     private boolean increment = false;
60
61     /**
62      *
63      */

64     protected JRFillElementDataset(
65         JRElementDataset dataset,
66         JRFillObjectFactory factory
67         )
68     {
69         factory.put(dataset, this);
70
71         parent = dataset;
72         filler = factory.getFiller();
73         
74         resetGroup = factory.getGroup(dataset.getResetGroup());
75         incrementGroup = factory.getGroup(dataset.getIncrementGroup());
76         
77         datasetRun = factory.getDatasetRun(dataset.getDatasetRun());
78     }
79
80
81     /**
82      *
83      */

84     public byte getResetType()
85     {
86         return parent.getResetType();
87     }
88         
89     /**
90      *
91      */

92     public byte getIncrementType()
93     {
94         return parent.getIncrementType();
95     }
96         
97     /**
98      *
99      */

100     public JRGroup getResetGroup()
101     {
102         return resetGroup;
103     }
104         
105     /**
106      *
107      */

108     public JRGroup getIncrementGroup()
109     {
110         return incrementGroup;
111     }
112         
113     /**
114      *
115      */

116     protected TimeZone JavaDoc getTimeZone()
117     {
118         return filler.getTimeZone();
119     }
120         
121     /**
122      *
123      */

124     protected void initialize()
125     {
126         customInitialize();
127         isIncremented = false;
128         increment = false;
129     }
130
131     /**
132      *
133      */

134     protected void evaluate(JRCalculator calculator) throws JRExpressionEvalException
135     {
136         evaluateIncrementWhenExpression(calculator);
137         
138         if (increment)
139         {
140             customEvaluate(calculator);
141         }
142
143         isIncremented = false;
144     }
145
146     
147     protected void evaluateIncrementWhenExpression(JRCalculator calculator) throws JRExpressionEvalException
148     {
149         JRExpression incrementWhenExpression = getIncrementWhenExpression();
150         if (incrementWhenExpression == null)
151         {
152             increment = true;
153         }
154         else
155         {
156             Boolean JavaDoc evaluated = (Boolean JavaDoc) calculator.evaluate(incrementWhenExpression);
157             increment = evaluated != null && evaluated.booleanValue();
158         }
159     }
160
161
162     /**
163      *
164      */

165     protected void increment()
166     {
167         if (!isIncremented && increment)
168         {
169             customIncrement();
170         }
171         isIncremented = true;
172     }
173
174
175     /**
176      *
177      */

178     protected abstract void customInitialize();
179
180     /**
181      *
182      */

183     protected abstract void customEvaluate(JRCalculator calculator) throws JRExpressionEvalException;
184
185     /**
186      *
187      */

188     protected abstract void customIncrement();
189
190
191     public JRDatasetRun getDatasetRun()
192     {
193         return datasetRun;
194     }
195     
196     
197     public void evaluateDatasetRun(byte evaluation) throws JRException
198     {
199         if (datasetRun != null)
200         {
201             datasetRun.evaluate(this, evaluation);
202         }
203     }
204     
205     public JRFillDataset getInputDataset()
206     {
207         JRFillDataset inputDataset;
208         if (datasetRun != null)
209         {
210             inputDataset = datasetRun.getDataset();
211         }
212         else
213         {
214             inputDataset = filler.mainDataset;
215         }
216         
217         return inputDataset;
218     }
219
220
221     public JRExpression getIncrementWhenExpression()
222     {
223         return parent.getIncrementWhenExpression();
224     }
225 }
226
Popular Tags