diff gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java @ 725:dde7f51dbe1e

Improved exception handling while feeding an artifact. gnv-artifacts/trunk@757 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 10 Mar 2010 13:27:14 +0000
parents 65f09139e9b3
children 9a828e5a2390
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java	Tue Mar 09 12:54:05 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java	Wed Mar 10 13:27:14 2010 +0000
@@ -2,6 +2,7 @@
 
 import de.intevation.artifactdatabase.XMLUtils;
 
+import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
 
 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
@@ -38,10 +39,6 @@
 public class MinMaxState extends StateBase {
 
     /**
-     * The UID of this Class
-     */
-    private static final long serialVersionUID = -3525903792105187408L;
-    /**
      * the logger, used to log exceptions and additonaly information
      */
     private static Logger log = Logger.getLogger(MinMaxState.class);
@@ -84,11 +81,18 @@
      *      java.lang.String)
      */
     @Override
-    public void feed(Collection<InputData> inputData, String uuid)
-    throws StateException
-    {
-        if (inputData == null)
-            return;
+    public Document feed(
+        CallContext           context,
+        Collection<InputData> inputData,
+        String                uuid)
+    throws StateException {
+        RessourceFactory resFactory = RessourceFactory.getInstance();
+
+        if (inputData == null) {
+            String msg = "No input data given.";
+            log.warn(msg);
+            return feedFailure(msg);
+        }
 
         InputValidator iv = new InputValidator();
         Iterator iter     = inputData.iterator();
@@ -99,19 +103,21 @@
         while (iter.hasNext()) {
             InputData  tmp   = (InputData) iter.next();
             InputValue meta  = inputValues.get(tmp.getName());
+            String     type  = meta.getType();
             String     value = tmp.getValue();
             String     name  = tmp.getName();
 
             if (meta == null) {
-                log.warn("Input data not expected here. Data will be ignored.");
-                return;
+                String msg = "Input data not expected here. Data will be ignored.";
+                log.warn(msg);
+                return feedFailure(msg);
             }
 
-            boolean valid = iv.isInputValid(value, meta.getType());
+            boolean valid = iv.isInputValid(value, type);
             if (!valid) {
                 String msg = "Input is not valid for this state.";
                 log.error(msg);
-                throw new StateException(msg);
+                return feedFailure(msg);
             }
 
             if (name.equals(MINVALUEFIELDNAME)) {
@@ -121,14 +127,24 @@
             if (name.equals(MAXVALUEFIELDNAME)) {
                 max = value;
             }
+
+            if (min != null && max != null) {
+                if (!iv.isInputValid((String) min, (String) max, type)) {
+                    String msg = "Input is not valid for this state.";
+                    log.error(msg);
+                    return feedFailure(msg);
+                }
+            }
         }
 
-        if (min != null && max != null) {
-            DescribeData values = new DefaultMinMaxDescribeData(
-                dataName, min, max, getID());
+        
 
-            this.inputData.put(dataName, new DefaultInputData(dataName, values));
-        }
+        DescribeData values = new DefaultMinMaxDescribeData(
+            dataName, min, max, getID());
+
+        this.inputData.put(dataName, new DefaultInputData(dataName, values)); 
+
+        return feedSuccess();
     }
 
 

http://dive4elements.wald.intevation.org