Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 4fc442f1b4f6 |
children | 28be160b5870 |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.artifacts.context; | |
2 | |
3 import java.util.Map; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Document; | |
8 | |
9 import de.intevation.artifactdatabase.DefaultArtifactContext; | |
10 import de.intevation.artifacts.CallContext; | |
11 import de.intevation.flys.exports.OutGenerator; | |
12 | |
13 | |
14 /** | |
15 * This class is used to store application wide information in a global context. | |
16 * | |
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
18 */ | |
19 public class FLYSContext extends DefaultArtifactContext { | |
20 | |
21 /** The logger used in this class. */ | |
22 private static Logger logger = Logger.getLogger(FLYSContext.class); | |
23 | |
24 /** The key that is used to store the StateEngine in the context. */ | |
25 public static final String ARTIFACT_KEY = | |
26 "artifact"; | |
27 | |
28 /** The key that is used to store the TransitionEngine in the context. */ | |
29 public static final String TRANSITION_ENGINE_KEY = | |
30 "artifact.transition.engine"; | |
31 | |
32 /** The key that is used to store the StateEngine in the context. */ | |
33 public static final String STATE_ENGINE_KEY = | |
34 "artifact.state.engine"; | |
35 | |
36 /** The key that is used to store the Map of OutGenerator classes in the | |
37 * context. */ | |
38 public static final String OUTGENERATORS_KEY = | |
39 "flys.export.outgenerators"; | |
40 | |
41 /** The key that is used to store the map of themes in the context. */ | |
42 public static final String THEMES = | |
43 "flys.themes.map"; | |
44 | |
45 /** The key that is used to store a map of theme mappings in the context. */ | |
46 public static final String THEME_MAPPING = | |
47 "flys.themes.mapping.map"; | |
48 | |
49 /** The key that is used to store a map of WMS urls for each river. */ | |
50 public static final String RIVER_WMS = | |
51 "flys.floodmap.river.wms"; | |
52 | |
53 /** The key that is used to store an instance of Scheduler in the context.*/ | |
54 public static final String SCHEDULER = | |
55 "flys.wsplgen.scheduler"; | |
56 | |
57 | |
58 /** | |
59 * The default constructor. | |
60 */ | |
61 public FLYSContext() { | |
62 super(); | |
63 } | |
64 | |
65 | |
66 /** | |
67 * A constructor with a config document. | |
68 */ | |
69 public FLYSContext(Document config) { | |
70 super(config); | |
71 } | |
72 | |
73 /** | |
74 * Returns the OutGenerator for a specified <i>type</i>. | |
75 * | |
76 * @param name The name of the output type. | |
77 * @param type Defines the type of the desired OutGenerator. | |
78 * | |
79 * @return Instance of an OutGenerator for specified <i>type</i>. | |
80 */ | |
81 public static OutGenerator getOutGenerator( | |
82 CallContext context, | |
83 String name, | |
84 String type) | |
85 { | |
86 | |
87 FLYSContext flysContext = context instanceof FLYSContext | |
88 ? (FLYSContext) context | |
89 : (FLYSContext) context.globalContext(); | |
90 | |
91 Map<String, Class> generators = (Map<String, Class>) | |
92 flysContext.get(FLYSContext.OUTGENERATORS_KEY); | |
93 | |
94 if (generators == null) { | |
95 return null; | |
96 } | |
97 | |
98 Class clazz = generators.get(name); | |
99 | |
100 try { | |
101 return clazz != null ? (OutGenerator) clazz.newInstance() : null; | |
102 } | |
103 catch (InstantiationException ie) { | |
104 logger.error(ie, ie); | |
105 } | |
106 catch (IllegalAccessException iae) { | |
107 logger.error(iae, iae); | |
108 } | |
109 | |
110 return null; | |
111 } | |
112 } | |
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |