comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.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 468d9ebda4ce
children 4e597d435398
comparison
equal deleted inserted replaced
7034:557cb3a3d772 7037:5c6fd2c010dd
22 import org.dive4elements.river.artifacts.transitions.TransitionFactory; 22 import org.dive4elements.river.artifacts.transitions.TransitionFactory;
23 import org.dive4elements.river.themes.Theme; 23 import org.dive4elements.river.themes.Theme;
24 import org.dive4elements.river.themes.ThemeFactory; 24 import org.dive4elements.river.themes.ThemeFactory;
25 import org.dive4elements.river.themes.ThemeGroup; 25 import org.dive4elements.river.themes.ThemeGroup;
26 import org.dive4elements.river.themes.ThemeMapping; 26 import org.dive4elements.river.themes.ThemeMapping;
27 import org.dive4elements.river.utils.Pair;
28 import org.dive4elements.river.exports.OutGenerator;
27 29
28 import java.io.File; 30 import java.io.File;
29 import java.util.ArrayList; 31 import java.util.ArrayList;
30 import java.util.HashMap; 32 import java.util.HashMap;
31 import java.util.List; 33 import java.util.List;
305 * 307 *
306 * @param config the config document. 308 * @param config the config document.
307 * @param context the RiverContext. 309 * @param context the RiverContext.
308 */ 310 */
309 protected void configureOutGenerators(Document config, RiverContext context){ 311 protected void configureOutGenerators(Document config, RiverContext context){
310 Map<String, Class<?>> generators = new HashMap<String, Class<?>>();
311 312
312 NodeList outGenerators = (NodeList) XMLUtils.xpath( 313 NodeList outGenerators = (NodeList) XMLUtils.xpath(
313 config, 314 config,
314 XPATH_OUTPUT_GENERATORS, 315 XPATH_OUTPUT_GENERATORS,
315 XPathConstants.NODESET); 316 XPathConstants.NODESET);
321 return; 322 return;
322 } 323 }
323 324
324 logger.info("Found " + num + " configured output generators."); 325 logger.info("Found " + num + " configured output generators.");
325 326
327 Map<String, Pair<Class<OutGenerator>, Element>> generators =
328 new HashMap<String, Pair<Class<OutGenerator>, Element>>();
329
326 int idx = 0; 330 int idx = 0;
327 331
328 for (int i = 0; i < num; i++) { 332 for (int i = 0; i < num; i++) {
329 Node item = outGenerators.item(i); 333 Element item = (Element)outGenerators.item(i);
330 334
331 String name = (String) XMLUtils.xpath( 335 String name = (String) XMLUtils.xpath(
332 item, "@name", XPathConstants.STRING); 336 item, "@name", XPathConstants.STRING);
333 337
334 String clazz = (String) XMLUtils.xpath( 338 String clazz = (String) XMLUtils.xpath(
337 if (name == null || clazz == null) { 341 if (name == null || clazz == null) {
338 continue; 342 continue;
339 } 343 }
340 344
341 try { 345 try {
342 generators.put(name, Class.forName(clazz)); 346 generators.put(
347 name,
348 new Pair<Class<OutGenerator>, Element>(
349 (Class<OutGenerator>)Class.forName(clazz), item));
343 350
344 idx++; 351 idx++;
345 } 352 }
346 catch (ClassNotFoundException cnfe) { 353 catch (ClassNotFoundException cnfe) {
347 logger.warn(cnfe, cnfe); 354 logger.warn(cnfe, cnfe);

http://dive4elements.wald.intevation.org