changeset 1078:048517d67215

Changed state spawning mechanism of MainValuesArtifact. flys-artifacts/trunk@2575 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 25 Aug 2011 10:38:45 +0000
parents 3067e700fc13
children ef756e166154
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java
diffstat 2 files changed, 46 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Aug 25 10:34:20 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Aug 25 10:38:45 2011 +0000
@@ -1,3 +1,9 @@
+2011-08-25  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java
+	  (getState):
+	  Resolved multiple creation of state (yet not very clean).
+
 2011-08-25  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Thu Aug 25 10:34:20 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Thu Aug 25 10:38:45 2011 +0000
@@ -7,16 +7,23 @@
 
 import org.w3c.dom.Document;
 
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.State;
+
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.ArtifactFactory;
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
+import de.intevation.flys.artifacts.model.RiverFactory;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.states.StaticState;
 
-import de.intevation.artifactdatabase.state.DefaultFacet;
-import de.intevation.artifactdatabase.state.Facet;
-import de.intevation.artifactdatabase.state.DefaultOutput;
-import de.intevation.artifactdatabase.state.State;
+import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.River;
+
 
 /**
  * Artifact to access names of Points Of Interest along a segment of a river.
@@ -32,6 +39,9 @@
     /** The name of the artifact. */
     public static final String ARTIFACT_NAME = "mainvalue";
 
+    /** One and only state to be in. */
+    protected transient State state = null;
+
 
     /**
      * Trivial Constructor.
@@ -98,16 +108,32 @@
      */
     @Override
     protected State getState(Object context, String stateID) {
-        // TODO Add other outputs, prevent this code from being executed
-        // multiple times (e.g. make state serializable and a field).
-        State state = new StaticState();
-        List<Facet>  fs = new ArrayList<Facet>();
-        fs.add(new MainValuesFacet());
-        facets.put(state.getID(), fs);
-        DefaultOutput mainValuesOutput = new DefaultOutput(
-                    "discharge_curve", "output.discharge_curve", "image/png",
-                    fs,
-                    "chart");
+        if (state != null) {
+            
+        }
+        else {
+            state = new StaticState();
+            List<Facet> fs = new ArrayList<Facet>();
+            fs.add(new MainValuesFacet());
+            // TODO check if facets and outputs already exist.
+            // TODO also check, this is usually done in initialize, too.
+            facets.put(state.getID(), fs);
+            DefaultOutput mainValuesOutput1 = new DefaultOutput(
+                        "discharge_curve", "output.discharge_curve", "image/png",
+                        fs,
+                        "chart");
+            DefaultOutput mainValuesOutput2 = new DefaultOutput(
+                        "computed_discharge_curve",
+                        "output.computed_discharge_curve", "image/png",
+                        fs,
+                        "chart");
+    
+            state.getOutputs().add(mainValuesOutput1);
+            state.getOutputs().add(mainValuesOutput2);
+        }
+        return state;
+    }
+
 
         state.getOutputs().add(mainValuesOutput);
         return state;

http://dive4elements.wald.intevation.org