diff gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 57:f01592cd6419

Funktionalität Feed initial bereitgestellt. gnv-artifacts/trunk@39 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Sep 2009 12:22:00 +0000
parents 737d8bf63701
children f31343d80d53
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 10:39:50 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 12:22:00 2009 +0000
@@ -5,6 +5,9 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
@@ -13,6 +16,7 @@
 
 import de.intevation.artifactdatabase.Config;
 import de.intevation.gnv.artifacts.GNVArtifactBase;
+import de.intevation.gnv.transition.exception.TransitionException;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -34,9 +38,13 @@
     
     private Collection<String> reachableTransitions = null;
     
-    private Collection<InputValue> inputValues = null;
+    private Collection<String> inputValueNames = null;
+    
+    private Map<String,InputValue> inputValues = null;
     
     private Transition parent = null;
+    
+    private Collection<InputData> inputData = null;
     /**
      * Constructor
      */
@@ -69,7 +77,7 @@
      * @see de.intevation.gnv.transition.Transition#getRequiredInputValues()
      */
     public Collection<InputValue> getRequiredInputValues() {
-        return this.inputValues;
+        return this.inputValues.values();
     }
 
     /**
@@ -91,16 +99,18 @@
         }
         
         NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,"inputvalues/inputvalue");
-        this.inputValues = new ArrayList<InputValue>(inputValuesNodes.getLength());
+        this.inputValues = new HashMap<String,InputValue>(inputValuesNodes.getLength());
+        this.inputValueNames = new ArrayList<String>(inputValuesNodes.getLength());
         for (int i = 0 ; i < inputValuesNodes.getLength(); i++){
             Node inputValueNode = inputValuesNodes.item(i);
             InputValue inputValue = new DefaultInputValue(Config.getStringXPath(inputValueNode,"@name"), Config.getStringXPath(inputValueNode,"@type"));
             log.debug(inputValue.toString());
-            this.inputValues.add(inputValue);
+            this.inputValues.put(inputValue.getName(),inputValue);
+            this.inputValueNames.add(inputValue.getName());
         }
         
         this.queryID = Config.getStringXPath(configuration,"queryID");
-        log.info("QueryID ==>"+ this.queryID);
+        log.info("QueryID ==> "+ this.queryID);
         
     }
 
@@ -117,4 +127,35 @@
     public void setParent(Transition transition) {
         this.parent = transition;
     }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#putInputData(java.util.Collection)
+     */
+    public void putInputData(Collection<InputData> inputData) throws TransitionException {
+        log.debug("TransitionBase.putInputData");
+        if (inputData != null){
+            Iterator<InputData> it = inputData.iterator();
+            while(it.hasNext()){
+                InputData tmpItem = it.next();
+                InputValue inputValue = this.inputValues.get(tmpItem.getName());
+                if (inputValue != null){
+                    if (this.inputData == null){
+                        this.inputData = new ArrayList<InputData>(inputData.size());
+                        // TODO validate Value;
+                        this.inputData.add(tmpItem);
+                    }
+                    
+                }else{
+                    String errMsg = "No Inputvalue given for Inputdata "+ tmpItem.getName();
+                    log.warn(errMsg+ "Value will be ignored");
+                    throw new TransitionException(errMsg);
+                    
+                }
+            }
+        }else{
+            log.warn("No Inputdata given");
+        }
+    
+    }
+    
 }

http://dive4elements.wald.intevation.org