diff gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java @ 337:a887074460b6

Last Step of the Refactoring Work on the Transition Model. Splitted Businesslogic between States and Transitions. Splitted the ConfigurationElements of State and Transition in several XML-Fragments. gnv-artifacts/trunk@403 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Dec 2009 13:38:21 +0000
parents
children 9a828e5a2390
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java	Tue Dec 08 13:38:21 2009 +0000
@@ -0,0 +1,82 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition;
+
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Node;
+
+import de.intevation.artifactdatabase.Config;
+import de.intevation.gnv.state.InputData;
+import de.intevation.gnv.state.State;
+import de.intevation.gnv.state.exception.StateException;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class ValueCompareTransition extends TransitionBase {
+
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(ValueCompareTransition.class);
+    
+    private String dataName = null;
+    private String dataValue = null;
+    private String operator = null;
+    
+    /**
+     * The UID of this Class.
+     */
+    private static final long serialVersionUID = -7846722158776823205L;
+
+    /**
+     * Constructor
+     */
+    public ValueCompareTransition() {
+        super();
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State)
+     */
+    public boolean isValid(State state) {
+        
+        try {
+            Iterator<InputData> it = state.getInputData().iterator();
+            while (it.hasNext()){
+                InputData inputData = it.next();
+                if (inputData.getName().equals(this.dataName)){
+                    boolean returnValue = false;
+                    if (operator.equals("equal")){
+                        returnValue = this.dataValue.equals(inputData.getValue());
+                    }else if (operator.equals("notequal")){
+                        returnValue = !this.dataValue.equals(inputData.getValue());
+                    }
+                    return returnValue;
+                }
+            }
+            if (operator.equals("notequal")){
+                // data is not given. So the constraint not Equals is fullfilled.
+                return true;
+            }
+        } catch (StateException e) {
+            log.error(e,e);
+            return false;
+        }
+        return false;
+    }
+
+    @Override
+    public void setup(Node configuration) {
+        super.setup(configuration);
+        this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue");
+        this.dataValue = Config.getStringXPath(configuration,"condition/@value");
+        this.operator = Config.getStringXPath(configuration,"condition/@operator");
+    }
+    
+
+}

http://dive4elements.wald.intevation.org