diff artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.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 ece0fdb07975
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java	Thu Feb 03 18:00:41 2011 +0000
@@ -0,0 +1,57 @@
+package de.intevation.artifactdatabase.state;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The StateEngine stores all states for each Artifact.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class StateEngine {
+
+    /** The logger used in this class. */
+    private static Logger logger = Logger.getLogger(StateEngine.class);
+
+    /**
+     * A map that contains the states of the artifacts. The key of this map is
+     * the name of an artifact, its value is a list of all states the artifact
+     * can reach.
+     */
+    protected Map<String, List> states;
+
+
+    /**
+     * The default constructor.
+     */
+    public StateEngine() {
+        states = new HashMap<String, List>();
+    }
+
+
+    /**
+     * Add new states for a specific artifact.
+     *
+     * @param artifact The name of the artifact.
+     * @param states A list of states that the artifact can reach.
+     *
+     * @return true, if the states were added, otherwise false.
+     */
+    public boolean addStates(String artifact, List states) {
+        List tmp = this.states.get(artifact);
+
+        if (tmp != null) {
+            logger.info(
+                "States for the artifact '" + artifact + "' already stored.");
+
+            return false;
+        }
+
+        logger.debug("Add new states for the artifact '" + artifact + "'");
+        return this.states.put(artifact, states) != null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org