KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sf.jasperreports.engine.JRExpression;
31 import net.sf.jasperreports.engine.JRGroup;
32 import net.sf.jasperreports.engine.JRVariable;
33
34
35 /**
36  * @author Teodor Danciu (teodord@users.sourceforge.net)
37  * @version $Id: JRFillVariable.java 1321 2006-07-03 18:38:02 +0300 (Mon, 03 Jul 2006) lucianc $
38  */

39 public class JRFillVariable implements JRVariable, JRCalculable
40 {
41
42
43     /**
44      *
45      */

46     protected JRVariable parent = null;
47
48     /**
49      *
50      */

51     private JRGroup resetGroup = null;
52     private JRGroup incrementGroup = null;
53
54     /**
55      *
56      */

57     private Object JavaDoc previousOldValue = null;
58     private Object JavaDoc oldValue = null;
59     private Object JavaDoc estimatedValue = null;
60     private Object JavaDoc incrementedValue = null;
61     private Object JavaDoc value = null;
62     private boolean isInitialized = false;
63     private Object JavaDoc savedValue;
64     
65     private JRFillVariable[] helperVariables;
66
67     /**
68      *
69      */

70     private JRIncrementer incrementer = null;
71
72
73     /**
74      *
75      */

76     protected JRFillVariable(
77         JRVariable variable,
78         JRFillObjectFactory factory
79         )
80     {
81         factory.put(variable, this);
82
83         parent = variable;
84         
85         resetGroup = factory.getGroup(variable.getResetGroup());
86         incrementGroup = factory.getGroup(variable.getIncrementGroup());
87         
88         helperVariables = new JRFillVariable[JRCalculable.HELPER_SIZE];
89     }
90
91
92     /**
93      *
94      */

95     public String JavaDoc getName()
96     {
97         return parent.getName();
98     }
99         
100     /**
101      *
102      */

103     public Class JavaDoc getValueClass()
104     {
105         return parent.getValueClass();
106     }
107         
108     /**
109      *
110      */

111     public String JavaDoc getValueClassName()
112     {
113         return parent.getValueClassName();
114     }
115         
116     /**
117      *
118      */

119     public Class JavaDoc getIncrementerFactoryClass()
120     {
121         return parent.getIncrementerFactoryClass();
122     }
123         
124     /**
125      *
126      */

127     public String JavaDoc getIncrementerFactoryClassName()
128     {
129         return parent.getIncrementerFactoryClassName();
130     }
131         
132     /**
133      *
134      */

135     public JRExpression getExpression()
136     {
137         return parent.getExpression();
138     }
139         
140     /**
141      *
142      */

143     public JRExpression getInitialValueExpression()
144     {
145         return parent.getInitialValueExpression();
146     }
147         
148     /**
149      *
150      */

151     public byte getResetType()
152     {
153         return parent.getResetType();
154     }
155         
156     /**
157      *
158      */

159     public byte getIncrementType()
160     {
161         return parent.getIncrementType();
162     }
163         
164     /**
165      *
166      */

167     public byte getCalculation()
168     {
169         return parent.getCalculation();
170     }
171         
172     /**
173      *
174      */

175     public boolean isSystemDefined()
176     {
177         return parent.isSystemDefined();
178     }
179
180     /**
181      *
182      */

183     public JRGroup getResetGroup()
184     {
185         return resetGroup;
186     }
187         
188     /**
189      *
190      */

191     public JRGroup getIncrementGroup()
192     {
193         return incrementGroup;
194     }
195     
196     /**
197      *
198      */

199     public Object JavaDoc getOldValue()
200     {
201         return oldValue;
202     }
203         
204     /**
205      *
206      */

207     public void setOldValue(Object JavaDoc oldValue)
208     {
209         this.oldValue = oldValue;
210     }
211
212     /**
213      *
214      */

215     public Object JavaDoc getEstimatedValue()
216     {
217         return estimatedValue;
218     }
219         
220     /**
221      *
222      */

223     public void setEstimatedValue(Object JavaDoc estimatedValue)
224     {
225         this.estimatedValue = estimatedValue;
226     }
227
228     /**
229      *
230      */

231     public Object JavaDoc getIncrementedValue()
232     {
233         return incrementedValue;
234     }
235         
236     /**
237      *
238      */

239     public void setIncrementedValue(Object JavaDoc incrementedValue)
240     {
241         this.incrementedValue = incrementedValue;
242     }
243
244     /**
245      *
246      */

247     public Object JavaDoc getValue()
248     {
249         return value;
250     }
251         
252     /**
253      *
254      */

255     public void setValue(Object JavaDoc value)
256     {
257         this.value = value;
258     }
259
260     /**
261      *
262      */

263     public boolean isInitialized()
264     {
265         return isInitialized;
266     }
267         
268     /**
269      *
270      */

271     public void setInitialized(boolean isInitialized)
272     {
273         this.isInitialized = isInitialized;
274     }
275
276         
277     /**
278      *
279      */

280     public JRIncrementer getIncrementer()
281     {
282         if (incrementer == null)
283         {
284             Class JavaDoc incrementerFactoryClass = getIncrementerFactoryClass();
285             
286             JRIncrementerFactory incrementerFactory;
287             if (incrementerFactoryClass == null)
288             {
289                 incrementerFactory = JRDefaultIncrementerFactory.getFactory(getValueClass());
290             }
291             else
292             {
293                 incrementerFactory = JRIncrementerFactoryCache.getInstance(incrementerFactoryClass);
294             }
295             
296             incrementer = incrementerFactory.getIncrementer(getCalculation());
297         }
298         
299         return incrementer;
300     }
301
302     
303     /**
304      * Sets a helper variable.
305      *
306      * @param helperVariable the helper variable
307      * @param type the helper type
308      * @return the previous helper variable for the type
309      */

310     public JRFillVariable setHelperVariable(JRFillVariable helperVariable, byte type)
311     {
312         JRFillVariable old = helperVariables[type];
313         helperVariables[type] = helperVariable;
314         return old;
315     }
316     
317     
318     /**
319      * Returns a helper variable.
320      *
321      * @param type the helper type
322      * @return the helper variable for the specified type
323      */

324     public JRCalculable getHelperVariable(byte type)
325     {
326         return helperVariables[type];
327     }
328     
329     
330     public Object JavaDoc getValue(byte evaluation)
331     {
332         Object JavaDoc returnValue;
333         switch (evaluation)
334         {
335             case JRExpression.EVALUATION_OLD:
336                 returnValue = oldValue;
337                 break;
338             case JRExpression.EVALUATION_ESTIMATED:
339                 returnValue = estimatedValue;
340                 break;
341             default:
342                 returnValue = value;
343                 break;
344         }
345         return returnValue;
346     }
347     
348     public void overwriteValue(Object JavaDoc newValue, byte evaluation)
349     {
350         switch (evaluation)
351         {
352             case JRExpression.EVALUATION_OLD:
353                 savedValue = oldValue;
354                 oldValue = newValue;
355                 break;
356             case JRExpression.EVALUATION_ESTIMATED:
357                 savedValue = estimatedValue;
358                 estimatedValue = newValue;
359                 break;
360             default:
361                 savedValue = value;
362                 value = newValue;
363                 break;
364         }
365     }
366     
367     public void restoreValue(byte evaluation)
368     {
369         switch (evaluation)
370         {
371             case JRExpression.EVALUATION_OLD:
372                 oldValue = savedValue;
373                 break;
374             case JRExpression.EVALUATION_ESTIMATED:
375                 estimatedValue = savedValue;
376                 break;
377             default:
378                 value = savedValue;
379                 break;
380         }
381         savedValue = null;
382     }
383
384
385     
386     public Object JavaDoc getPreviousOldValue()
387     {
388         return previousOldValue;
389     }
390
391
392     
393     public void setPreviousOldValue(Object JavaDoc previousOldValue)
394     {
395         this.previousOldValue = previousOldValue;
396     }
397 }
398
Popular Tags