1 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 39 public class JRFillVariable implements JRVariable, JRCalculable 40 { 41 42 43 46 protected JRVariable parent = null; 47 48 51 private JRGroup resetGroup = null; 52 private JRGroup incrementGroup = null; 53 54 57 private Object previousOldValue = null; 58 private Object oldValue = null; 59 private Object estimatedValue = null; 60 private Object incrementedValue = null; 61 private Object value = null; 62 private boolean isInitialized = false; 63 private Object savedValue; 64 65 private JRFillVariable[] helperVariables; 66 67 70 private JRIncrementer incrementer = null; 71 72 73 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 95 public String getName() 96 { 97 return parent.getName(); 98 } 99 100 103 public Class getValueClass() 104 { 105 return parent.getValueClass(); 106 } 107 108 111 public String getValueClassName() 112 { 113 return parent.getValueClassName(); 114 } 115 116 119 public Class getIncrementerFactoryClass() 120 { 121 return parent.getIncrementerFactoryClass(); 122 } 123 124 127 public String getIncrementerFactoryClassName() 128 { 129 return parent.getIncrementerFactoryClassName(); 130 } 131 132 135 public JRExpression getExpression() 136 { 137 return parent.getExpression(); 138 } 139 140 143 public JRExpression getInitialValueExpression() 144 { 145 return parent.getInitialValueExpression(); 146 } 147 148 151 public byte getResetType() 152 { 153 return parent.getResetType(); 154 } 155 156 159 public byte getIncrementType() 160 { 161 return parent.getIncrementType(); 162 } 163 164 167 public byte getCalculation() 168 { 169 return parent.getCalculation(); 170 } 171 172 175 public boolean isSystemDefined() 176 { 177 return parent.isSystemDefined(); 178 } 179 180 183 public JRGroup getResetGroup() 184 { 185 return resetGroup; 186 } 187 188 191 public JRGroup getIncrementGroup() 192 { 193 return incrementGroup; 194 } 195 196 199 public Object getOldValue() 200 { 201 return oldValue; 202 } 203 204 207 public void setOldValue(Object oldValue) 208 { 209 this.oldValue = oldValue; 210 } 211 212 215 public Object getEstimatedValue() 216 { 217 return estimatedValue; 218 } 219 220 223 public void setEstimatedValue(Object estimatedValue) 224 { 225 this.estimatedValue = estimatedValue; 226 } 227 228 231 public Object getIncrementedValue() 232 { 233 return incrementedValue; 234 } 235 236 239 public void setIncrementedValue(Object incrementedValue) 240 { 241 this.incrementedValue = incrementedValue; 242 } 243 244 247 public Object getValue() 248 { 249 return value; 250 } 251 252 255 public void setValue(Object value) 256 { 257 this.value = value; 258 } 259 260 263 public boolean isInitialized() 264 { 265 return isInitialized; 266 } 267 268 271 public void setInitialized(boolean isInitialized) 272 { 273 this.isInitialized = isInitialized; 274 } 275 276 277 280 public JRIncrementer getIncrementer() 281 { 282 if (incrementer == null) 283 { 284 Class 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 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 324 public JRCalculable getHelperVariable(byte type) 325 { 326 return helperVariables[type]; 327 } 328 329 330 public Object getValue(byte evaluation) 331 { 332 Object 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 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 getPreviousOldValue() 387 { 388 return previousOldValue; 389 } 390 391 392 393 public void setPreviousOldValue(Object previousOldValue) 394 { 395 this.previousOldValue = previousOldValue; 396 } 397 } 398 | Popular Tags |