changeset 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 1282cf96d3eb
children 265f150f4f7f
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/data/StateData.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/State.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java artifact-database/src/main/java/de/intevation/artifactdatabase/transition/Transition.java artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java
diffstat 6 files changed, 295 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Feb 02 14:43:32 2011 +0000
+++ b/ChangeLog	Thu Feb 03 18:00:41 2011 +0000
@@ -1,3 +1,15 @@
+2011-02-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java:
+	  Implementations to store the provided states and transitions of the
+	  artifact server. These engines should be filled at bootstrap.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/State.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/transition/Transition.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/data/StateData.java:
+	  Interface descriptions for states, transitions and user inserted data.
+
 2011-02-02  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/data/StateData.java	Thu Feb 03 18:00:41 2011 +0000
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+package de.intevation.artifactdatabase.data;
+
+import java.io.Serializable;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface StateData extends Serializable {
+
+    /**
+     * Returns the name of the data object.
+     *
+     * @return the name.
+     */
+    public String getName();
+
+
+    /**
+     * Returns the description of the data object.
+     *
+     * @return the description of the data object.
+     */
+    public String getDescription();
+
+
+    /**
+     * Returns the type of the data object as string.
+     *
+     * @return the type as string.
+     */
+    public String getType();
+
+
+    /**
+     * Returns the value of the data object.
+     *
+     * @return the value.
+     */
+    public Object getValue();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/State.java	Thu Feb 03 18:00:41 2011 +0000
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+package de.intevation.artifactdatabase.state;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.data.StateData;
+
+
+/**
+ * This interface describes the basic methods a concrete state class needs to
+ * implement.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface State extends Serializable {
+
+    /**
+     * Return the id of the state.
+     *
+     * @return the id.
+     */
+    public String getID();
+
+
+    /**
+     * Return the description of the state.
+     *
+     * @return the description of the state.
+     */
+    public String getDescription();
+
+
+    /**
+     * Returns the data provided by this state.
+     *
+     * @return the data stored in this state.
+     */
+    public Map<String, StateData> getData();
+
+
+    /**
+     * Initialize the state based on the state node in the configuration.
+     *
+     * @param config The state configuration node.
+     */
+    public void setup(Node config);
+
+
+    /**
+     * This method is called when an artifacts retrieves a describe request. It
+     * creates the user interface description of the current state.
+     *
+     * @param document Describe doucment.
+     * @param rootNode Parent node for all new elements.
+     * @param context The CallContext.
+     * @param uuid The uuid of an artifact.
+     */
+    public void describe(
+        Document    document,
+        Node        rootNode,
+        CallContext context,
+        String      uuid
+    );
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /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 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/transition/Transition.java	Thu Feb 03 18:00:41 2011 +0000
@@ -0,0 +1,40 @@
+package de.intevation.artifactdatabase.transition;
+
+import de.intevation.artifactdatabase.state.State;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface Transition {
+
+    /**
+     * Return the ID of the start State.
+     */
+    public String getFrom();
+
+    /**
+     * Return the ID of the target State.
+     */
+    public String getTo();
+
+    /**
+     * Set the ID of the current State.
+     *
+     * @param from The ID of the current state.
+     */
+    public void setFrom(String from);
+
+    /**
+     * Set the ID of the target State.
+     *
+     * @param to The ID of the target state.
+     */
+    public void setTo(String to);
+
+    /**
+     * Determines if the transition from <code>state</code> is valid.
+     */
+    public boolean isValid(State state);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /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