comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 325:3eff9241ea1e

Refactoring of the Transitionmodel. Now each Transition is responsible to allocate the Data which is required to describe or feed it. gnv-artifacts/trunk@390 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 01 Dec 2009 15:58:02 +0000
parents 251f16a083f8
children
comparison
equal deleted inserted replaced
324:e6e172a4915e 325:3eff9241ea1e
44 * @author Tim Englich <tim.englich@intevation.de> 44 * @author Tim Englich <tim.englich@intevation.de>
45 * 45 *
46 */ 46 */
47 public abstract class TransitionBase implements Transition { 47 public abstract class TransitionBase implements Transition {
48 48
49
50
49 /** 51 /**
50 * The UID of this Class 52 * The UID of this Class
51 */ 53 */
52 private static final long serialVersionUID = 2411169179001645426L; 54 private static final long serialVersionUID = 2411169179001645426L;
53 55
74 protected boolean dataNoSelect = false; 76 protected boolean dataNoSelect = false;
75 77
76 protected String queryID = null; 78 protected String queryID = null;
77 79
78 private Collection<String> reachableTransitions = null; 80 private Collection<String> reachableTransitions = null;
79
80 private Transition alternativeTransition = null;
81 81
82 protected Collection<String> inputValueNames = null; 82 protected Collection<String> inputValueNames = null;
83 83
84 private Map<String, InputValue> inputValues = null; 84 private Map<String, InputValue> inputValues = null;
85 85
113 * @see de.intevation.gnv.transition.Transition#reachableTransitions() 113 * @see de.intevation.gnv.transition.Transition#reachableTransitions()
114 */ 114 */
115 public Collection<String> reachableTransitions() { 115 public Collection<String> reachableTransitions() {
116 116
117 if (this.couldAlternativeTransitionUsed()){ 117 if (this.couldAlternativeTransitionUsed()){
118 return this.alternativeTransition.reachableTransitions(); 118 Iterator<String> it = this.reachableTransitions.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;
119 }else{ 126 }else{
120 return this.reachableTransitions; 127 return this.reachableTransitions;
121 } 128 }
122 129
123 } 130 }
125 /** 132 /**
126 * @return 133 * @return
127 */ 134 */
128 private boolean couldAlternativeTransitionUsed() { 135 private boolean couldAlternativeTransitionUsed() {
129 // TODO das muss hier noch etwas freier gestaltet werden. 136 // TODO das muss hier noch etwas freier gestaltet werden.
130 Object[] inputValues = this.inputValueNames.toArray(); 137 String key = this.dataName;
131 String key = (String)inputValues[inputValues.length-1]; 138 boolean returnValue= /*this.alternativeTransition != null &&*/
132 boolean returnValue= this.alternativeTransition != null &&
133 this.inputData != null && 139 this.inputData != null &&
134 this.inputData.containsKey(key) && 140 this.inputData.containsKey(key) &&
135 this.inputData.get(key).getValue(). 141 this.inputData.get(key).getValue().
136 equals(NODATASELECTIONKEY); 142 equals(NODATASELECTIONKEY);
137 return returnValue; 143 return returnValue;
161 log.info("ReachableTransition ==> " + reachableTransition); 167 log.info("ReachableTransition ==> " + reachableTransition);
162 this.reachableTransitions.add(reachableTransition); 168 this.reachableTransitions.add(reachableTransition);
163 169
164 } 170 }
165 171
166 Node alternativeTransitionNode = Config.getNodeXPath(configuration,
167 "alternativeTransition/transition");
168 if (alternativeTransitionNode != null){
169 this.alternativeTransition = TransitionFactory.getInstance()
170 .createTransition(alternativeTransitionNode);
171 }
172 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, 172 NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,
173 "inputvalues/inputvalue"); 173 "inputvalues/inputvalue");
174 this.inputValues = new HashMap<String, InputValue>(inputValuesNodes 174 this.inputValues = new HashMap<String, InputValue>(inputValuesNodes
175 .getLength()); 175 .getLength());
176 this.inputValueNames = new ArrayList<String>(inputValuesNodes 176 this.inputValueNames = new ArrayList<String>(inputValuesNodes
394 * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String) 394 * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String)
395 */ 395 */
396 public boolean isTransitionReachable(String transitionID) { 396 public boolean isTransitionReachable(String transitionID) {
397 log.debug("TransitionBase.isTransitionReachable"); 397 log.debug("TransitionBase.isTransitionReachable");
398 boolean returnValue = false; 398 boolean returnValue = false;
399 if (this.couldAlternativeTransitionUsed()){ 399 Iterator<String> transitions = reachableTransitions.iterator();
400 return alternativeTransition.isTransitionReachable(transitionID); 400 while (transitions.hasNext()) {
401 }else{ 401 if (transitions.next().equals(transitionID)) {
402 Iterator<String> transitions = reachableTransitions.iterator(); 402 log.debug("Transition " + transitionID + " wird unterstützt.");
403 while (transitions.hasNext()) { 403 returnValue = true;
404 if (transitions.next().equals(transitionID)) { 404 break;
405 log.debug("Transition " + transitionID + " wird unterstützt.");
406 returnValue = true;
407 break;
408 }
409 } 405 }
410 } 406 }
411 return returnValue; 407 return returnValue;
412 } 408 }
413 409
414 /** 410 /**
415 * @see de.intevation.gnv.transition.Transition#advance(java.lang.String, 411 * @see de.intevation.gnv.transition.Transition#advance(java.lang.String,
416 * de.intevation.artifacts.CallMeta) 412 * de.intevation.artifacts.CallMeta)
417 */ 413 */
418 public void advance(String uuid, CallMeta callMeta) 414 public void advance(String uuid, CallMeta callMeta)
419 throws TransitionException { 415 throws TransitionException {
420 log.debug("TransitionBase.advance"); 416 }
421 417
422 if (this.couldAlternativeTransitionUsed()){ 418 public void initialize(String uuid, CallMeta callMeta)
423 this.alternativeTransition.setParent(this.getParent()); 419 throws TransitionException {
424 this.alternativeTransition.putInputData(this.inputData != null ? 420 log.debug("TransitionBase.initialize");
425 this.inputData.values() : 421 try {
426 null,uuid); 422 String[] filterValues = this
427 this.alternativeTransition.advance(uuid, callMeta); 423 .generateFilterValuesFromInputData();
428 }else{ 424 Collection<Result> result = null;
429 try { 425 try {
430 String[] filterValues = this.generateFilterValuesFromInputData(); 426 if (this.queryID != null) {
431 Collection<Result> result = null; 427 QueryExecutor queryExecutor = QueryExecutorFactory
432 try { 428 .getInstance().getQueryExecutor();
433 if (this.queryID != null) { 429 result = queryExecutor.executeQuery(this.queryID,
434 QueryExecutor queryExecutor = QueryExecutorFactory 430 filterValues);
435 .getInstance().getQueryExecutor(); 431 }
436 result = queryExecutor.executeQuery(this.queryID, 432 this.purifyResult(result, uuid);
437 filterValues); 433 } catch (RuntimeException e) {
438 }
439 this.purifyResult(result, uuid);
440 } catch (RuntimeException e) {
441 log.error(e, e);
442 }
443 } catch (QueryException e) {
444 log.error(e, e); 434 log.error(e, e);
445 throw new TransitionException(e); 435 }
446 } 436 } catch (QueryException e) {
437 log.error(e, e);
438 throw new TransitionException(e);
447 } 439 }
448 } 440 }
449 441
450 /** 442 /**
451 * @return 443 * @return
645 choiceNode.appendChild(itemNode); 637 choiceNode.appendChild(itemNode);
646 } 638 }
647 selectNode.appendChild(lableNode); 639 selectNode.appendChild(lableNode);
648 selectNode.appendChild(choiceNode); 640 selectNode.appendChild(choiceNode);
649 641
650 if (!it.hasNext()) { 642 if (!it.hasNext() && this.dataName != null) {
651 dynamic.appendChild(selectNode); 643 dynamic.appendChild(selectNode);
652 } else { 644 } else {
653 staticNode.appendChild(selectNode); 645 staticNode.appendChild(selectNode);
654 } 646 }
655 647
712 inputMaxNode.appendChild(inputMaxValueNode); 704 inputMaxNode.appendChild(inputMaxValueNode);
713 705
714 groupNode.appendChild(inputMinNode); 706 groupNode.appendChild(inputMinNode);
715 groupNode.appendChild(inputMaxNode); 707 groupNode.appendChild(inputMaxNode);
716 708
717 if (!it.hasNext()) { 709 if (!it.hasNext() && this.dataName != null) {
718 dynamic.appendChild(groupNode); 710 dynamic.appendChild(groupNode);
719 } else { 711 } else {
720 staticNode.appendChild(groupNode); 712 staticNode.appendChild(groupNode);
721 } 713 }
722 } else if (o instanceof SingleValueDescribeData) { 714 } else if (o instanceof SingleValueDescribeData) {
748 document, "value"); 740 document, "value");
749 inputValueNode.setTextContent(svdb.getValue()); 741 inputValueNode.setTextContent(svdb.getValue());
750 inputNode.appendChild(inputValueNode); 742 inputNode.appendChild(inputValueNode);
751 743
752 groupNode.appendChild(inputNode); 744 groupNode.appendChild(inputNode);
753 if (!it.hasNext()) { 745 if (!it.hasNext() && this.dataName != null) {
754 dynamic.appendChild(groupNode); 746 dynamic.appendChild(groupNode);
755 } else { 747 } else {
756 staticNode.appendChild(groupNode); 748 staticNode.appendChild(groupNode);
757 } 749 }
758 } 750 }
790 782
791 /** 783 /**
792 * @see de.intevation.gnv.transition.Transition#getInputData() 784 * @see de.intevation.gnv.transition.Transition#getInputData()
793 */ 785 */
794 public Collection<InputData> getInputData() throws TransitionException { 786 public Collection<InputData> getInputData() throws TransitionException {
795 if (this.couldAlternativeTransitionUsed()){ 787 return this.inputData != null ? this.inputData.values() : null;
796 return this.alternativeTransition.getInputData();
797 }else{
798 return this.inputData != null ? this.inputData.values() : null;
799 }
800 } 788 }
801 } 789 }

http://dive4elements.wald.intevation.org