changeset 1072:80aecb01d79a

Let MainValuesArtifact have a state, outputmode and facet. flys-artifacts/trunk@2556 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 24 Aug 2011 12:07:33 +0000
parents 470087bd39e2
children 107d44b3455d
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StaticState.java
diffstat 2 files changed, 94 insertions(+), 132 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Wed Aug 24 11:40:09 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Wed Aug 24 12:07:33 2011 +0000
@@ -14,18 +14,22 @@
 import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.artifacts.CallContext;
 import de.intevation.artifacts.CallMeta;
-
+import de.intevation.flys.artifacts.states.StaticState;
 import de.intevation.flys.artifacts.context.FLYSContext;
 
 import de.intevation.flys.artifacts.states.DefaultState;
 import de.intevation.artifactdatabase.ProtocolUtils;
+import de.intevation.artifactdatabase.state.DefaultFacet;
 import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifactdatabase.state.DefaultOutput;
 import de.intevation.artifactdatabase.state.Output;
+import de.intevation.artifactdatabase.state.State;
 import de.intevation.artifacts.common.utils.XMLUtils;
 
 /**
  * Artifact to access names of Points Of Interest along a segment of a river.
+ * This artifact neglects (Static)FLYSArtifacts capabilities of interaction
+ * with the StateEngine by overriding the getState*-methods.
  */
 public class MainValuesArtifact
 extends      StaticFLYSArtifact
@@ -35,14 +39,18 @@
 
     /** The name of the artifact. */
     public static final String ARTIFACT_NAME = "mainvalue";
-   
+
+
+    /**
+     * Trivial Constructor.
+     */
     public MainValuesArtifact() {
-        logger.warn("MainValuesArtifact.MainValuesartifact()");
+        logger.debug("MainValuesArtifact.MainValuesartifact()");
     }
 
+
     /**
      * Gets called from factory, to set things up.
-     * Do nothing.
      */
     @Override
     public void setup(
@@ -52,136 +60,77 @@
         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;
+        logger.debug("MainValuesArtifact.setup");
+        super.setup(identifier, factory, context, callMeta, data);
     }
 
 
     /**
-     * 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).
+     * Get a list containing the one and only State.
+     * @param context ignored.
+     * @return list with one and only state.
      */
-    protected void appendOutputModes(
-        Document    doc,
-        Element     outs,
-        CallContext context)
-    {
-        // TODO outputmodes
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
-            doc,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+    @Override
+    protected List<State> getStates(Object context) {
+        ArrayList<State> states = new ArrayList<State>();
+        states.add(getState(null,null));
+        return states;
+    }
 
-        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(
+    /**
+     * Get the "current" state.
+     * @param cc ignored.
+     * @return the "current" state.
+     */
+    @Override
+    protected State getCurrentState(Object cc) {
+        return getState();
+    }
+
+
+    /**
+     * Get the only possible state.
+     * @return the state.
+     */
+    protected State getState() {
+        return getState(null, null);
+    }
+
+
+    /**
+     * Get the state.
+     * @param context ignored.
+     * @param stateID ignored.
+     * @return the state.
+     */
+    @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");
 
-            // 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)) {
-                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.
-        }
+        state.getOutputs().add(mainValuesOutput);
+        return state;
     }
 
 
     /* FACET IMPLEMENTATION  */
-    class MainValuesFacet implements Facet {
+    class MainValuesFacet extends DefaultFacet {
+
+        public MainValuesFacet()
+        {
+        description = "facet.mainvalues";
+        name = "facet.mainvalues";
+        index = 0;
+        }
 
         // TODO implement; what is index used for?
         /**
@@ -201,6 +150,7 @@
          */
         public String getName() {
             // TODO define, static
+            // TODO remove, is part of DefaultFacet.
             return "facet.mainvalue";
         }
  
@@ -211,7 +161,8 @@
          * @return the description of this facet.
          */
         public String getDescription() {
-            return null;
+            // TODO remove, is part of DefaultFacet.
+            return "facet.mainvalues";
         }
  
  
@@ -227,20 +178,15 @@
             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;
-        }
-
+         * Create a deep copy of this Facet.
+         * @return a deep copy.
+         */ 
         public MainValuesFacet deepCopy() {
-            return null;
+            MainValuesFacet copy = new MainValuesFacet();
+            copy.set(this);
+            return copy;
         }
     }
  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StaticState.java	Wed Aug 24 12:07:33 2011 +0000
@@ -0,0 +1,16 @@
+package de.intevation.flys.artifacts.states;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+
+/**
+ * Yet, a non-abstract DefaultState.
+ */
+public class StaticState
+extends      DefaultState
+implements   FacetTypes
+{
+    /** The logger that is used in this state. */
+    private static final Logger logger = Logger.getLogger(StaticState.class);
+}

http://dive4elements.wald.intevation.org