comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java @ 796:a5526908f92f

Added javadoc in state package. gnv-artifacts/trunk@878 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 01 Apr 2010 09:15:36 +0000
parents c4156275c1e1
children feae2f9d6c6f
comparison
equal deleted inserted replaced
795:cdade5005cba 796:a5526908f92f
42 import org.w3c.dom.Element; 42 import org.w3c.dom.Element;
43 import org.w3c.dom.Node; 43 import org.w3c.dom.Node;
44 import org.w3c.dom.NodeList; 44 import org.w3c.dom.NodeList;
45 45
46 /** 46 /**
47 * This is the default implementation of <code>OutputState</code>. Artifacts
48 * having reached this state or a subclass of this state are able to produce
49 * some output (e.g. chart, histograms, statistic, etc).
50 *
47 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> 51 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
48 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 52 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
49 * 53 *
50 */ 54 */
51 public abstract class OutputStateBase 55 public abstract class OutputStateBase
52 extends StateBase 56 extends StateBase
53 implements OutputState 57 implements OutputState
54 { 58 {
59 /**
60 *
61 */
55 public static final String XPATH_OUTPUT_MODE = 62 public static final String XPATH_OUTPUT_MODE =
56 "/art:action/art:out/@name"; 63 "/art:action/art:out/@name";
57 64
65 /**
66 *
67 */
58 public static final String XPATH_EXPORT_MODE = 68 public static final String XPATH_EXPORT_MODE =
59 "/art:action/art:out/art:export/@name"; 69 "/art:action/art:out/art:export/@name";
60 70
71 /**
72 *
73 */
61 public static final String XPATH_MIME_TYPE = 74 public static final String XPATH_MIME_TYPE =
62 "/art:action/art:out/art:mime-type/@value"; 75 "/art:action/art:out/art:mime-type/@value";
63 76
77 /**
78 *
79 */
64 public static final String XPATH_EXPORTS = 80 public static final String XPATH_EXPORTS =
65 "exportModes/export"; 81 "exportModes/export";
66 82
67 /** 83 /**
68 * The UID of this Class 84 * The UID of this Class
77 /** 93 /**
78 * The different Outputmodes which are provided by an OutputState 94 * The different Outputmodes which are provided by an OutputState
79 */ 95 */
80 protected Collection<OutputMode> outputModes = null; 96 protected Collection<OutputMode> outputModes = null;
81 97
98 /**
99 *
100 */
82 protected String queryODVID = null; 101 protected String queryODVID = null;
83 102
84 /** 103 /**
85 * Constructor 104 * Constructor
86 */ 105 */
87 public OutputStateBase() { 106 public OutputStateBase() {
88 super(); 107 super();
89 } 108 }
90 109
91 /** 110 /**
92 * @see de.intevation.gnv.state.OutputState#getOutputModes() 111 *
112 * @return
93 */ 113 */
94 public Collection<OutputMode> getOutputModes() { 114 public Collection<OutputMode> getOutputModes() {
95 log.debug("OutputStateBase.getOutputModes"); 115 log.debug("OutputStateBase.getOutputModes");
96 return this.outputModes; 116 return this.outputModes;
97 } 117 }
98 118
99 /** 119 /**
100 * @see de.intevation.gnv.state.StateBase#setup(org.w3c.dom.Node) 120 * @param configuration
101 */ 121 */
102 @Override 122 @Override
103 public void setup(Node configuration) { 123 public void setup(Node configuration) {
104 log.debug("OutputStateBase.setup"); 124 log.debug("OutputStateBase.setup");
105 super.setup(configuration); 125 super.setup(configuration);
164 } 184 }
165 } 185 }
166 } 186 }
167 187
168 /** 188 /**
169 * @see de.intevation.gnv.state.StateBase#advance() 189 * @param uuid
190 * @param context
191 * @throws StateException
170 */ 192 */
171 @Override 193 @Override
172 public void advance(String uuid, CallContext context) 194 public void advance(String uuid, CallContext context)
173 throws StateException 195 throws StateException
174 { 196 {
175 } 197 }
176 198
199 /**
200 *
201 * @param uuid
202 * @param context
203 * @throws StateException
204 */
177 @Override 205 @Override
178 public void initialize(String uuid, CallContext context) 206 public void initialize(String uuid, CallContext context)
179 throws StateException 207 throws StateException
180 { 208 {
181 } 209 }
182 210
211 /**
212 * This method needs to be defined by concrete subclasses. Nothing is done
213 * here.
214 *
215 * @param format
216 * @param inputData
217 * @param outputStream
218 * @param uuid
219 * @param callMeta
220 * @throws StateException
221 */
183 public void out( 222 public void out(
184 Document format, 223 Document format,
185 Collection<InputData> inputData, 224 Collection<InputData> inputData,
186 OutputStream outputStream, 225 OutputStream outputStream,
187 String uuid, 226 String uuid,
190 throws StateException 229 throws StateException
191 { 230 {
192 } 231 }
193 232
194 /** 233 /**
234 * This method needs to be defined by concrete subclasses. Nothing is done
235 * here.
236 *
237 * @param outputMode
238 * @param inputData
239 * @param outputStream
240 * @throws StateException
195 * @see de.intevation.gnv.state.OutputState#out(java.lang.String, 241 * @see de.intevation.gnv.state.OutputState#out(java.lang.String,
196 * java.util.Collection, java.io.OutputStream) 242 * java.util.Collection, java.io.OutputStream)
197 */ 243 */
198 public void out(String outputMode, Collection<InputData> inputData, 244 public void out(String outputMode, Collection<InputData> inputData,
199 OutputStream outputStream) throws StateException { 245 OutputStream outputStream) throws StateException {
200 } 246 }
201 247
202 /** 248 /**
203 * @return 249 * Returns the data used to create charts. If a cache is configured, try to
250 * fetch the data from cache. The database is queried if the data is not in
251 * cache yet, or if no cache is configured. If the cache is configured, but
252 * the data is not in cache yet, put it into cache for a faster access
253 * in a later time.
254 *
255 * @param uuid The uuid of an artifact.
256 * @param callContext The CallContext.
257 * @return the chart data.
204 */ 258 */
205 protected Object getChartResult(String uuid, CallContext callContext) { 259 protected Object getChartResult(String uuid, CallContext callContext) {
206 log.debug("OutputStateBase.getChartResult"); 260 log.debug("OutputStateBase.getChartResult");
207 CacheFactory factory = CacheFactory.getInstance(); 261 CacheFactory factory = CacheFactory.getInstance();
208 262
231 log.info("Not using a cache."); 285 log.info("Not using a cache.");
232 return getData(queryID); 286 return getData(queryID);
233 } 287 }
234 } 288 }
235 289
290 /**
291 * This method should no longer be used, because it is not good to put a
292 * chart into cache. Parameter changes done by the user wouldn't be detected
293 * proper.
294 *
295 * @param uuid
296 * @param callContext
297 * @return
298 * @deprecated
299 */
236 protected Object getChartFromCache(String uuid, CallContext callContext) { 300 protected Object getChartFromCache(String uuid, CallContext callContext) {
237 log.debug("Fetch chart [" + uuid + "] from cache"); 301 log.debug("Fetch chart [" + uuid + "] from cache");
238 CacheFactory cacheFactory = CacheFactory.getInstance(); 302 CacheFactory cacheFactory = CacheFactory.getInstance();
239 if (cacheFactory.isInitialized()) { 303 if (cacheFactory.isInitialized()) {
240 String key = "chart_" + getHash(); 304 String key = "chart_" + getHash();
245 } 309 }
246 } 310 }
247 return null; 311 return null;
248 } 312 }
249 313
314 /**
315 * Retrieves the data used to create an ODV export.
316 *
317 * @param uuid
318 * @return odv data.
319 */
250 protected Collection<Result> getODVResult(String uuid) { 320 protected Collection<Result> getODVResult(String uuid) {
251 log.debug("OutputStateBase.getODVResult"); 321 log.debug("OutputStateBase.getODVResult");
252 // TODO add Caching? I think it's not nessessary 322 // TODO add Caching? I think it's not nessessary
253 Collection<Result> returnValue = null; 323 Collection<Result> returnValue = null;
254 if (this.queryODVID != null){ 324 if (this.queryODVID != null){
258 } 328 }
259 return returnValue; 329 return returnValue;
260 } 330 }
261 331
262 /** 332 /**
263 * @param returnValue 333 * Retrieve data from database with help of queryID.
264 * @return 334 *
335 * @param queryID A query id defined in sql statements properties file.
336 * @return some data.
265 */ 337 */
266 protected Collection<Result> getData(String queryID) { 338 protected Collection<Result> getData(String queryID) {
267 log.debug("OutputStateBase.getData"); 339 log.debug("OutputStateBase.getData");
268 Collection<Result> returnValue = null; 340 Collection<Result> returnValue = null;
269 try { 341 try {
280 log.error(e, e); 352 log.error(e, e);
281 } 353 }
282 return returnValue; 354 return returnValue;
283 } 355 }
284 356
357 /**
358 * This method removes the data used for creating charts from cache.
359 *
360 * @param uuid
361 */
285 protected void removeChartResult(String uuid) { 362 protected void removeChartResult(String uuid) {
286 log.debug("OutputStateBase.getChartResult"); 363 log.debug("OutputStateBase.getChartResult");
287 if (CacheFactory.getInstance().isInitialized()) { 364 if (CacheFactory.getInstance().isInitialized()) {
288 String key = "chart_" + getHash(); 365 String key = "chart_" + getHash();
289 log.debug("Hash for Queryelements: " + key); 366 log.debug("Hash for Queryelements: " + key);
292 CacheFactory.getInstance().getCache().remove(key); 369 CacheFactory.getInstance().getCache().remove(key);
293 } 370 }
294 } 371 }
295 } 372 }
296 373
374 /**
375 * This method should no longer be used. It removes a chart from cache.
376 *
377 * @param uuid
378 * @deprecated
379 */
297 protected void removeChart(String uuid) { 380 protected void removeChart(String uuid) {
298 log.debug("OutputStateBase.removeChart from cache"); 381 log.debug("OutputStateBase.removeChart from cache");
299 382
300 CacheFactory cacheFactory = CacheFactory.getInstance(); 383 CacheFactory cacheFactory = CacheFactory.getInstance();
301 if (cacheFactory.isInitialized()) { 384 if (cacheFactory.isInitialized()) {
304 if (object != null) 387 if (object != null)
305 cacheFactory.getCache().remove(key); 388 cacheFactory.getCache().remove(key);
306 } 389 }
307 } 390 }
308 391
392 /**
393 * This is an internal method used while database query.
394 *
395 * @param chart
396 * @param uuid
397 */
309 protected void purifyChart(Object chart, String uuid) { 398 protected void purifyChart(Object chart, String uuid) {
310 log.debug("Prufify chart [" + uuid + "]"); 399 log.debug("Prufify chart [" + uuid + "]");
311 CacheFactory cacheFactory = CacheFactory.getInstance(); 400 CacheFactory cacheFactory = CacheFactory.getInstance();
312 if (cacheFactory.isInitialized()) { 401 if (cacheFactory.isInitialized()) {
313 String key = "chart_" + getHash(); 402 String key = "chart_" + getHash();
314 cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart)); 403 cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart));
315 } 404 }
316 } 405 }
317 406
318 407
408 /**
409 * Use this method to feed a state with new data.
410 *
411 * @param context
412 * @param inputData
413 * @param uuid
414 * @return
415 * @throws StateException
416 */
319 @Override 417 @Override
320 public Document feed( 418 public Document feed(
321 CallContext context, 419 CallContext context,
322 Collection<InputData> inputData, 420 Collection<InputData> inputData,
323 String uuid) 421 String uuid)
327 425
328 return feedSuccess(); 426 return feedSuccess();
329 } 427 }
330 428
331 /** 429 /**
332 * @see de.intevation.gnv.state.StateBase#putInputData(java.util.Collection, java.lang.String) 430 * This method is used to put new data into a next state. The difference
431 * between this method and feed is, that this method should be used to
432 * transfer some old input data required by this state. New data need to be
433 * inserted via feed!
434 *
435 * @param inputData
436 * @param uuid
437 * @throws StateException
333 */ 438 */
334 @Override 439 @Override
440 @SuppressWarnings({"static-access", "static-access", "static-access", "static-access"})
335 public void putInputData(Collection<InputData> inputData, 441 public void putInputData(Collection<InputData> inputData,
336 String uuid) 442 String uuid)
337 throws StateException { 443 throws StateException {
338 log.debug("OutputStateBase.putInputData"); 444 log.debug("OutputStateBase.putInputData");
339 this.removeChartResult(uuid); 445 this.removeChartResult(uuid);
350 if (this.inputData == null) { 456 if (this.inputData == null) {
351 this.inputData = new HashMap<String, InputData>( 457 this.inputData = new HashMap<String, InputData>(
352 inputData.size()); 458 inputData.size());
353 } 459 }
354 460
355 boolean valid = iv.isInputValid(tmpItem.getValue(), 461 @SuppressWarnings("static-access")
462 boolean valid = InputValidator.isInputValid(tmpItem.getValue(),
356 inputValue.getType()); 463 inputValue.getType());
357 if (valid) { 464 if (valid) {
358 if (tmpItem.getName().equals(MINVALUEFIELDNAME)){ 465 if (tmpItem.getName().equals(MINVALUEFIELDNAME)){
359 String minValue = tmpItem.getValue(); 466 String minValue = tmpItem.getValue();
360 String maxValue = getInputValue4ID(inputData, MAXVALUEFIELDNAME); 467 String maxValue = getInputValue4ID(inputData, MAXVALUEFIELDNAME);
361 valid = iv.isInputValid(maxValue,inputValue.getType()); 468 valid = InputValidator.isInputValid(maxValue,inputValue.getType());
362 if (!valid){ 469 if (!valid){
363 String errMsg = "Wrong input for " + tmpItem.getValue() 470 String errMsg = "Wrong input for " + tmpItem.getValue()
364 + " is not an " + inputValue.getType() 471 + " is not an " + inputValue.getType()
365 + " Value."; 472 + " Value.";
366 log.warn(errMsg); 473 log.warn(errMsg);
367 throw new StateException(errMsg); 474 throw new StateException(errMsg);
368 } 475 }
369 476
370 valid = iv.isInputValid(minValue, 477 valid = InputValidator.isInputValid(minValue,
371 maxValue, 478 maxValue,
372 inputValue.getType()); 479 inputValue.getType());
373 if (!valid){ 480 if (!valid){
374 String errMsg = "MaxValue-Input is less than MinValue-Input "; 481 String errMsg = "MaxValue-Input is less than MinValue-Input ";
375 log.warn(errMsg); 482 log.warn(errMsg);
376 throw new StateException(errMsg); 483 throw new StateException(errMsg);
377 } 484 }
378 }else if (tmpItem.getName().equals(MAXVALUEFIELDNAME)){ 485 }else if (tmpItem.getName().equals(MAXVALUEFIELDNAME)){
379 String minValue = getInputValue4ID(inputData, MINVALUEFIELDNAME); 486 String minValue = getInputValue4ID(inputData, MINVALUEFIELDNAME);
380 String maxValue = tmpItem.getValue(); 487 String maxValue = tmpItem.getValue();
381 valid = iv.isInputValid(minValue,inputValue.getType()); 488 valid = InputValidator.isInputValid(minValue,inputValue.getType());
382 if (!valid){ 489 if (!valid){
383 String errMsg = "Wrong input for " + tmpItem.getValue() 490 String errMsg = "Wrong input for " + tmpItem.getValue()
384 + " is not an " + inputValue.getType() 491 + " is not an " + inputValue.getType()
385 + " Value."; 492 + " Value.";
386 log.warn(errMsg); 493 log.warn(errMsg);
387 throw new StateException(errMsg); 494 throw new StateException(errMsg);
388 } 495 }
389 496
390 valid = iv.isInputValid(minValue, 497 valid = InputValidator.isInputValid(minValue,
391 maxValue, 498 maxValue,
392 inputValue.getType()); 499 inputValue.getType());
393 if (!valid){ 500 if (!valid){
394 String errMsg = "MaxValue-Input is less than MinValue-Input "; 501 String errMsg = "MaxValue-Input is less than MinValue-Input ";
395 log.warn(errMsg); 502 log.warn(errMsg);
426 } else { 533 } else {
427 log.warn("No Inputdata given"); 534 log.warn("No Inputdata given");
428 } 535 }
429 } 536 }
430 537
431 public void out(String outputMode, Collection<InputData> inputData, 538 /**
432 OutputStream outputStream, String uuid, CallMeta callMeta) 539 *
433 throws StateException { 540 * @param outputMode
434 } 541 * @param inputData
435 542 * @param outputStream
436 543 * @param uuid
544 * @param callMeta
545 * @throws StateException
546 */
547 public void out(
548 String outputMode,
549 Collection<InputData> inputData,
550 OutputStream outputStream,
551 String uuid,
552 CallMeta callMeta)
553 throws StateException { }
554
555
556 /**
557 * Retrieves a message from resource bundle specified by locale.
558 *
559 * @param locale Locale to use.
560 * @param key The key of the message.
561 * @param value The default value.
562 * @return The value.
563 */
437 protected String getMessage(Locale locale, String key, String value) { 564 protected String getMessage(Locale locale, String key, String value) {
438 return RessourceFactory.getInstance().getRessource( 565 return RessourceFactory.getInstance().getRessource(
439 locale, 566 locale,
440 key, 567 key,
441 value 568 value
442 ); 569 );
443 } 570 }
444 } 571 }
445 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: 572 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org