comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java @ 7037:5c6fd2c010dd generator-refactoring

Add setup(Element config) method to Generator interface to be initialized from configuration.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 18 Sep 2013 15:04:26 +0200
parents af13ceeba52a
children 24f153ad1f40
comparison
equal deleted inserted replaced
7034:557cb3a3d772 7037:5c6fd2c010dd
11 import java.util.Map; 11 import java.util.Map;
12 12
13 import org.apache.log4j.Logger; 13 import org.apache.log4j.Logger;
14 14
15 import org.w3c.dom.Document; 15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
16 17
17 import org.dive4elements.artifactdatabase.DefaultArtifactContext; 18 import org.dive4elements.artifactdatabase.DefaultArtifactContext;
18 import org.dive4elements.artifacts.CallContext; 19 import org.dive4elements.artifacts.CallContext;
19 import org.dive4elements.river.exports.OutGenerator; 20 import org.dive4elements.river.exports.OutGenerator;
21 import org.dive4elements.river.utils.Pair;
20 22
21 23
22 /** 24 /**
23 * This class is used to store application wide information in a global context. 25 * This class is used to store application wide information in a global context.
24 * 26 *
97 99
98 RiverContext flysContext = context instanceof RiverContext 100 RiverContext flysContext = context instanceof RiverContext
99 ? (RiverContext) context 101 ? (RiverContext) context
100 : (RiverContext) context.globalContext(); 102 : (RiverContext) context.globalContext();
101 103
102 Map<String, Class> generators = (Map<String, Class>) 104 Map<String, Pair<Class<OutGenerator>, Element>> generators =
103 flysContext.get(RiverContext.OUTGENERATORS_KEY); 105 (Map<String, Pair<Class<OutGenerator>, Element>>)flysContext
106 .get(RiverContext.OUTGENERATORS_KEY);
104 107
105 if (generators == null) { 108 if (generators == null) {
106 return null; 109 return null;
107 } 110 }
108 111
109 Class clazz = generators.get(name); 112 Pair<Class<OutGenerator>, Element> pair = generators.get(name);
113
114 if (pair == null) {
115 logger.warn("No generator class found for " + name);
116 return null;
117 }
110 118
111 try { 119 try {
112 return clazz != null ? (OutGenerator) clazz.newInstance() : null; 120 Class<OutGenerator> clazz = pair.getA();
121 OutGenerator generator = clazz.newInstance();
122 generator.setup(pair.getB());
123 return generator;
113 } 124 }
114 catch (InstantiationException ie) { 125 catch (InstantiationException ie) {
115 logger.error(ie, ie); 126 logger.error(ie, ie);
116 } 127 }
117 catch (IllegalAccessException iae) { 128 catch (IllegalAccessException iae) {

http://dive4elements.wald.intevation.org