changeset 1086:825ea312116d

Call State.endOfLife() for all States in the Artifact when Artifact.endOfLife() is called. flys-artifacts/trunk@2589 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 26 Aug 2011 08:53:37 +0000
parents 07878836ee0d
children 22149b0545b9
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java
diffstat 2 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Aug 26 08:49:18 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Aug 26 08:53:37 2011 +0000
@@ -1,3 +1,9 @@
+2011-08-26  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Call
+	  State.endOfLife() for all States when endOfLife() of the Artifact is
+	  called.
+
 2011-08-26  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Also plot "W"-MainValues (on vertical axis), take correct parameters, but
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Aug 26 08:49:18 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Aug 26 08:53:37 2011 +0000
@@ -370,21 +370,17 @@
         else if (isPreviousState(targetState, context)) {
             logger.info("Advance: Step back to");
 
-            List<String> prevs = getPreviousStateIds();
+            List<String> prevs   = getPreviousStateIds();
             int targetIdx        = prevs.indexOf(targetState);
             int start            = prevs.size() - 1;
 
-            logger.debug("Remove current state: " + getCurrentStateId());
-            State cur = getCurrentState(context);
-            cur.endOfLife(this, context);
+            prevs.add(getCurrentStateId());
+            destroyStates(prevs, context);
 
             for (int i = start; i >= targetIdx; i--) {
                 String prev = prevs.get(i);
                 logger.debug("Remove state id '" + prev + "'");
 
-                State s = getState(context, prev);
-                s.endOfLife(this, context);
-
                 prevs.remove(prev);
                 facets.remove(prev);
             }
@@ -921,5 +917,30 @@
             logger.debug("++++++++++++++ END ARTIFACT DUMP +++++++++++++++++");
         }
     }
+
+
+    /**
+     * Calls endOfLife() for each state in the list <i>ids</i>.
+     *
+     * @param ids The State IDs that should be destroyed.
+     * @param context The FLYSContext.
+     */
+    protected void destroyStates(List<String> ids, Object context) {
+        for (int i = 0, num = ids.size(); i < num; i++) {
+            State s = getState(context, ids.get(i));
+            s.endOfLife(this, context);
+        }
+    }
+
+
+    @Override
+    public void endOfLife(Object context) {
+        logger.info("FLYSArtifact.endOfLife: " + identifier());
+
+        List<String> ids = getPreviousStateIds();
+        ids.add(getCurrentStateId());
+
+        destroyStates(ids, context);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org