diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/DataFacet.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/DataFacet.java@bd047b71ab37
children 4897a58c8746
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/DataFacet.java	Thu Apr 25 15:23:37 2013 +0200
@@ -0,0 +1,107 @@
+package org.dive4elements.river.artifacts.model;
+
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+
+import org.dive4elements.artifactdatabase.state.Facet;
+
+import org.dive4elements.river.artifacts.FLYSArtifact;
+
+import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
+
+public class DataFacet
+extends      BlackboardDataFacet
+{
+    protected ComputeType type;
+    protected String      hash;
+    protected String      stateId;
+
+
+    /** Trivial constructor. */
+    public DataFacet() {
+    }
+
+    /**
+     * Defaults to ADVANCE Compute type.
+     * @param name Name of the facet.
+     * @param description maybe localized description of the facet.
+     */
+    public DataFacet(String name, String description) {
+        this(name, description, ComputeType.ADVANCE);
+    }
+
+
+    public DataFacet(String name, String description, ComputeType type) {
+        this(name, description, type, null);
+    }
+
+
+    public DataFacet(
+        String      name,
+        String      description,
+        ComputeType type,
+        String      hash
+    ) {
+        super(name, description);
+        this.type = type;
+        this.hash = hash;
+    }
+
+
+    public DataFacet(
+        String      name,
+        String      description,
+        ComputeType type,
+        String      hash,
+        String      stateId
+    ) {
+        super(name, description);
+        this.type    = type;
+        this.hash    = hash;
+        this.stateId = stateId;
+    }
+
+
+    public DataFacet(
+        int         index,
+        String      name,
+        String      description,
+        ComputeType type,
+        String      hash,
+        String      stateId
+    ) {
+        super(index, name, description);
+        this.type    = type;
+        this.hash    = hash;
+        this.stateId = stateId;
+    }
+
+
+    /**
+     * Return computation result.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        FLYSArtifact flys = (FLYSArtifact)artifact;
+        String    theHash = (hash != null) ? hash : flys.hash();
+
+        return (stateId != null && stateId.length() > 0)
+            ? flys.compute(context, theHash, stateId, type, false)
+            : flys.compute(context, theHash, type, false);
+    }
+
+
+    /**
+     * Return a deep copy.
+     */
+    @Override
+    public Facet deepCopy() {
+        DataFacet copy = new DataFacet();
+        copy.set(this);
+        copy.type    = type;
+        copy.hash    = hash;
+        copy.stateId = stateId;
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org