changeset 1067:f364410c7bc9

Refactored (state access) to ease future development of more trivial artifacts. flys-artifacts/trunk@2549 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 24 Aug 2011 09:44:31 +0000
parents 7f5426c69ee0
children 67b8a2b03e36
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java
diffstat 2 files changed, 28 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Aug 24 08:53:11 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Aug 24 09:44:31 2011 +0000
@@ -1,3 +1,9 @@
+2011-08-24  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
+	  Extracted access to state and states in order to have fewer places to
+	  modify when going for single/trivial state- artifacts.
+
 2011-08-24  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/WMSBackgroundState.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Aug 24 08:53:11 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Aug 24 09:44:31 2011 +0000
@@ -160,14 +160,12 @@
 
         super.setup(identifier, factory, context, callMeta, data);
 
-        FLYSContext flysContext = (FLYSContext) context;
-        StateEngine engine      = (StateEngine) flysContext.get(
-            FLYSContext.STATE_ENGINE_KEY);
+        FLYSContext flysContext = getFlysContext(context);
+
+        List<State> states = getStates(context);
 
         String name = getName();
-
         logger.debug("Set initial state for artifact '" + name + "'");
-        List<State> states = engine.getStates(name);
 
         setCurrentState(states.get(0));
 
@@ -436,13 +434,29 @@
      * @return the current State of the artifact.
      */
     protected State getCurrentState(Object context) {
+        return getState(context, getCurrentStateId());
+    }
+
+
+    /**
+     * Get list of existant states for this Artifact.
+     * @param context Contex to get StateEngine from.
+     * @return list of states.
+     */
+    protected List<State> getStates(Object context) {
         FLYSContext flysContext = getFlysContext(context);
         StateEngine engine      = (StateEngine) flysContext.get(
             FLYSContext.STATE_ENGINE_KEY);
-
-        return engine.getState(getCurrentStateId());
+        return engine.getStates(getName());
     }
 
+
+    /**
+     * Get state with given ID.
+     * @param context Context to get StateEngine from.
+     * @param stateID ID of state to get.
+     * @return state with given ID.
+     */
     protected State getState(Object context, String stateID) {
         FLYSContext flysContext = getFlysContext(context);
         StateEngine engine      = (StateEngine) flysContext.get(
@@ -672,12 +686,8 @@
         List<String> stateIds  = getPreviousStateIds();
         List<Output> generated = new ArrayList<Output>();
 
-        FLYSContext flysContext = getFlysContext(context);
-        StateEngine engine      = (StateEngine) flysContext.get(
-            FLYSContext.STATE_ENGINE_KEY);
-
         for (String stateId: stateIds) {
-            DefaultState state = (DefaultState) engine.getState(stateId);
+            DefaultState state = (DefaultState) getState(context, stateId);
             generated.addAll(getOutputForState(state));
         }
 

http://dive4elements.wald.intevation.org