changeset 355:6bd37edd9a80

Added handy implementation of a DataProvider. artifacts/trunk@3333 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 30 Nov 2011 08:28:04 +0000
parents c83519249fea
children 079ab7c971a4
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/state/ArtifactAndFacet.java
diffstat 2 files changed, 82 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Nov 30 08:25:10 2011 +0000
+++ b/ChangeLog	Wed Nov 30 08:28:04 2011 +0000
@@ -1,3 +1,14 @@
+2011-11-30	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Added convenienve bundle of artifact and facet that implements
+	DataProvider. This will help keeping things together in the upcoming
+	inter-facet pre-rendering communication ('blackboard') phase.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/ArtifactAndFacet.java:
+	  New class, keeping together an artifact and a facet (thus, should
+	  only have a short live span). Only implementation of the new
+	  DataProvider interface.
+
 2011-11-30	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Extended CallContext to also act as a blackboard/service broker.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/ArtifactAndFacet.java	Wed Nov 30 08:28:04 2011 +0000
@@ -0,0 +1,71 @@
+package de.intevation.artifactdatabase.state;
+
+import java.util.List;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.DataProvider;
+
+
+/**
+ * A bundle of a "native" Facet and its Artifact.
+ */
+public class ArtifactAndFacet implements DataProvider {
+    /** The Artifact. */
+    protected Artifact artifact;
+    /** The (native) facet. */
+    protected Facet    facet;
+
+    
+    /** Trivial constructor. */
+    public ArtifactAndFacet(
+        Artifact a,
+        Facet f
+    ) {
+        this.artifact   = a;
+        this.facet      = f;
+    }
+
+
+    /** Get data (to plot). */
+    public Object getData(CallContext context) {
+        return facet.getData(artifact, context);
+    }
+
+
+    /** Get data (for other facet). */
+    public Object provideData(Object key, Object param, CallContext context) {
+        return facet.provideBlackboardData(artifact, key, param, context);
+    }
+
+
+    /** (Maybe) Register on blackboard (depending on facet). */
+    public void register(CallContext context) {
+        List keys = facet.getDataProviderKeys();
+        if (keys == null) {
+            return;
+        }
+        for (Object key: keys) {
+            context.registerDataProvider(key, this);
+        }
+    }
+
+
+    /** Access the artifact. */
+    public Artifact getArtifact() {
+        return artifact;
+    }
+
+
+    /** Access the (native) facet. */
+    public Facet getFacet() {
+        return facet;
+    }
+
+
+    /** Shortcut to facets name. */
+    public String getFacetName() {
+        return facet.getName();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org