changeset 1964:85e442933e6d

New CrossSectionArtifact. flys-artifacts/trunk@3374 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 09 Dec 2011 13:58:29 +0000
parents 6c24ffe946a5
children e71615d95afb
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java
diffstat 2 files changed, 138 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Dec 09 10:33:40 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Dec 09 13:58:29 2011 +0000
@@ -1,3 +1,8 @@
+2011-12-09	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java:
+	  New artifact to handle cross-section access.
+
 2011-12-09  Raimund Renkert <raimund.renkert@intevation.de>
 
 	Issue 413.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java	Fri Dec 09 13:58:29 2011 +0000
@@ -0,0 +1,133 @@
+package de.intevation.flys.artifacts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.flys.artifacts.model.CrossSectionFacet;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.artifacts.states.StaticState;
+
+import de.intevation.artifactdatabase.data.DefaultStateData;
+import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.State;
+
+import de.intevation.flys.artifacts.states.WMSBackgroundState;
+
+
+public class CrossSectionArtifact extends StaticFLYSArtifact {
+
+    /** Access ids of doc. */
+    public static final String XPATH_IDS = "/art:action/art:ids/@value";
+
+    /** Name of Artifact. */
+    public static final String CS_ARTIFACT_NAME = "cross_section";
+
+    /** Name of state. */
+    public static final String STATIC_STATE_NAME = "state.cross_section";
+
+    /** Own logger. */
+    private static final Logger logger =
+        Logger.getLogger(CrossSectionArtifact.class);
+
+
+    /** Return given name. */
+    @Override
+    public String getName() {
+        return CS_ARTIFACT_NAME;
+    }
+
+
+    /** Store ids, create a (broken) CrossSectionFacet. */
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callMeta,
+        Document        data)
+    {
+        logger.info("CrossSectionArtifact.setup");
+
+        super.setup(identifier, factory, context, callMeta, data);
+
+        String ids = XMLUtils.xpathString(
+            data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE);
+
+        if (ids != null && ids.length() > 0) {
+            addStringData("ids", ids);
+        }
+        else {
+            throw new IllegalArgumentException("No attribute 'ids' found!");
+        }
+
+        List<Facet> fs = new ArrayList<Facet>();
+        fs.add(new CrossSectionFacet(0, "TODO GET NAME FROM DB"));
+
+        StaticState state = (StaticState) getCurrentState(context);
+        state.computeInit(this, hash(), context, callMeta, fs);
+
+        if (!fs.isEmpty()) {
+            facets.put(getCurrentStateId(), fs);
+        }
+    }
+
+
+    /** Do not copy data from daddyfact. */
+    @Override
+    protected void initialize(
+        Artifact artifact,
+        Object   context,
+        CallMeta callMeta)
+    {
+        // do nothing
+    }
+
+
+    /**
+     * Create and return a new StaticState with charting output.
+     */
+    @Override
+    public State getCurrentState(Object cc) {
+        State state = new StaticState(STATIC_STATE_NAME);
+
+        List<Facet> fs = facets.get(getCurrentStateId());
+
+        DefaultOutput o = new DefaultOutput(
+            "cross_section",
+            "cross_section",
+            "image/png",
+            fs,
+            "chart");
+
+        state.getOutputs().add(o);
+
+        return state;
+    }
+
+
+    /**
+     * Get a list containing the one and only State.
+     * @param  context ignored.
+     * @return list with one and only state.
+     */
+    @Override
+    protected List<State> getStates(Object context) {
+        ArrayList<State> states = new ArrayList<State>();
+        states.add(getCurrentState(context));
+
+        return states;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org