diff artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java @ 374:5420b96dd0b3

Added a method StateEngine.getStateData() that returns the StateData of a specific Artifact. artifacts/trunk@3827 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 30 Jan 2012 13:17:32 +0000
parents 16ab243507e0
children 708de1779232
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java	Mon Jan 30 13:15:52 2012 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java	Mon Jan 30 13:17:32 2012 +0000
@@ -7,6 +7,9 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifactdatabase.data.StateData;
+
+
 /**
  * The StateEngine stores all states and associated information about
  * outputs and facets for each Artifact.
@@ -64,6 +67,30 @@
     }
 
 
+    public StateData getStateData(String artifact, String dataName) {
+        List<State> artifactStates = getStates(artifact);
+
+        if (artifactStates == null || artifactStates.size() == 0) {
+            logger.warn("No States for Artifact '" + artifact + "' existing.");
+            return null;
+        }
+
+        for (State state: artifactStates) {
+            StateData sd = state.getData(dataName);
+
+            if (sd != null) {
+                return sd;
+            }
+        }
+
+        logger.warn(
+            "No StateData for Artifact '" + artifact +
+            "' with name '" + dataName + "' existing.");
+
+        return null;
+    }
+
+
     /**
      * Add new states for a specific artifact.
      *

http://dive4elements.wald.intevation.org