changeset 1047:38088c982db6

Added stub implementation of new MainValuesArtifact. flys-artifacts/trunk@2509 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 19 Aug 2011 10:17:08 +0000
parents 0a5eff5511b1
children fd5c70973e0b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java
diffstat 2 files changed, 253 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Aug 19 09:48:13 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Aug 19 10:17:08 2011 +0000
@@ -1,3 +1,10 @@
+2011-08-19  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Added stub implementation of new MainValuesArtifact.
+
+	* src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java:
+	  New. Stub implementation for new MainValuesArtifact.
+
 2011-08-19  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	Fixed flys/issue262
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Fri Aug 19 10:17:08 2011 +0000
@@ -0,0 +1,246 @@
+package de.intevation.flys.artifacts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.flys.artifacts.context.FLYSContext;
+
+import de.intevation.flys.artifacts.states.DefaultState;
+import de.intevation.artifactdatabase.ProtocolUtils;
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.Output;
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+/**
+ * Artifact to access names of Points Of Interest along a segment of a river.
+ */
+public class MainValuesArtifact
+extends      StaticFLYSArtifact
+implements   Facet {
+
+    /** The logger for this class. */
+    private static Logger logger = Logger.getLogger(WINFOArtifact.class);
+
+    /** The name of the artifact. */
+    public static final String ARTIFACT_NAME = "annotation";
+   
+    public MainValuesArtifact() {
+        logger.warn("MainValuesArtifact.MainValuesartifact()");
+    }
+
+    /**
+     * Gets called from factory, to set things up.
+     * Do nothing.
+     */
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callMeta,
+        Document        data)
+    {
+        logger.warn("MainValuesArtifact.setup");
+        ; 
+    }
+
+    /**
+     * Create the description of this MainValuesArtiface-instance.
+     *
+     * @param data    some data.
+     * @param context the CallContext.
+     *
+     * @return the description of this artifact.
+     */
+    @Override
+    public Document describe(Document data, CallContext context) {
+        logger.debug("MainValuesArtifact.describe");
+
+        if (logger.isDebugEnabled()) {
+            dumpArtifact();
+        }
+
+        FLYSContext flysContext = getFlysContext(context);
+
+        Document description            = XMLUtils.newDocument();
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+            description,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = ProtocolUtils.createRootNode(creator);
+        description.appendChild(root);
+
+        ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
+
+        Element name = ProtocolUtils.createArtNode(
+            creator, "name",
+            new String[] { "value" },
+            new String[] { getName() });
+
+        Element outs = ProtocolUtils.createArtNode(
+            creator, "outputmodes", null, null);
+        appendOutputModes(description, outs, context);
+
+        root.appendChild(name);
+        root.appendChild(outs);
+
+        return description;
+    }
+
+
+    /**
+     * Append outputmode elements to given document.
+     *
+     * @param doc Document to add outputmodes to.
+     * @param outs Element to add outputmode elements to.
+     * @param context The given CallContext (mostly for internationalization).
+     */
+    protected void appendOutputModes(
+        Document    doc,
+        Element     outs,
+        CallContext context)
+    {
+        // TODO outputmodes
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        FLYSContext flysContext = getFlysContext(context);
+
+        for (int i = 0; i < 1; i++) {
+            logger.debug("Append output mode.");
+
+            // TODO create outputs.
+            /*
+            List<Output> list = state.getOutputs();
+            if (list == null || list.size() == 0) {
+                logger.debug("-> No output modes for this state.");
+                continue;
+            }*/
+            List<Facet>  fs = new ArrayList<Facet>();
+            DefaultOutput mainValuesOutput = new DefaultOutput(
+                    "discharge_curve", "output.discharge_curve", "image/png",
+                    fs,
+                    "chart");
+
+            // Create facets.
+            if (fs == null || fs.size() == 0) {
+                logger.debug("No facets found.");
+                continue;
+            }
+            logger.debug("Built stateless facets.");
+            // TODO remember issues here.
+            //List<Output> generated = generateOutputs(list, fs);
+            //ProtocolUtils.appendOutputModes(doc, outs, generated);
+        }
+
+        try {
+            DefaultState cur = (DefaultState) getCurrentState(context);
+            if (cur.validate(this, context)) {
+                List<Output> list = cur.getOutputs();
+                if (list != null && list.size() > 0) {
+                    logger.debug(
+                        "Append output modes for state: " + cur.getID());
+
+                    List<Facet>  fs = facets.get(cur.getID());
+                    if (fs != null && fs.size() > 0) {
+                        List<Output> generated = generateOutputs(list, fs);
+
+                        logger.debug("Found " + fs.size() + " current facets.");
+                        if (!generated.isEmpty()) {
+                            ProtocolUtils.appendOutputModes(
+                                doc, outs, generated);
+                        }
+                        else{
+                            logger.debug("Cannot append output to generated document.");
+                        }
+                    }
+                    else {
+                        logger.debug("No facets found for the current state.");
+                    }
+                }
+            }
+        }
+        catch (IllegalArgumentException iae) {
+            // state is not valid, so we do not append its outputs.
+        }
+    }
+
+
+    /* FACET IMPLEMENTATION  */
+
+
+    // TODO implement; what is index used for?
+    /**
+     * Returns the index of this facet.
+     *
+     * @return the index of this facet.
+     */
+    public int getIndex() {
+        return 0;
+    }
+
+
+    /**
+     * Returns the name of this facet.
+     *
+     * @return the name of this facet.
+     */
+    public String getName() {
+        // TODO define, static
+        return "FACETNAME";
+    }
+
+
+    /**
+     * Returns the description of this facet.
+     *
+     * @return the description of this facet.
+     */
+    public String getDescription() {
+        return null;
+    }
+
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact The owner artifact.
+     * @param context The CallContext.
+     *
+     * @return the data.
+     */
+    public Object getData(Artifact artifact, CallContext context) {
+        return null;
+    }
+
+
+    /**
+     * Write the internal representation of a facet to a node.
+     *
+     * @param doc A Document.
+     *
+     * @return the representation as Node.
+     */
+    public Node toXML(Document doc) {
+        return null;
+    }
+ 
+}

http://dive4elements.wald.intevation.org