changeset 1059:fdb0f4ef96f0

Made FLYS artifacts cloneable. flys-artifacts/trunk@2531 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 23 Aug 2011 11:07:21 +0000
parents c37084f31c84
children 2d60a875e28c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java
diffstat 3 files changed, 53 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Aug 23 07:53:41 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Aug 23 11:07:21 2011 +0000
@@ -1,3 +1,12 @@
+2011-08-23  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java:
+	  Removed facet interface.
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
+	  Make artifacts cloneable. TODO: Override deepCopy() in subclassed
+	  states and facets.
+
 2011-08-23  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/conf.xml: Added the MapInfoService and adapted the floodmap
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Tue Aug 23 07:53:41 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Tue Aug 23 11:07:21 2011 +0000
@@ -121,8 +121,9 @@
      *
      * @return the name of the concrete artifact.
      */
-    public abstract String getName();
-
+    public String getName() {
+        return name;
+    }
 
     /**
      * Returns the FLYSContext from context object.
@@ -190,13 +191,52 @@
         filterFacets = buildFilterFacets(data);
     }
 
+    protected List<String> clonePreviousStateIds() {
+        return new ArrayList<String>(previousStateIds);
+    }
+
+    protected Map<String, StateData> cloneData() {
+        Map<String, StateData> copy = new TreeMap<String, StateData>();
+
+        for (Map.Entry<String, StateData> entry: data.entrySet()) {
+            copy.put(entry.getKey(), entry.getValue().deepCopy());
+        }
+
+        return copy;
+    }
+
+    protected Map<String, List<Facet>> cloneFacets() {
+        Map copy = new HashMap<String, List<Facet>>();
+
+        for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) {
+            List<Facet> facets      = entry.getValue();
+            List<Facet> facetCopies = new ArrayList<Facet>(facets.size());
+            for (Facet facet: facets) {
+                facetCopies.add(facet.deepCopy());
+            }
+            copy.put(entry.getKey(), facetCopies);
+        }
+
+        return copy;
+    }
 
     protected void initialize(
         Artifact artifact,
         Object   context,
         CallMeta callMeta)
     {
-        // do nothing here
+        if (!(artifact instanceof FLYSArtifact)) {
+            return;
+        }
+
+        FLYSArtifact flys = (FLYSArtifact)artifact;
+
+        currentStateId   = flys.currentStateId;
+        previousStateIds = flys.clonePreviousStateIds();
+        name             = flys.name;
+        data             = flys.cloneData();
+        facets           = flys.cloneFacets();
+        // Do not clone filter facets!
     }
 
     protected Map<String, List<Facet>> buildFilterFacets(Document document) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Tue Aug 23 07:53:41 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Tue Aug 23 11:07:21 2011 +0000
@@ -29,8 +29,7 @@
  */
 public class MainValuesArtifact
 extends      StaticFLYSArtifact
-implements   Facet {
-
+{
     /** The logger for this class. */
     private static Logger logger = Logger.getLogger(WINFOArtifact.class);
 
@@ -54,7 +53,6 @@
         Document        data)
     {
         logger.warn("MainValuesArtifact.setup");
-        ; 
     }
 
     /**
@@ -180,65 +178,4 @@
             // 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