changeset 7226:8ab618dda850

Made lookup for generators a class of its own. First step to use it as a compat filter for facets, too.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 02 Oct 2013 18:41:12 +0200
parents fa66845c1977
children 744df5a03337
files artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java artifacts/src/main/java/org/dive4elements/river/exports/GeneratorLookup.java
diffstat 3 files changed, 45 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java	Wed Oct 02 14:14:09 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java	Wed Oct 02 18:41:12 2013 +0200
@@ -8,14 +8,13 @@
 
 package org.dive4elements.river.artifacts.context;
 
-import java.util.Map;
-
 import org.apache.log4j.Logger;
 
 import org.w3c.dom.Document;
 
 import org.dive4elements.artifactdatabase.DefaultArtifactContext;
 import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.exports.GeneratorLookup;
 import org.dive4elements.river.exports.OutGenerator;
 import org.dive4elements.river.utils.Pair;
 
@@ -100,15 +99,14 @@
             ? (RiverContext) context
             : (RiverContext) context.globalContext();
 
-        Map<String, Pair<Class<OutGenerator>, Object>> generators =
-            (Map<String, Pair<Class<OutGenerator>, Object>>)flysContext
-                .get(RiverContext.OUTGENERATORS_KEY);
+        GeneratorLookup generators =
+            (GeneratorLookup)flysContext.get(RiverContext.OUTGENERATORS_KEY);
 
         if (generators == null) {
             return null;
         }
 
-        Pair<Class<OutGenerator>, Object> pair = generators.get(name);
+        Pair<Class<OutGenerator>, Object> pair = generators.getGenerator(name);
 
         if (pair == null) {
             logger.warn("No generator class found for " + name);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Wed Oct 02 14:14:09 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Wed Oct 02 18:41:12 2013 +0200
@@ -39,6 +39,7 @@
 
 import org.dive4elements.river.artifacts.transitions.TransitionFactory;
 
+import org.dive4elements.river.exports.GeneratorLookup;
 import org.dive4elements.river.exports.OutGenerator;
 
 import org.dive4elements.river.themes.Theme;
@@ -46,8 +47,6 @@
 import org.dive4elements.river.themes.ThemeGroup;
 import org.dive4elements.river.themes.ThemeMapping;
 
-import org.dive4elements.river.utils.Pair;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -335,8 +334,7 @@
 
         logger.info("Found " + num + " configured output generators.");
 
-        Map<String, Pair<Class<OutGenerator>, Object>> generators =
-            new HashMap<String, Pair<Class<OutGenerator>, Object>>();
+        GeneratorLookup generators = new GeneratorLookup();
 
         int idx = 0;
 
@@ -381,12 +379,9 @@
                 }
             }
 
-            Pair<Class<OutGenerator>, Object> pair =
-                new Pair<Class<OutGenerator>, Object>(generatorClass, cfg);
-
             for (String key: names.split("[\\s,]")) {
                 if (!(key = key.trim()).isEmpty()) {
-                    generators.put(key, pair);
+                    generators.putGenerator(key, generatorClass, cfg);
                     idx++;
                 }
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/GeneratorLookup.java	Wed Oct 02 18:41:12 2013 +0200
@@ -0,0 +1,38 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.exports;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.dive4elements.river.utils.Pair;
+
+public class GeneratorLookup
+{
+    private Map<String, Pair<Class<OutGenerator>, Object>> generators;
+
+    public GeneratorLookup() {
+        generators = new HashMap<String, Pair<Class<OutGenerator>, Object>>();
+    }
+
+    public void putGenerator(
+        String              outName,
+        Class<OutGenerator> generatorClass,
+        Object              ctx
+    ) {
+        Pair<Class<OutGenerator>, Object> pair =
+            new Pair<Class<OutGenerator>, Object>(generatorClass, ctx);
+        generators.put(outName, pair);
+    }
+
+    public Pair<Class<OutGenerator>, Object> getGenerator(String outName) {
+        return generators.get(outName);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org