changeset 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 6072f84608c2
children 33176e6e3c37
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jan 30 13:15:52 2012 +0000
+++ b/ChangeLog	Mon Jan 30 13:17:32 2012 +0000
@@ -1,3 +1,9 @@
+2012-01-30  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java:
+	  Added a method that returns a StateData objects of a specific Artifact
+	  based on the Artifact's StateData's name.
+
 2012-01-30  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java:
--- 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