changeset 1946:a584a26d5fde

Introduce pre-rendering inter-facet communication phase ('blackboard pass'). flys-artifacts/trunk@3336 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 30 Nov 2011 10:18:38 +0000
parents f2c14e09a8f1
children 8c0e9d13d1fc
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 2 files changed, 58 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Nov 30 10:13:16 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Nov 30 10:18:38 2011 +0000
@@ -1,3 +1,14 @@
+2011-11-30  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Introduce pre-rendering inter-facet communication phase ('blackboard
+	pass').
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
+	  (doBlackboardPass): New. Before actually calling doOut, bundle
+			      ArtifactAndFacets and let them register
+			      themselfes as DataProvider in CallContext if they
+			      want ("announce on blackboard").
+
 2011-11-30  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Wed Nov 30 10:13:16 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Wed Nov 30 10:18:38 2011 +0000
@@ -30,6 +30,9 @@
 import de.intevation.artifactdatabase.Backend;
 import de.intevation.artifactdatabase.Backend.PersistentArtifact;
 import de.intevation.artifactdatabase.DefaultArtifactCollection;
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.artifactdatabase.state.Blackboard;
+import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifactdatabase.state.StateEngine;
 
 import de.intevation.flys.artifacts.context.FLYSContext;
@@ -46,7 +49,6 @@
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class FLYSArtifactCollection extends DefaultArtifactCollection {
-
     /** The logger used in this class. */
     private static Logger log = Logger.getLogger(FLYSArtifactCollection.class);
 
@@ -269,6 +271,9 @@
         int size = themeList.size();
         log.debug("Output will contain " + size + " elements.");
 
+        List<ArtifactAndFacet> dataProviders =
+            doBlackboardPass(themeList, context);
+
         try {
             for (int i = 0; i < size; i++) {
                 ManagedFacet theme = themeList.get(i);
@@ -279,24 +284,20 @@
                 }
 
                 String art = theme.getArtifact();
+                String facetName = theme.getName();
 
                 if (log.isDebugEnabled()) {
                     log.debug("Do output for...");
                     log.debug("... artifact: " + art);
-                    log.debug("... facet: " + theme.getName());
+                    log.debug("... facet: " + facetName);
                 }
 
-                String facetName = theme.getName();
-
                 if (outName.equals("export") && !facetName.equals(facet)) {
                     continue;
                 }
 
-                Artifact artifact = getArtifact(art, context);
-
                 generator.doOut(
-                    artifact,
-                    theme,
+                    dataProviders.get(i),
                     getFacetThemeFromAttribute(
                         art,
                         outName,
@@ -316,6 +317,44 @@
 
 
     /**
+     * Show blackboard (context) to each facet and create a list of
+     * ArtifactAndFacets on the fly (with the same ordering as the passed
+     * ThemeList).
+     * @param themeList ThemeList to create a ArtifactAndFacetList along.
+     * @param contect   The "Blackboard".
+     */
+    protected List<ArtifactAndFacet> doBlackboardPass(
+        ThemeList themeList, CallContext context
+    ) {
+        ArrayList<ArtifactAndFacet> dataProviders =
+            new ArrayList<ArtifactAndFacet>();
+        int size = themeList.size();
+
+        try {
+            // Collect all ArtifactAndFacets for blackboard pass.
+            for (int i = 0; i < size; i++) {
+                ManagedFacet theme = themeList.get(i);
+                String uuid        = theme.getArtifact();
+                Artifact artifact  = getArtifact(uuid, context);
+                FLYSArtifact flys  = (FLYSArtifact) artifact;
+                ArtifactAndFacet artifactAndFacet = new ArtifactAndFacet(artifact,
+                    flys.getNativeFacet(theme));
+
+                // Show blackboard to facet.
+                artifactAndFacet.register(context);
+
+                // Add to themes.
+                dataProviders.add(i, artifactAndFacet);
+            }
+        }
+        catch (ArtifactDatabaseException ade) {
+            log.error("ArtifactDatabaseException!", ade);
+        }
+
+        return dataProviders;
+    }
+    
+    /**
      * @return masterartifact or null if exception/not found.
      */
     protected FLYSArtifact getMasterArtifact(CallContext context)

http://dive4elements.wald.intevation.org