diff 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
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Mon Nov 30 15:08:47 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Dec 01 15:58:02 2009 +0000
@@ -46,6 +46,8 @@
  */
 public abstract class TransitionBase implements Transition {
 
+    
+
     /**
      * The UID of this Class
      */
@@ -76,8 +78,6 @@
     protected String queryID = null;
 
     private Collection<String> reachableTransitions = null;
-    
-    private Transition alternativeTransition = null;
 
     protected Collection<String> inputValueNames = null;
 
@@ -115,7 +115,14 @@
     public Collection<String> reachableTransitions() {
         
         if (this.couldAlternativeTransitionUsed()){
-            return this.alternativeTransition.reachableTransitions();
+            Iterator<String> it = this.reachableTransitions.iterator();
+            String transValue = null;
+            while (it.hasNext()){
+                transValue = it.next();
+            }
+            Collection<String> returnValue = new ArrayList<String>(1);
+            returnValue.add(transValue);
+            return returnValue;
         }else{
             return this.reachableTransitions;
         }
@@ -127,9 +134,8 @@
      */
     private boolean couldAlternativeTransitionUsed() {
      // TODO das muss hier noch etwas freier gestaltet werden.
-        Object[] inputValues = this.inputValueNames.toArray();
-        String key = (String)inputValues[inputValues.length-1];
-        boolean returnValue= this.alternativeTransition != null && 
+        String key = this.dataName;
+        boolean returnValue= /*this.alternativeTransition != null &&*/ 
                             this.inputData != null &&
                             this.inputData.containsKey(key) && 
                             this.inputData.get(key).getValue().
@@ -163,12 +169,6 @@
 
         }
         
-        Node alternativeTransitionNode = Config.getNodeXPath(configuration,
-                                                     "alternativeTransition/transition");
-        if (alternativeTransitionNode != null){
-            this.alternativeTransition = TransitionFactory.getInstance()
-                                        .createTransition(alternativeTransitionNode);
-        }
         NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,
                 "inputvalues/inputvalue");
         this.inputValues = new HashMap<String, InputValue>(inputValuesNodes
@@ -396,16 +396,12 @@
     public boolean isTransitionReachable(String transitionID) {
         log.debug("TransitionBase.isTransitionReachable");
         boolean returnValue = false;
-        if (this.couldAlternativeTransitionUsed()){
-            return alternativeTransition.isTransitionReachable(transitionID);
-        }else{
-            Iterator<String> transitions = reachableTransitions.iterator();
-            while (transitions.hasNext()) {
-                if (transitions.next().equals(transitionID)) {
-                    log.debug("Transition " + transitionID + " wird unterstützt.");
-                    returnValue = true;
-                    break;
-                }
+        Iterator<String> transitions = reachableTransitions.iterator();
+        while (transitions.hasNext()) {
+            if (transitions.next().equals(transitionID)) {
+                log.debug("Transition " + transitionID + " wird unterstützt.");
+                returnValue = true;
+                break;
             }
         }
         return returnValue;
@@ -416,34 +412,30 @@
      *      de.intevation.artifacts.CallMeta)
      */
     public void advance(String uuid, CallMeta callMeta)
-                                                       throws TransitionException {
-        log.debug("TransitionBase.advance");
-        
-        if (this.couldAlternativeTransitionUsed()){
-            this.alternativeTransition.setParent(this.getParent());
-            this.alternativeTransition.putInputData(this.inputData != null ? 
-                                                    this.inputData.values() : 
-                                                    null,uuid);
-            this.alternativeTransition.advance(uuid, callMeta);
-        }else{
+                                                   throws TransitionException {
+    }
+    
+    public void initialize(String uuid, CallMeta callMeta)
+                                                   throws TransitionException {
+        log.debug("TransitionBase.initialize");
+        try {
+            String[] filterValues = this
+                    .generateFilterValuesFromInputData();
+            Collection<Result> result = null;
             try {
-                String[] filterValues = this.generateFilterValuesFromInputData();
-                Collection<Result> result = null;
-                try {
-                    if (this.queryID != null) {
-                        QueryExecutor queryExecutor = QueryExecutorFactory
-                                .getInstance().getQueryExecutor();
-                        result = queryExecutor.executeQuery(this.queryID,
-                                filterValues);
-                    }
-                    this.purifyResult(result, uuid);
-                } catch (RuntimeException e) {
-                    log.error(e, e);
+                if (this.queryID != null) {
+                    QueryExecutor queryExecutor = QueryExecutorFactory
+                            .getInstance().getQueryExecutor();
+                    result = queryExecutor.executeQuery(this.queryID,
+                            filterValues);
                 }
-            } catch (QueryException e) {
+                this.purifyResult(result, uuid);
+            } catch (RuntimeException e) {
                 log.error(e, e);
-                throw new TransitionException(e);
             }
+        } catch (QueryException e) {
+            log.error(e, e);
+            throw new TransitionException(e);
         }
     }
 
@@ -647,7 +639,7 @@
                     selectNode.appendChild(lableNode);
                     selectNode.appendChild(choiceNode);
 
-                    if (!it.hasNext()) {
+                    if (!it.hasNext() && this.dataName != null) {
                         dynamic.appendChild(selectNode);
                     } else {
                         staticNode.appendChild(selectNode);
@@ -714,7 +706,7 @@
                     groupNode.appendChild(inputMinNode);
                     groupNode.appendChild(inputMaxNode);
                     
-                    if (!it.hasNext()) {
+                    if (!it.hasNext() && this.dataName != null) {
                         dynamic.appendChild(groupNode);
                     } else {
                         staticNode.appendChild(groupNode);
@@ -750,7 +742,7 @@
                     inputNode.appendChild(inputValueNode);
 
                     groupNode.appendChild(inputNode);
-                    if (!it.hasNext()) {
+                    if (!it.hasNext() && this.dataName != null) {
                         dynamic.appendChild(groupNode);
                     } else {
                         staticNode.appendChild(groupNode);
@@ -792,10 +784,6 @@
      * @see de.intevation.gnv.transition.Transition#getInputData()
      */
     public Collection<InputData> getInputData() throws TransitionException {
-        if (this.couldAlternativeTransitionUsed()){
-            return this.alternativeTransition.getInputData();
-        }else{
-            return this.inputData != null ? this.inputData.values() : null;
-        }
+        return this.inputData != null ? this.inputData.values() : null;
     }
 }

http://dive4elements.wald.intevation.org