Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java @ 7099:24f153ad1f40 generator-refactoring
Use pre-converted diagram attributes now.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 23 Sep 2013 12:28:22 +0200 |
parents | a2abd87c0d3b |
children | 8ab618dda850 |
comparison
equal
deleted
inserted
replaced
7098:7dc31a235232 | 7099:24f153ad1f40 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.context; | 9 package org.dive4elements.river.artifacts.context; |
10 | 10 |
11 import java.io.File; | |
12 | |
13 import java.util.ArrayList; | |
14 import java.util.HashMap; | |
15 import java.util.List; | |
16 import java.util.Map; | |
17 | |
18 import javax.xml.xpath.XPathConstants; | |
19 | |
20 import org.apache.log4j.Logger; | |
21 | |
11 import org.dive4elements.artifactdatabase.state.State; | 22 import org.dive4elements.artifactdatabase.state.State; |
12 import org.dive4elements.artifactdatabase.state.StateEngine; | 23 import org.dive4elements.artifactdatabase.state.StateEngine; |
24 | |
13 import org.dive4elements.artifactdatabase.transition.Transition; | 25 import org.dive4elements.artifactdatabase.transition.Transition; |
14 import org.dive4elements.artifactdatabase.transition.TransitionEngine; | 26 import org.dive4elements.artifactdatabase.transition.TransitionEngine; |
27 | |
15 import org.dive4elements.artifacts.ArtifactContextFactory; | 28 import org.dive4elements.artifacts.ArtifactContextFactory; |
16 import org.dive4elements.artifacts.GlobalContext; | 29 import org.dive4elements.artifacts.GlobalContext; |
30 | |
17 import org.dive4elements.artifacts.common.utils.Config; | 31 import org.dive4elements.artifacts.common.utils.Config; |
32 import org.dive4elements.artifacts.common.utils.ElementConverter; | |
18 import org.dive4elements.artifacts.common.utils.XMLUtils; | 33 import org.dive4elements.artifacts.common.utils.XMLUtils; |
34 | |
19 import org.dive4elements.river.artifacts.model.Module; | 35 import org.dive4elements.river.artifacts.model.Module; |
20 import org.dive4elements.river.artifacts.model.ZoomScale; | 36 import org.dive4elements.river.artifacts.model.ZoomScale; |
37 | |
21 import org.dive4elements.river.artifacts.states.StateFactory; | 38 import org.dive4elements.river.artifacts.states.StateFactory; |
39 | |
22 import org.dive4elements.river.artifacts.transitions.TransitionFactory; | 40 import org.dive4elements.river.artifacts.transitions.TransitionFactory; |
41 | |
42 import org.dive4elements.river.exports.OutGenerator; | |
43 | |
23 import org.dive4elements.river.themes.Theme; | 44 import org.dive4elements.river.themes.Theme; |
24 import org.dive4elements.river.themes.ThemeFactory; | 45 import org.dive4elements.river.themes.ThemeFactory; |
25 import org.dive4elements.river.themes.ThemeGroup; | 46 import org.dive4elements.river.themes.ThemeGroup; |
26 import org.dive4elements.river.themes.ThemeMapping; | 47 import org.dive4elements.river.themes.ThemeMapping; |
48 | |
27 import org.dive4elements.river.utils.Pair; | 49 import org.dive4elements.river.utils.Pair; |
28 import org.dive4elements.river.exports.OutGenerator; | 50 |
29 | |
30 import java.io.File; | |
31 import java.util.ArrayList; | |
32 import java.util.HashMap; | |
33 import java.util.List; | |
34 import java.util.Map; | |
35 | |
36 import javax.xml.xpath.XPathConstants; | |
37 | |
38 import org.apache.log4j.Logger; | |
39 import org.w3c.dom.Document; | 51 import org.w3c.dom.Document; |
40 import org.w3c.dom.Element; | 52 import org.w3c.dom.Element; |
41 import org.w3c.dom.Node; | 53 import org.w3c.dom.Node; |
42 import org.w3c.dom.NodeList; | 54 import org.w3c.dom.NodeList; |
43 | |
44 | 55 |
45 /** | 56 /** |
46 * The ArtifactContextFactory is used to initialize basic components and put | 57 * The ArtifactContextFactory is used to initialize basic components and put |
47 * them into the global context of the application. | 58 * them into the global context of the application. |
48 * | 59 * |
322 return; | 333 return; |
323 } | 334 } |
324 | 335 |
325 logger.info("Found " + num + " configured output generators."); | 336 logger.info("Found " + num + " configured output generators."); |
326 | 337 |
327 Map<String, Pair<Class<OutGenerator>, Element>> generators = | 338 Map<String, Pair<Class<OutGenerator>, Object>> generators = |
328 new HashMap<String, Pair<Class<OutGenerator>, Element>>(); | 339 new HashMap<String, Pair<Class<OutGenerator>, Object>>(); |
329 | 340 |
330 int idx = 0; | 341 int idx = 0; |
331 | 342 |
332 for (int i = 0; i < num; i++) { | 343 for (int i = 0; i < num; i++) { |
333 Element item = (Element)outGenerators.item(i); | 344 Element item = (Element)outGenerators.item(i); |
334 | 345 |
335 String names = item.getAttribute("names").trim(); | 346 String names = item.getAttribute("names").trim(); |
336 String clazz = item.getAttribute("class").trim(); | 347 String clazz = item.getAttribute("class").trim(); |
348 String converter = item.getAttribute("converter").trim(); | |
337 | 349 |
338 if (names.isEmpty() || clazz.isEmpty()) { | 350 if (names.isEmpty() || clazz.isEmpty()) { |
339 continue; | 351 continue; |
340 } | 352 } |
341 | 353 |
343 | 355 |
344 try { | 356 try { |
345 generatorClass = (Class<OutGenerator>)Class.forName(clazz); | 357 generatorClass = (Class<OutGenerator>)Class.forName(clazz); |
346 } | 358 } |
347 catch (ClassNotFoundException cnfe) { | 359 catch (ClassNotFoundException cnfe) { |
348 logger.warn(cnfe, cnfe); | 360 logger.error(cnfe, cnfe); |
349 continue; | 361 continue; |
350 } | 362 } |
351 | 363 |
352 Pair<Class<OutGenerator>, Element> pair = | 364 Object cfg = null; |
353 new Pair<Class<OutGenerator>, Element>(generatorClass, item); | 365 |
366 if (!converter.isEmpty()) { | |
367 try { | |
368 ElementConverter ec = | |
369 (ElementConverter)Class.forName(converter) | |
370 .newInstance(); | |
371 cfg = ec.convert(item); | |
372 } | |
373 catch (ClassNotFoundException cnfe) { | |
374 logger.error(cnfe, cnfe); | |
375 } | |
376 catch (InstantiationException ie) { | |
377 logger.error(ie); | |
378 } | |
379 catch (IllegalAccessException iae) { | |
380 logger.error(iae); | |
381 } | |
382 } | |
383 | |
384 Pair<Class<OutGenerator>, Object> pair = | |
385 new Pair<Class<OutGenerator>, Object>(generatorClass, cfg); | |
354 | 386 |
355 for (String key: names.split("[\\s,]")) { | 387 for (String key: names.split("[\\s,]")) { |
356 if (!(key = key.trim()).isEmpty()) { | 388 if (!(key = key.trim()).isEmpty()) { |
357 generators.put(key, pair); | 389 generators.put(key, pair); |
358 idx++; | 390 idx++; |