Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 335:e964a3d8f7bc
Some Refactoring work done.
Moved Transition to State
gnv-artifacts/trunk@401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 08 Dec 2009 08:39:03 +0000 |
parents | |
children | a887074460b6 |
comparison
equal
deleted
inserted
replaced
334:e37930705daa | 335:e964a3d8f7bc |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.state; | |
5 | |
6 import java.util.ArrayList; | |
7 import java.util.Collection; | |
8 import java.util.Date; | |
9 import java.util.GregorianCalendar; | |
10 import java.util.HashMap; | |
11 import java.util.HashSet; | |
12 import java.util.Iterator; | |
13 import java.util.List; | |
14 import java.util.Map; | |
15 import java.util.Set; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 import org.w3c.dom.Document; | |
19 import org.w3c.dom.Element; | |
20 import org.w3c.dom.Node; | |
21 import org.w3c.dom.NodeList; | |
22 | |
23 import de.intevation.artifactdatabase.Config; | |
24 import de.intevation.artifacts.CallMeta; | |
25 import de.intevation.gnv.artifacts.GNVArtifactBase; | |
26 import de.intevation.gnv.artifacts.cache.CacheFactory; | |
27 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | |
28 import de.intevation.gnv.geobackend.base.Result; | |
29 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | |
30 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | |
31 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | |
32 import de.intevation.gnv.geobackend.util.DateUtils; | |
33 import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData; | |
34 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | |
35 import de.intevation.gnv.state.describedata.MinMaxDescribeData; | |
36 import de.intevation.gnv.state.describedata.NamedArrayList; | |
37 import de.intevation.gnv.state.describedata.NamedCollection; | |
38 import de.intevation.gnv.state.describedata.SingleValueDescribeData; | |
39 import de.intevation.gnv.state.exception.StateException; | |
40 import de.intevation.gnv.utils.ArtifactXMLUtilities; | |
41 import de.intevation.gnv.utils.InputValidator; | |
42 | |
43 /** | |
44 * @author Tim Englich <tim.englich@intevation.de> | |
45 * | |
46 */ | |
47 public abstract class StateBase implements State { | |
48 | |
49 | |
50 | |
51 /** | |
52 * The UID of this Class | |
53 */ | |
54 private static final long serialVersionUID = 2411169179001645426L; | |
55 | |
56 /** | |
57 * the logger, used to log exceptions and additonaly information | |
58 */ | |
59 private static Logger log = Logger.getLogger(GNVArtifactBase.class); | |
60 | |
61 private final static String MINVALUEFIELDNAME = "minvalue"; | |
62 private final static String MAXVALUEFIELDNAME = "maxvalue"; | |
63 | |
64 private final static String NODATASELECTIONKEY = "n/n"; | |
65 | |
66 private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; | |
67 | |
68 private String id = null; | |
69 | |
70 private String description = null; | |
71 | |
72 protected String dataName = null; | |
73 | |
74 protected boolean dataMultiSelect = false; | |
75 | |
76 protected boolean dataNoSelect = false; | |
77 | |
78 protected String queryID = null; | |
79 | |
80 private Collection<String> reachableStates = null; | |
81 | |
82 protected Collection<String> inputValueNames = null; | |
83 | |
84 private Map<String, InputValue> inputValues = null; | |
85 | |
86 private State parent = null; | |
87 | |
88 protected Map<String, InputData> inputData = null; | |
89 | |
90 | |
91 /** | |
92 * Constructor | |
93 */ | |
94 public StateBase() { | |
95 super(); | |
96 } | |
97 | |
98 /** | |
99 * @see de.intevation.gnv.state.State#getID() | |
100 */ | |
101 public String getID() { | |
102 return this.id; | |
103 } | |
104 | |
105 /** | |
106 * @see de.intevation.gnv.state.State#getDescription() | |
107 */ | |
108 public String getDescription() { | |
109 return this.description; | |
110 } | |
111 | |
112 /** | |
113 * @see de.intevation.gnv.state.State#reachableStates() | |
114 */ | |
115 public Collection<String> reachableStates() { | |
116 | |
117 if (this.couldAlternativeStateUsed()){ | |
118 Iterator<String> it = this.reachableStates.iterator(); | |
119 String transValue = null; | |
120 while (it.hasNext()){ | |
121 transValue = it.next(); | |
122 } | |
123 Collection<String> returnValue = new ArrayList<String>(1); | |
124 returnValue.add(transValue); | |
125 return returnValue; | |
126 }else{ | |
127 return this.reachableStates; | |
128 } | |
129 | |
130 } | |
131 | |
132 /** | |
133 * @return | |
134 */ | |
135 private boolean couldAlternativeStateUsed() { | |
136 // TODO das muss hier noch etwas freier gestaltet werden. | |
137 String key = this.dataName; | |
138 boolean returnValue=this.inputData != null && | |
139 this.inputData.containsKey(key) && | |
140 this.inputData.get(key).getValue(). | |
141 equals(NODATASELECTIONKEY); | |
142 return returnValue; | |
143 } | |
144 | |
145 /** | |
146 * @see de.intevation.gnv.state.State#getRequiredInputValues() | |
147 */ | |
148 public Collection<InputValue> getRequiredInputValues() { | |
149 return this.inputValues.values(); | |
150 } | |
151 | |
152 /** | |
153 * @see de.intevation.gnv.state.State#setup(org.w3c.dom.Node) | |
154 */ | |
155 public void setup(Node configuration) { | |
156 log.debug("StateBase.setup"); | |
157 this.id = ((Element)configuration).getAttribute("id"); | |
158 this.description = ((Element)configuration).getAttribute("description"); | |
159 | |
160 log.info("State-ID = " + this.id); | |
161 NodeList nodes = Config.getNodeSetXPath(configuration, | |
162 "reachablestates/state"); | |
163 this.reachableStates = new ArrayList<String>(nodes.getLength()); | |
164 for (int i = 0; i < nodes.getLength(); i++) { | |
165 String reachableState = nodes.item(i).getTextContent(); | |
166 log.info("ReachableState ==> " + reachableState); | |
167 this.reachableStates.add(reachableState); | |
168 | |
169 } | |
170 | |
171 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, | |
172 "inputvalues/inputvalue"); | |
173 this.inputValues = new HashMap<String, InputValue>(inputValuesNodes | |
174 .getLength()); | |
175 this.inputValueNames = new ArrayList<String>(inputValuesNodes | |
176 .getLength()); | |
177 for (int i = 0; i < inputValuesNodes.getLength(); i++) { | |
178 Element inputValueNode = (Element)inputValuesNodes.item(i); | |
179 String usedinQueryValue = inputValueNode.getAttribute("usedinquery"); | |
180 int usedinQuery = 1; | |
181 if (usedinQueryValue != null) { | |
182 try { | |
183 usedinQuery = Integer.parseInt(usedinQueryValue); | |
184 } catch (NumberFormatException e) { | |
185 log | |
186 .warn("Used in Query Value cannot be transformed into a Number"); | |
187 } | |
188 } | |
189 InputValue inputValue = new DefaultInputValue(inputValueNode.getAttribute("name"), | |
190 inputValueNode.getAttribute("type"), | |
191 Boolean.parseBoolean(inputValueNode. | |
192 getAttribute("multiselect")), usedinQuery); | |
193 log.debug(inputValue.toString()); | |
194 this.inputValues.put(inputValue.getName(), inputValue); | |
195 this.inputValueNames.add(inputValue.getName()); | |
196 } | |
197 | |
198 this.queryID = Config.getStringXPath(configuration, "queryID"); | |
199 log.info("QueryID ==> " + this.queryID); | |
200 | |
201 this.dataName = Config.getStringXPath(configuration, "dataname"); | |
202 | |
203 String dataMultiSelectValue = Config.getStringXPath(configuration, | |
204 "data-multiselect"); | |
205 if (dataMultiSelectValue != null) { | |
206 this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue); | |
207 } | |
208 | |
209 String dataNoSelectValue =Config.getStringXPath(configuration, | |
210 "data-noselect"); | |
211 if (dataNoSelectValue != null) { | |
212 this. dataNoSelect = Boolean.parseBoolean(dataNoSelectValue); | |
213 } | |
214 | |
215 } | |
216 | |
217 /** | |
218 * @see de.intevation.gnv.state.State#getParent() | |
219 */ | |
220 public State getParent() { | |
221 return this.parent; | |
222 } | |
223 | |
224 /** | |
225 * @see de.intevation.gnv.state.State#setParent(de.intevation.gnv.state.State) | |
226 */ | |
227 public void setParent(State state) { | |
228 this.parent = state; | |
229 } | |
230 | |
231 /** | |
232 * @see de.intevation.gnv.state.State#putInputData(java.util.Collection) | |
233 */ | |
234 public void putInputData(Collection<InputData> inputData, String uuid) | |
235 throws StateException { | |
236 log.debug("StateBase.putInputData"); | |
237 if (inputData != null) { | |
238 Iterator<InputData> it = inputData.iterator(); | |
239 InputValidator iv = new InputValidator(); | |
240 while (it.hasNext()) { | |
241 InputData tmpItem = it.next(); | |
242 InputValue inputValue = this.inputValues.get(tmpItem.getName()); | |
243 if (inputValue != null) { | |
244 if (this.inputData == null) { | |
245 this.inputData = new HashMap<String, InputData>( | |
246 inputData.size()); | |
247 } | |
248 | |
249 boolean valid = iv.isInputValid(tmpItem.getValue(), | |
250 inputValue.getType()); | |
251 if (valid) { | |
252 if (tmpItem.getName().equals(MINVALUEFIELDNAME)){ | |
253 String minValue = tmpItem.getValue(); | |
254 String maxValue = this.getInputValue4ID(inputData, MAXVALUEFIELDNAME); | |
255 valid = iv.isInputValid(maxValue,inputValue.getType()); | |
256 if (!valid){ | |
257 String errMsg = "Wrong input for " + tmpItem.getValue() | |
258 + " is not an " + inputValue.getType() | |
259 + " Value."; | |
260 log.warn(errMsg); | |
261 throw new StateException(errMsg); | |
262 } | |
263 | |
264 valid = iv.isInputValid(minValue, | |
265 maxValue, | |
266 inputValue.getType()); | |
267 if (!valid){ | |
268 String errMsg = "MaxValue-Input is less than MinValue-Input "; | |
269 log.warn(errMsg); | |
270 throw new StateException(errMsg); | |
271 } | |
272 }else if (tmpItem.getName().equals(MAXVALUEFIELDNAME)){ | |
273 String minValue = this.getInputValue4ID(inputData, MINVALUEFIELDNAME); | |
274 String maxValue = tmpItem.getValue(); | |
275 valid = iv.isInputValid(minValue,inputValue.getType()); | |
276 if (!valid){ | |
277 String errMsg = "Wrong input for " + tmpItem.getValue() | |
278 + " is not an " + inputValue.getType() | |
279 + " Value."; | |
280 log.warn(errMsg); | |
281 throw new StateException(errMsg); | |
282 } | |
283 | |
284 valid = iv.isInputValid(minValue, | |
285 maxValue, | |
286 inputValue.getType()); | |
287 if (!valid){ | |
288 String errMsg = "MaxValue-Input is less than MinValue-Input "; | |
289 log.warn(errMsg); | |
290 throw new StateException(errMsg); | |
291 } | |
292 } | |
293 this.setSelection(tmpItem, uuid); | |
294 this.inputData.put(tmpItem.getName(), tmpItem); | |
295 } else { | |
296 String errMsg = "Wrong input for " + tmpItem.getValue() | |
297 + " is not an " + inputValue.getType() | |
298 + " Value."; | |
299 log.warn(errMsg); | |
300 throw new StateException(errMsg); | |
301 } | |
302 | |
303 } else { | |
304 String errMsg = "No Inputvalue given for Inputdata " | |
305 + tmpItem.getName(); | |
306 log.warn(errMsg + "Value will be ignored"); | |
307 | |
308 } | |
309 } | |
310 } else { | |
311 log.warn("No Inputdata given"); | |
312 } | |
313 } | |
314 | |
315 private String getInputValue4ID(Collection<InputData> inputData, String inputName){ | |
316 Iterator<InputData> it = inputData.iterator(); | |
317 while (it.hasNext()) { | |
318 InputData tmpItem = it.next(); | |
319 if (tmpItem.getName().equals(inputName)){ | |
320 return tmpItem.getValue(); | |
321 } | |
322 } | |
323 return null; | |
324 } | |
325 | |
326 private void setSelection(InputData inputData, String uuid) { | |
327 log.debug("StateBase.setSelection"); | |
328 | |
329 Object o = this.getDescribeData(inputData.getName(),uuid); | |
330 if (o != null) { | |
331 if (o instanceof Collection<?>) { | |
332 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; | |
333 | |
334 String value = inputData.getValue(); | |
335 String[] selectedValues = value.split(","); | |
336 Set<String> selectedItems = new HashSet<String>( | |
337 selectedValues.length); | |
338 for (int i = 0; i < selectedValues.length; i++) { | |
339 selectedItems.add(selectedValues[i].trim()); | |
340 } | |
341 // Selektion umsetzen | |
342 Iterator<KeyValueDescibeData> it = values.iterator(); | |
343 while (it.hasNext()) { | |
344 KeyValueDescibeData data = it.next(); | |
345 String key = "" + data.getKey(); | |
346 boolean selected = selectedItems.contains(key); | |
347 data.setSelected(selected); | |
348 } | |
349 } else if (o instanceof MinMaxDescribeData) { | |
350 MinMaxDescribeData data = (MinMaxDescribeData) o; | |
351 if (inputData.getName().equals(MINVALUEFIELDNAME)) { | |
352 data.setMinValue(inputData.getValue()); | |
353 } | |
354 if (inputData.getName().equals(MAXVALUEFIELDNAME)) { | |
355 data.setMaxValue(inputData.getValue()); | |
356 } | |
357 } else if (o instanceof SingleValueDescribeData) { | |
358 ((SingleValueDescribeData)o).setValue(inputData.getValue()); | |
359 } | |
360 } | |
361 } | |
362 | |
363 private Object getDescribeData(String name, String uuid) { | |
364 log.debug("StateBase.getDescribeData"); | |
365 Collection<Object> descibeData = this.getDescibeData(uuid); | |
366 if (descibeData != null) { | |
367 Iterator<Object> it = descibeData.iterator(); | |
368 while (it.hasNext()) { | |
369 Object o = it.next(); | |
370 if (o instanceof NamedCollection<?>) { | |
371 if (name.equals(((NamedCollection<?>) o).getName())) { | |
372 return o; | |
373 } | |
374 } else if (o instanceof MinMaxDescribeData) { | |
375 if (name.equals(((MinMaxDescribeData) o).getMinName())) { | |
376 return o; | |
377 } | |
378 if (name.equals(((MinMaxDescribeData) o).getMaxName())) { | |
379 return o; | |
380 } | |
381 }else if (o instanceof SingleValueDescribeData) { | |
382 if (name.equals(((SingleValueDescribeData)o).getName())){ | |
383 return o; | |
384 } | |
385 } | |
386 } | |
387 } | |
388 return null; | |
389 | |
390 } | |
391 | |
392 /** | |
393 * @see de.intevation.gnv.state.State#isStateReachable(java.lang.String) | |
394 */ | |
395 public boolean isStateReachable(String stateID) { | |
396 log.debug("StateBase.isStateReachable"); | |
397 boolean returnValue = false; | |
398 Iterator<String> states = reachableStates.iterator(); | |
399 while (states.hasNext()) { | |
400 if (states.next().equals(stateID)) { | |
401 log.debug("State " + stateID + " wird unterstützt."); | |
402 returnValue = true; | |
403 break; | |
404 } | |
405 } | |
406 return returnValue; | |
407 } | |
408 | |
409 /** | |
410 * @see de.intevation.gnv.state.State#advance(java.lang.String, | |
411 * de.intevation.artifacts.CallMeta) | |
412 */ | |
413 public void advance(String uuid, CallMeta callMeta) | |
414 throws StateException { | |
415 } | |
416 | |
417 public void initialize(String uuid, CallMeta callMeta) | |
418 throws StateException { | |
419 log.debug("StateBase.initialize"); | |
420 try { | |
421 String[] filterValues = this | |
422 .generateFilterValuesFromInputData(); | |
423 Collection<Result> result = null; | |
424 try { | |
425 if (this.queryID != null) { | |
426 QueryExecutor queryExecutor = QueryExecutorFactory | |
427 .getInstance().getQueryExecutor(); | |
428 result = queryExecutor.executeQuery(this.queryID, | |
429 filterValues); | |
430 } | |
431 this.purifyResult(result, uuid); | |
432 } catch (RuntimeException e) { | |
433 log.error(e, e); | |
434 } | |
435 } catch (QueryException e) { | |
436 log.error(e, e); | |
437 throw new StateException(e); | |
438 } | |
439 } | |
440 | |
441 /** | |
442 * @return | |
443 */ | |
444 protected String[] generateFilterValuesFromInputData() { | |
445 List<String> list = new ArrayList<String>(); | |
446 Iterator<String> it = this.inputValueNames.iterator(); | |
447 while (it.hasNext()) { | |
448 String value = it.next(); | |
449 InputData data = this.inputData.get(value); | |
450 if (data != null | |
451 && this.inputValues.containsKey(data.getName())) { | |
452 int size = this.inputValues.get(data.getName()) | |
453 .usedInQueries(); | |
454 String type = this.inputValues.get(data.getName()) | |
455 .getType(); | |
456 String requestValue = data.getValue(); | |
457 if (type.equalsIgnoreCase("string")) { | |
458 requestValue = this | |
459 .prepareInputData4DBQuery(requestValue); | |
460 } else if (type.equalsIgnoreCase("date")) { | |
461 requestValue = this | |
462 .prepareInputData4DateDBQuery(requestValue); | |
463 } else if (type.equalsIgnoreCase("coordinate")){ | |
464 requestValue = this | |
465 .prepareInputData4RegionDBQuery(requestValue); | |
466 } | |
467 for (int j = 0; j < size; j++) { | |
468 list.add(requestValue); | |
469 } | |
470 } | |
471 } | |
472 String[] filterValues = list.toArray(new String[0]); | |
473 return filterValues; | |
474 } | |
475 | |
476 protected String prepareInputData4RegionDBQuery(String value){ | |
477 return value; | |
478 } | |
479 | |
480 private String prepareInputData4DateDBQuery(String value) { | |
481 log.debug("StateBase.prepareInputData4DateDBQuery"); | |
482 if (value != null) { | |
483 String[] values = value.split(","); | |
484 String newValue = ""; | |
485 for (int i = 0; i < values.length; i++) { | |
486 if (newValue.length() > 0) { | |
487 newValue = newValue + " , "; | |
488 } | |
489 // TODO JUST HACK FIND A BETTER RESOLUTION | |
490 newValue = newValue + "to_date('" + values[i].trim() | |
491 + "', 'YYYY.MM.DD HH24:MI:SS')"; | |
492 } | |
493 return newValue; | |
494 } | |
495 | |
496 return value; | |
497 } | |
498 | |
499 private String prepareInputData4DBQuery(String value) { | |
500 log.debug("StateBase.prepareInputData4DBQuery"); | |
501 if (value != null) { | |
502 String[] values = value.split(","); | |
503 String newValue = ""; | |
504 for (int i = 0; i < values.length; i++) { | |
505 if (newValue.length() > 0) { | |
506 newValue = newValue + " , "; | |
507 } | |
508 newValue = newValue + "'" + values[i].trim() + "'"; | |
509 } | |
510 return newValue; | |
511 } | |
512 | |
513 return value; | |
514 | |
515 } | |
516 | |
517 /** | |
518 * @param result | |
519 */ | |
520 protected void purifyResult(Collection<Result> result, String uuid) { | |
521 log.debug("StateBase.purifyResult"); | |
522 Collection<Object> describeData = this.getDescibeData(uuid); | |
523 if (describeData == null) { | |
524 describeData = new ArrayList<Object>(); | |
525 } | |
526 NamedCollection<KeyValueDescibeData> keyValueDescibeData = extractKVP(result, "KEY", "VALUE"); | |
527 describeData.add(keyValueDescibeData); | |
528 this.setDescibeData(uuid, describeData); | |
529 } | |
530 | |
531 /** | |
532 * @param result | |
533 * @return | |
534 */ | |
535 protected NamedCollection<KeyValueDescibeData> extractKVP(Collection<Result> result, | |
536 String keyid, | |
537 String valueid) { | |
538 Iterator<Result> rit = result.iterator(); | |
539 int dataSize = (this.dataNoSelect ? result.size()+1 : result.size()); | |
540 | |
541 NamedCollection<KeyValueDescibeData> keyValueDescibeData = new NamedArrayList<KeyValueDescibeData>( | |
542 this.dataName, dataSize); | |
543 keyValueDescibeData.setMultiSelect(this.dataMultiSelect); | |
544 | |
545 if (this.dataNoSelect){ | |
546 keyValueDescibeData.add(new DefaultKeyValueDescribeData(NODATASELECTIONKEY, | |
547 "No Selection")); | |
548 } | |
549 boolean initialized = false; | |
550 int keyPos= 0; | |
551 int valuePos = 1; | |
552 String previousKey = null; | |
553 while (rit.hasNext()) { | |
554 Result resultValue = rit.next(); | |
555 if (!initialized){ | |
556 keyPos = resultValue.getResultDescriptor().getColumnIndex(keyid); | |
557 valuePos = resultValue.getResultDescriptor().getColumnIndex(valueid); | |
558 if (valuePos < 0){ | |
559 valuePos = 1; | |
560 } | |
561 initialized = true; | |
562 } | |
563 String tmpKey = resultValue.getString(keyPos); | |
564 // TODO: HACK da die ARCSDE kein DISTINCT auf räumlichen Anfragen unterstützt. | |
565 if (previousKey == null || !tmpKey.equals(previousKey)){ | |
566 previousKey = tmpKey; | |
567 keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos))); | |
568 } | |
569 } | |
570 return keyValueDescibeData; | |
571 } | |
572 | |
573 /** | |
574 * @see de.intevation.gnv.state.State#describe(org.w3c.dom.Document, | |
575 * org.w3c.dom.Node, de.intevation.artifacts.CallMeta, | |
576 * java.lang.String) | |
577 */ | |
578 public void describe(Document document, Node rootNode, CallMeta callMeta,String uuid) { | |
579 log.debug("StateBase.describe"); | |
580 Collection<Object> descibeData = this.getDescibeData(uuid); | |
581 if (descibeData != null) { | |
582 ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); | |
583 Iterator<Object> it = descibeData.iterator(); | |
584 Node staticNode = xmlutilities.createArtifactElement(document, | |
585 "static"); | |
586 Node dynamic = xmlutilities.createArtifactElement(document, | |
587 "dynamic"); | |
588 rootNode.appendChild(staticNode); | |
589 rootNode.appendChild(dynamic); | |
590 while (it.hasNext()) { | |
591 | |
592 Object o = it.next(); | |
593 if (o instanceof Collection<?>) { | |
594 String name = null; | |
595 boolean multiselect = false; | |
596 if (o instanceof NamedCollection<?>) { | |
597 NamedCollection<?> nc = ((NamedCollection<?>) o); | |
598 name = nc.getName(); | |
599 multiselect = nc.isMultiSelect(); | |
600 } else { | |
601 Object[] names = this.inputValueNames.toArray(); | |
602 name = names[names.length - 1].toString(); | |
603 } | |
604 | |
605 Element selectNode = xmlutilities.createXFormElement( | |
606 document, multiselect ? "select" : "select1"); | |
607 selectNode.setAttribute("ref", name); | |
608 | |
609 Element lableNode = xmlutilities.createXFormElement( | |
610 document, "label"); | |
611 lableNode.setTextContent(RessourceFactory.getInstance() | |
612 .getRessource(callMeta.getLanguages(), name, name)); | |
613 Element choiceNode = xmlutilities.createXFormElement( | |
614 document, "choices"); | |
615 | |
616 Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o; | |
617 Iterator<KeyValueDescibeData> resultIt = values.iterator(); | |
618 while (resultIt.hasNext()) { | |
619 KeyValueDescibeData result = resultIt.next(); | |
620 Element itemNode = xmlutilities.createXFormElement( | |
621 document, "item"); | |
622 | |
623 if (result.isSelected()) { | |
624 itemNode.setAttribute("selected", "true"); | |
625 } | |
626 | |
627 Element choiceLableNode = xmlutilities | |
628 .createXFormElement(document, "label"); | |
629 choiceLableNode.setTextContent(result.getValue()); | |
630 itemNode.appendChild(choiceLableNode); | |
631 | |
632 Element choicValueNode = xmlutilities | |
633 .createXFormElement(document, "value"); | |
634 choicValueNode.setTextContent("" + result.getKey()); | |
635 itemNode.appendChild(choicValueNode); | |
636 choiceNode.appendChild(itemNode); | |
637 } | |
638 selectNode.appendChild(lableNode); | |
639 selectNode.appendChild(choiceNode); | |
640 | |
641 if (!it.hasNext() && this.dataName != null) { | |
642 dynamic.appendChild(selectNode); | |
643 } else { | |
644 staticNode.appendChild(selectNode); | |
645 } | |
646 | |
647 } else if (o instanceof MinMaxDescribeData) { | |
648 MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; | |
649 Object min = minMaxDescibeData.getMinValue(); | |
650 Object max = minMaxDescibeData.getMaxValue(); | |
651 if (min instanceof GregorianCalendar) { | |
652 Date d = ((GregorianCalendar) min).getTime(); | |
653 min = DateUtils.getPatternedDateAmer(d); | |
654 } | |
655 | |
656 if (max instanceof GregorianCalendar) { | |
657 Date d = ((GregorianCalendar) max).getTime(); | |
658 max = DateUtils.getPatternedDateAmer(d); | |
659 } | |
660 | |
661 Element groupNode = xmlutilities.createXFormElement( | |
662 document, "group"); | |
663 groupNode.setAttribute("ref", minMaxDescibeData.getName()); | |
664 Element groupNodeLableNode = xmlutilities | |
665 .createXFormElement(document, "label"); | |
666 groupNodeLableNode.setTextContent(RessourceFactory | |
667 .getInstance().getRessource( | |
668 callMeta.getLanguages(), | |
669 minMaxDescibeData.getName(), | |
670 minMaxDescibeData.getName())); | |
671 groupNode.appendChild(groupNodeLableNode); | |
672 | |
673 Element inputMinNode = xmlutilities.createXFormElement( | |
674 document, "input"); | |
675 inputMinNode.setAttribute("ref", MINVALUEFIELDNAME); | |
676 Element inputMinLableNode = xmlutilities | |
677 .createXFormElement(document, "label"); | |
678 inputMinLableNode.setTextContent(RessourceFactory | |
679 .getInstance().getRessource( | |
680 callMeta.getLanguages(), MINVALUEFIELDNAME, | |
681 MINVALUEFIELDNAME)); | |
682 inputMinNode.appendChild(inputMinLableNode); | |
683 | |
684 Element inputMinValueNode = xmlutilities | |
685 .createXFormElement(document, "value"); | |
686 inputMinValueNode.setTextContent(min.toString()); | |
687 inputMinNode.appendChild(inputMinValueNode); | |
688 | |
689 Element inputMaxNode = xmlutilities.createXFormElement( | |
690 document, "input"); | |
691 inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME); | |
692 Element inputMaxLableNode = xmlutilities | |
693 .createXFormElement(document, "label"); | |
694 inputMaxLableNode.setTextContent(RessourceFactory | |
695 .getInstance().getRessource( | |
696 callMeta.getLanguages(), MAXVALUEFIELDNAME, | |
697 MAXVALUEFIELDNAME)); | |
698 inputMaxNode.appendChild(inputMaxLableNode); | |
699 | |
700 Element inputMaxValueNode = xmlutilities | |
701 .createXFormElement(document, "value"); | |
702 inputMaxValueNode.setTextContent(max.toString()); | |
703 inputMaxNode.appendChild(inputMaxValueNode); | |
704 | |
705 groupNode.appendChild(inputMinNode); | |
706 groupNode.appendChild(inputMaxNode); | |
707 | |
708 if (!it.hasNext() && this.dataName != null) { | |
709 dynamic.appendChild(groupNode); | |
710 } else { | |
711 staticNode.appendChild(groupNode); | |
712 } | |
713 } else if (o instanceof SingleValueDescribeData) { | |
714 | |
715 SingleValueDescribeData svdb = (SingleValueDescribeData) o; | |
716 | |
717 Element groupNode = xmlutilities.createXFormElement( | |
718 document, "group"); | |
719 groupNode.setAttribute("ref", svdb.getName()); | |
720 Element groupNodeLableNode = xmlutilities | |
721 .createXFormElement(document, "label"); | |
722 groupNodeLableNode.setTextContent(RessourceFactory | |
723 .getInstance().getRessource( | |
724 callMeta.getLanguages(), | |
725 svdb.getName(), | |
726 svdb.getName())); | |
727 groupNode.appendChild(groupNodeLableNode); | |
728 | |
729 Element inputNode = xmlutilities.createXFormElement( | |
730 document, "input"); | |
731 inputNode.setAttribute("ref", svdb.getName()); | |
732 | |
733 Element inputLableNode = xmlutilities.createXFormElement( | |
734 document, "label"); | |
735 inputLableNode.setTextContent(""); | |
736 inputNode.appendChild(inputLableNode); | |
737 | |
738 Element inputValueNode = xmlutilities.createXFormElement( | |
739 document, "value"); | |
740 inputValueNode.setTextContent(svdb.getValue()); | |
741 inputNode.appendChild(inputValueNode); | |
742 | |
743 groupNode.appendChild(inputNode); | |
744 if (!it.hasNext() && this.dataName != null) { | |
745 dynamic.appendChild(groupNode); | |
746 } else { | |
747 staticNode.appendChild(groupNode); | |
748 } | |
749 } | |
750 | |
751 } | |
752 } | |
753 } | |
754 | |
755 /** | |
756 * @see de.intevation.gnv.state.State#getDescibeData() | |
757 */ | |
758 protected Collection<Object> getDescibeData(String uuid) { | |
759 if (CacheFactory.getInstance().isInitialized()) { | |
760 String key = uuid + DESCRIBEDATAKEY; | |
761 log.debug("Hash for Queryelements: " + key); | |
762 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); | |
763 if (value != null) { | |
764 return (Collection<Object>) (value.getObjectValue()); | |
765 } | |
766 } | |
767 return null; | |
768 } | |
769 | |
770 /** | |
771 * @see de.intevation.gnv.state.State#getDescibeData() | |
772 */ | |
773 protected void setDescibeData(String uuid, Collection<Object> describeData) { | |
774 | |
775 if (CacheFactory.getInstance().isInitialized()) { | |
776 String key = uuid + DESCRIBEDATAKEY; | |
777 log.debug("Hash for Queryelements: " + key); | |
778 CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, describeData)); | |
779 } | |
780 } | |
781 | |
782 /** | |
783 * @see de.intevation.gnv.state.State#getInputData() | |
784 */ | |
785 public Collection<InputData> getInputData() throws StateException { | |
786 return this.inputData != null ? this.inputData.values() : null; | |
787 } | |
788 } |