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 net.sf.jasperreports.engine.JRExpression;
031: import net.sf.jasperreports.engine.JRGroup;
032: import net.sf.jasperreports.engine.JRVariable;
033:
034: /**
035: * @author Teodor Danciu (teodord@users.sourceforge.net)
036: * @version $Id: JRFillVariable.java 1321 2006-07-03 15:38:02Z lucianc $
037: */
038: public class JRFillVariable implements JRVariable, JRCalculable {
039:
040: /**
041: *
042: */
043: protected JRVariable parent = null;
044:
045: /**
046: *
047: */
048: private JRGroup resetGroup = null;
049: private JRGroup incrementGroup = null;
050:
051: /**
052: *
053: */
054: private Object previousOldValue = null;
055: private Object oldValue = null;
056: private Object estimatedValue = null;
057: private Object incrementedValue = null;
058: private Object value = null;
059: private boolean isInitialized = false;
060: private Object savedValue;
061:
062: private JRFillVariable[] helperVariables;
063:
064: /**
065: *
066: */
067: private JRIncrementer incrementer = null;
068:
069: /**
070: *
071: */
072: protected JRFillVariable(JRVariable variable,
073: JRFillObjectFactory factory) {
074: factory.put(variable, this );
075:
076: parent = variable;
077:
078: resetGroup = factory.getGroup(variable.getResetGroup());
079: incrementGroup = factory.getGroup(variable.getIncrementGroup());
080:
081: helperVariables = new JRFillVariable[JRCalculable.HELPER_SIZE];
082: }
083:
084: /**
085: *
086: */
087: public String getName() {
088: return parent.getName();
089: }
090:
091: /**
092: *
093: */
094: public Class getValueClass() {
095: return parent.getValueClass();
096: }
097:
098: /**
099: *
100: */
101: public String getValueClassName() {
102: return parent.getValueClassName();
103: }
104:
105: /**
106: *
107: */
108: public Class getIncrementerFactoryClass() {
109: return parent.getIncrementerFactoryClass();
110: }
111:
112: /**
113: *
114: */
115: public String getIncrementerFactoryClassName() {
116: return parent.getIncrementerFactoryClassName();
117: }
118:
119: /**
120: *
121: */
122: public JRExpression getExpression() {
123: return parent.getExpression();
124: }
125:
126: /**
127: *
128: */
129: public JRExpression getInitialValueExpression() {
130: return parent.getInitialValueExpression();
131: }
132:
133: /**
134: *
135: */
136: public byte getResetType() {
137: return parent.getResetType();
138: }
139:
140: /**
141: *
142: */
143: public byte getIncrementType() {
144: return parent.getIncrementType();
145: }
146:
147: /**
148: *
149: */
150: public byte getCalculation() {
151: return parent.getCalculation();
152: }
153:
154: /**
155: *
156: */
157: public boolean isSystemDefined() {
158: return parent.isSystemDefined();
159: }
160:
161: /**
162: *
163: */
164: public JRGroup getResetGroup() {
165: return resetGroup;
166: }
167:
168: /**
169: *
170: */
171: public JRGroup getIncrementGroup() {
172: return incrementGroup;
173: }
174:
175: /**
176: *
177: */
178: public Object getOldValue() {
179: return oldValue;
180: }
181:
182: /**
183: *
184: */
185: public void setOldValue(Object oldValue) {
186: this .oldValue = oldValue;
187: }
188:
189: /**
190: *
191: */
192: public Object getEstimatedValue() {
193: return estimatedValue;
194: }
195:
196: /**
197: *
198: */
199: public void setEstimatedValue(Object estimatedValue) {
200: this .estimatedValue = estimatedValue;
201: }
202:
203: /**
204: *
205: */
206: public Object getIncrementedValue() {
207: return incrementedValue;
208: }
209:
210: /**
211: *
212: */
213: public void setIncrementedValue(Object incrementedValue) {
214: this .incrementedValue = incrementedValue;
215: }
216:
217: /**
218: *
219: */
220: public Object getValue() {
221: return value;
222: }
223:
224: /**
225: *
226: */
227: public void setValue(Object value) {
228: this .value = value;
229: }
230:
231: /**
232: *
233: */
234: public boolean isInitialized() {
235: return isInitialized;
236: }
237:
238: /**
239: *
240: */
241: public void setInitialized(boolean isInitialized) {
242: this .isInitialized = isInitialized;
243: }
244:
245: /**
246: *
247: */
248: public JRIncrementer getIncrementer() {
249: if (incrementer == null) {
250: Class incrementerFactoryClass = getIncrementerFactoryClass();
251:
252: JRIncrementerFactory incrementerFactory;
253: if (incrementerFactoryClass == null) {
254: incrementerFactory = JRDefaultIncrementerFactory
255: .getFactory(getValueClass());
256: } else {
257: incrementerFactory = JRIncrementerFactoryCache
258: .getInstance(incrementerFactoryClass);
259: }
260:
261: incrementer = incrementerFactory
262: .getIncrementer(getCalculation());
263: }
264:
265: return incrementer;
266: }
267:
268: /**
269: * Sets a helper variable.
270: *
271: * @param helperVariable the helper variable
272: * @param type the helper type
273: * @return the previous helper variable for the type
274: */
275: public JRFillVariable setHelperVariable(
276: JRFillVariable helperVariable, byte type) {
277: JRFillVariable old = helperVariables[type];
278: helperVariables[type] = helperVariable;
279: return old;
280: }
281:
282: /**
283: * Returns a helper variable.
284: *
285: * @param type the helper type
286: * @return the helper variable for the specified type
287: */
288: public JRCalculable getHelperVariable(byte type) {
289: return helperVariables[type];
290: }
291:
292: public Object getValue(byte evaluation) {
293: Object returnValue;
294: switch (evaluation) {
295: case JRExpression.EVALUATION_OLD:
296: returnValue = oldValue;
297: break;
298: case JRExpression.EVALUATION_ESTIMATED:
299: returnValue = estimatedValue;
300: break;
301: default:
302: returnValue = value;
303: break;
304: }
305: return returnValue;
306: }
307:
308: public void overwriteValue(Object newValue, byte evaluation) {
309: switch (evaluation) {
310: case JRExpression.EVALUATION_OLD:
311: savedValue = oldValue;
312: oldValue = newValue;
313: break;
314: case JRExpression.EVALUATION_ESTIMATED:
315: savedValue = estimatedValue;
316: estimatedValue = newValue;
317: break;
318: default:
319: savedValue = value;
320: value = newValue;
321: break;
322: }
323: }
324:
325: public void restoreValue(byte evaluation) {
326: switch (evaluation) {
327: case JRExpression.EVALUATION_OLD:
328: oldValue = savedValue;
329: break;
330: case JRExpression.EVALUATION_ESTIMATED:
331: estimatedValue = savedValue;
332: break;
333: default:
334: value = savedValue;
335: break;
336: }
337: savedValue = null;
338: }
339:
340: public Object getPreviousOldValue() {
341: return previousOldValue;
342: }
343:
344: public void setPreviousOldValue(Object previousOldValue) {
345: this.previousOldValue = previousOldValue;
346: }
347: }
|