changeset 106:ece0fdb07975

Implementations to initialize and retrieve states. artifacts/trunk@1291 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 04 Feb 2011 10:50:53 +0000
parents 265f150f4f7f
children 39d9391059bd
files ChangeLog artifact-database/pom.xml artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java
diffstat 4 files changed, 50 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Feb 04 08:55:17 2011 +0000
+++ b/ChangeLog	Fri Feb 04 10:50:53 2011 +0000
@@ -1,3 +1,15 @@
+2011-02-04  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java:
+	  Implements the method setup() - the ID and the description of the state
+	  are extracted at this place.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java:
+	  Added a method to retrieve the states of a specified artifact.
+
+	* artifact-database/pom.xml: Added a dependency to the artifacts-common
+	  package.
+
 2011-02-04  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java:
--- a/artifact-database/pom.xml	Fri Feb 04 08:55:17 2011 +0000
+++ b/artifact-database/pom.xml	Fri Feb 04 10:50:53 2011 +0000
@@ -50,6 +50,11 @@
       <version>1.0-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>de.intevation.artifacts.common</groupId>
+      <artifactId>artifacts-common</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>org.restlet.jse</groupId>
       <artifactId>org.restlet</artifactId>
       <version>2.0.4</version>
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java	Fri Feb 04 08:55:17 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java	Fri Feb 04 10:50:53 2011 +0000
@@ -10,11 +10,15 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.xml.xpath.XPathConstants;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
 import de.intevation.artifacts.CallContext;
 
+import de.intevation.artifacts.common.utils.XMLUtils;
+
 import de.intevation.artifactdatabase.data.StateData;
 
 
@@ -26,6 +30,15 @@
  */
 public abstract class AbstractState implements State {
 
+    /** The XPath to the ID of the state relative to the state node in the
+     * configuration. */
+    public static final String XPATH_ID = "@id";
+
+    /** The XPath to the description of the state relative to the state node in
+     * the configuration. */
+    public static final String XPATH_DESCRIPTION = "@description";
+
+
     /** The ID of the state. */
     protected String id;
 
@@ -115,12 +128,16 @@
 
 
     /**
-     * Initialize the state based on the state node in the configuration. This
-     * method needs to be implemented by concrete subclasses.
+     * Initialize the state based on the state node in the configuration.
      *
      * @param config The state configuration node.
      */
-    public abstract void setup(Node config);
+    public void setup(Node config) {
+        id = (String) XMLUtils.xpath(config, XPATH_ID, XPathConstants.STRING);
+
+        description = (String) XMLUtils.xpath(
+            config, XPATH_DESCRIPTION, XPathConstants.STRING);
+    }
 
 
     /**
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java	Fri Feb 04 08:55:17 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java	Fri Feb 04 10:50:53 2011 +0000
@@ -53,5 +53,18 @@
         logger.debug("Add new states for the artifact '" + artifact + "'");
         return this.states.put(artifact, states) != null;
     }
+
+
+    /**
+     * Returns the state list of an artifact specified by its name.
+     *
+     * @param artifact The name of the artifact.
+     *
+     * @return the list of states of this artifact or <i>null</i> if no states
+     * are existing for this <i>artifact</i>.
+     */
+    public List<State> getStates(String artifact) {
+        return states.get(artifact);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org