1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.util.TimeZone ; 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 43 public abstract class JRFillElementDataset implements JRElementDataset 44 { 45 46 47 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 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 84 public byte getResetType() 85 { 86 return parent.getResetType(); 87 } 88 89 92 public byte getIncrementType() 93 { 94 return parent.getIncrementType(); 95 } 96 97 100 public JRGroup getResetGroup() 101 { 102 return resetGroup; 103 } 104 105 108 public JRGroup getIncrementGroup() 109 { 110 return incrementGroup; 111 } 112 113 116 protected TimeZone getTimeZone() 117 { 118 return filler.getTimeZone(); 119 } 120 121 124 protected void initialize() 125 { 126 customInitialize(); 127 isIncremented = false; 128 increment = false; 129 } 130 131 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 evaluated = (Boolean ) calculator.evaluate(incrementWhenExpression); 157 increment = evaluated != null && evaluated.booleanValue(); 158 } 159 } 160 161 162 165 protected void increment() 166 { 167 if (!isIncremented && increment) 168 { 169 customIncrement(); 170 } 171 isIncremented = true; 172 } 173 174 175 178 protected abstract void customInitialize(); 179 180 183 protected abstract void customEvaluate(JRCalculator calculator) throws JRExpressionEvalException; 184 185 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 |