# HG changeset patch # User Felix Wolfsteller # Date 1314268725 0 # Node ID 048517d67215ab842b141955c1651b895ea9c8b1 # Parent 3067e700fc139e36b6e37cba3c18470a60d8321f Changed state spawning mechanism of MainValuesArtifact. flys-artifacts/trunk@2575 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3067e700fc13 -r 048517d67215 flys-artifacts/ChangeLog --- 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 + + * src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java + (getState): + Resolved multiple creation of state (yet not very clean). + 2011-08-25 Felix Wolfsteller * src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java, diff -r 3067e700fc13 -r 048517d67215 flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.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 fs = new ArrayList(); - 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 fs = new ArrayList(); + 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;