diff artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java @ 104:26bfff409dd3

Added interfaces and engines used in concrete artifact packages. artifacts/trunk@1289 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Feb 2011 18:00:41 +0000
parents
children 9ece61d918b1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java	Thu Feb 03 18:00:41 2011 +0000
@@ -0,0 +1,60 @@
+package de.intevation.artifactdatabase.transition;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The TransitionEngine stores all transitions for each Artifact and should be
+ * used to determine, if an Artifact is able to advance from one to another
+ * state.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class TransitionEngine {
+
+    /** The logger used in this class. */
+    private static Logger logger = Logger.getLogger(TransitionEngine.class);
+
+    /**
+     * A map that contains the transitions of the artifacts. The key is the name
+     * of the artifact, its value is a list of all transitions of this artifact.
+     */
+    protected Map<String, List> transitions;
+
+
+    /**
+     * The default constructor.
+     */
+    public TransitionEngine() {
+        transitions = new HashMap<String, List>();
+    }
+
+
+    /**
+     * Add new transitions for a specific artifact.
+     *
+     * @param stateId the name of the Artifact.
+     * @param transitions the list of transition of the artifact.
+     *
+     * @return true, if the transitions were added, otherwise false.
+     */
+    public boolean addTransition(String stateId, List transitions) {
+        List tmp = this.transitions.get(stateId);
+
+        if (tmp != null) {
+            logger.info(
+                "Transitions for the state '"
+                + stateId
+                + "' already stored.");
+
+            return false;
+        }
+
+        logger.debug("Add new transitions for state '" + stateId + "'");
+        return this.transitions.put(stateId, transitions) != null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org