[PATCH] Made lookup for generators a class of its own. First step to use it as a compat filter for facets, too

Wald Commits scm-commit at wald.intevation.org
Wed Oct 2 18:41:17 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1380732072 -7200
# Node ID 8ab618dda8502b7ff519c3b96ace98159d577d41
# Parent  fa66845c19777dae2ccbb196256caccd85a714d1
Made lookup for generators a class of its own. First step to use it as a compat filter for facets, too.

diff -r fa66845c1977 -r 8ab618dda850 artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java
--- 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);
diff -r fa66845c1977 -r 8ab618dda850 artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java
--- 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++;
                 }
             }
diff -r fa66845c1977 -r 8ab618dda850 artifacts/src/main/java/org/dive4elements/river/exports/GeneratorLookup.java
--- /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 :


More information about the Dive4elements-commits mailing list