changeset 7073:beb9e94f04d3 generator-refactoring

Allow comma separated names in "names" attribute in out generators to allow registering for more than one name. Old "name" attribute is removed.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 20 Sep 2013 15:42:21 +0200
parents 4e597d435398
children a2abd87c0d3b
files artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java
diffstat 1 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Fri Sep 20 15:29:02 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java	Fri Sep 20 15:42:21 2013 +0200
@@ -332,23 +332,31 @@
         for (int i = 0; i < num; i++) {
             Element item = (Element)outGenerators.item(i);
 
-            String name = item.getAttribute("name");
+            String name  = item.getAttribute("names");
             String clazz = item.getAttribute("class");
 
             if (name.isEmpty() || clazz.isEmpty()) {
                 continue;
             }
 
+            Class<OutGenerator> generatorClass = null;
+
             try {
-                generators.put(
-                    name,
-                    new Pair<Class<OutGenerator>, Element>(
-                        (Class<OutGenerator>)Class.forName(clazz), item));
-
-                idx++;
+                generatorClass = (Class<OutGenerator>)Class.forName(clazz);
             }
             catch (ClassNotFoundException cnfe) {
                 logger.warn(cnfe, cnfe);
+                continue;
+            }
+
+            Pair<Class<OutGenerator>, Element> pair =
+                new Pair<Class<OutGenerator>, Element>(generatorClass, item);
+
+            for (String key: name.split("[\\s,]")) {
+                if (!(key = key.trim()).isEmpty()) {
+                    generators.put(key, pair);
+                    idx++;
+                }
             }
         }
 

http://dive4elements.wald.intevation.org