1 28 package net.sf.jasperreports.engine; 29 30 import java.util.Map ; 31 32 import net.sf.jasperreports.engine.fill.JRFillField; 33 import net.sf.jasperreports.engine.fill.JRFillGroup; 34 import net.sf.jasperreports.engine.fill.JRFillParameter; 35 import net.sf.jasperreports.engine.fill.JRFillVariable; 36 37 38 45 public abstract class JRAbstractScriptlet 46 { 47 48 49 52 protected Map parametersMap = null; 53 protected Map fieldsMap = null; 54 protected Map variablesMap = null; 55 protected JRFillGroup[] groups = null; 56 57 58 61 public JRAbstractScriptlet() 62 { 63 } 64 65 66 69 public void setData( 70 Map parsm, 71 Map fldsm, 72 Map varsm, 73 JRFillGroup[] grps 74 ) 75 { 76 parametersMap = parsm; 77 fieldsMap = fldsm; 78 variablesMap = varsm; 79 groups = grps; 80 } 81 82 83 86 public Object getParameterValue(String parameterName) throws JRScriptletException 87 { 88 JRFillParameter parameter = (JRFillParameter)this.parametersMap.get(parameterName); 89 if (parameter == null) 90 { 91 throw new JRScriptletException("Parameter not found : " + parameterName); 92 } 93 return parameter.getValue(); 94 } 95 96 97 100 public Object getFieldValue(String fieldName) throws JRScriptletException 101 { 102 JRFillField field = (JRFillField)this.fieldsMap.get(fieldName); 103 if (field == null) 104 { 105 throw new JRScriptletException("Field not found : " + fieldName); 106 } 107 return field.getValue(); 108 } 109 110 111 114 public Object getVariableValue(String variableName) throws JRScriptletException 115 { 116 JRFillVariable variable = (JRFillVariable)this.variablesMap.get(variableName); 117 if (variable == null) 118 { 119 throw new JRScriptletException("Variable not found : " + variableName); 120 } 121 return variable.getValue(); 122 } 123 124 125 128 public void setVariableValue(String variableName, Object value) throws JRScriptletException 129 { 130 JRFillVariable variable = (JRFillVariable)this.variablesMap.get(variableName); 131 if (variable == null) 132 { 133 throw new JRScriptletException("Variable not found : " + variableName); 134 } 135 136 if (value != null && !variable.getValueClass().isInstance(value) ) 137 { 138 throw new JRScriptletException("Incompatible value assigned to variable " + variableName + ". Expected " + variable.getValueClassName() + "."); 139 } 140 141 variable.setValue(value); 142 } 143 144 145 148 public void callBeforeReportInit() throws JRScriptletException 149 { 150 this.beforeReportInit(); 151 this.beforePageInit(); 152 this.beforeColumnInit(); 153 154 if(groups != null && groups.length > 0) 155 { 156 for(int i = 0; i < groups.length; i++) 157 { 158 this.beforeGroupInit( groups[i].getName() ); 159 } 160 } 161 } 162 163 164 167 public void callAfterReportInit() throws JRScriptletException 168 { 169 if(groups != null && groups.length > 0) 170 { 171 for(int i = groups.length - 1; i >= 0; i--) 172 { 173 this.afterGroupInit( groups[i].getName() ); 174 } 175 } 176 177 this.afterColumnInit(); 178 this.afterPageInit(); 179 this.afterReportInit(); 180 } 181 182 183 186 public void callBeforePageInit() throws JRScriptletException 187 { 188 this.beforePageInit(); 189 this.beforeColumnInit(); 190 } 191 192 193 196 public void callAfterPageInit() throws JRScriptletException 197 { 198 this.afterColumnInit(); 199 this.afterPageInit(); 200 } 201 202 203 206 public void callBeforeColumnInit() throws JRScriptletException 207 { 208 this.beforeColumnInit(); 209 } 210 211 212 215 public void callAfterColumnInit() throws JRScriptletException 216 { 217 this.afterColumnInit(); 218 } 219 220 221 224 public void callBeforeGroupInit() throws JRScriptletException 225 { 226 if(groups != null && groups.length > 0) 227 { 228 JRFillGroup group = null; 229 for(int i = 0; i < groups.length; i++) 230 { 231 group = groups[i]; 232 if (group.hasChanged()) 233 { 234 this.beforeGroupInit(group.getName()); 235 } 236 } 237 } 238 } 239 240 241 244 public void callAfterGroupInit() throws JRScriptletException 245 { 246 if(groups != null && groups.length > 0) 247 { 248 JRFillGroup group = null; 249 for(int i = groups.length - 1; i >= 0; i--) 250 { 251 group = groups[i]; 252 if (group.hasChanged()) 253 { 254 this.afterGroupInit(group.getName()); 255 } 256 } 257 } 258 } 259 260 261 264 public void callBeforeDetailEval() throws JRScriptletException 265 { 266 this.beforeDetailEval(); 267 } 268 269 270 273 public void callAfterDetailEval() throws JRScriptletException 274 { 275 this.afterDetailEval(); 276 } 277 278 279 282 public abstract void beforeReportInit() throws JRScriptletException; 283 284 285 288 public abstract void afterReportInit() throws JRScriptletException; 289 290 291 294 public abstract void beforePageInit() throws JRScriptletException; 295 296 297 300 public abstract void afterPageInit() throws JRScriptletException; 301 302 303 306 public abstract void beforeColumnInit() throws JRScriptletException; 307 308 309 312 public abstract void afterColumnInit() throws JRScriptletException; 313 314 315 319 public abstract void beforeGroupInit(String groupName) throws JRScriptletException; 320 321 322 326 public abstract void afterGroupInit(String groupName) throws JRScriptletException; 327 328 329 332 public abstract void beforeDetailEval() throws JRScriptletException; 333 334 335 338 public abstract void afterDetailEval() throws JRScriptletException; 339 340 341 } 342 | Popular Tags |