Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java @ 5866:9a6741ccf6d4
FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 28 Apr 2013 15:14:30 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/artifacts/context/FLYSContext.java@4897a58c8746 |
children | af13ceeba52a |
comparison
equal
deleted
inserted
replaced
5865:73da40528cf2 | 5866:9a6741ccf6d4 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts.context; | |
10 | |
11 import java.util.Map; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
15 import org.w3c.dom.Document; | |
16 | |
17 import org.dive4elements.artifactdatabase.DefaultArtifactContext; | |
18 import org.dive4elements.artifacts.CallContext; | |
19 import org.dive4elements.river.exports.OutGenerator; | |
20 | |
21 | |
22 /** | |
23 * This class is used to store application wide information in a global context. | |
24 * | |
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
26 */ | |
27 public class RiverContext extends DefaultArtifactContext { | |
28 | |
29 /** The logger used in this class. */ | |
30 private static Logger logger = Logger.getLogger(RiverContext.class); | |
31 | |
32 /** The key that is used to store the StateEngine in the context. */ | |
33 public static final String ARTIFACT_KEY = | |
34 "artifact"; | |
35 | |
36 /** The key that is used to store the TransitionEngine in the context. */ | |
37 public static final String TRANSITION_ENGINE_KEY = | |
38 "artifact.transition.engine"; | |
39 | |
40 /** The key that is used to store the StateEngine in the context. */ | |
41 public static final String STATE_ENGINE_KEY = | |
42 "artifact.state.engine"; | |
43 | |
44 /** The key that is used to store the Map of OutGenerator classes in the | |
45 * context. */ | |
46 public static final String OUTGENERATORS_KEY = | |
47 "flys.export.outgenerators"; | |
48 | |
49 /** The key that is used to store the map of themes in the context. */ | |
50 public static final String THEMES = | |
51 "flys.themes.map"; | |
52 | |
53 /** The key that is used to store a map of theme mappings in the context. */ | |
54 public static final String THEME_MAPPING = | |
55 "flys.themes.mapping.map"; | |
56 | |
57 /** The key that is used to store a map of WMS urls for each river. */ | |
58 public static final String RIVER_WMS = | |
59 "flys.floodmap.river.wms"; | |
60 | |
61 /** The key that is used to store an instance of Scheduler in the context.*/ | |
62 public static final String SCHEDULER = | |
63 "flys.wsplgen.scheduler"; | |
64 | |
65 /** Key to store the configured modules in the context. */ | |
66 public static final String MODULES = "flys.modules"; | |
67 | |
68 | |
69 /** | |
70 * The default constructor. | |
71 */ | |
72 public RiverContext() { | |
73 super(); | |
74 } | |
75 | |
76 | |
77 /** | |
78 * A constructor with a config document. | |
79 */ | |
80 public RiverContext(Document config) { | |
81 super(config); | |
82 } | |
83 | |
84 /** | |
85 * Returns the OutGenerator for a specified <i>type</i>. | |
86 * | |
87 * @param name The name of the output type. | |
88 * @param type Defines the type of the desired OutGenerator. | |
89 * | |
90 * @return Instance of an OutGenerator for specified <i>type</i>. | |
91 */ | |
92 public static OutGenerator getOutGenerator( | |
93 CallContext context, | |
94 String name, | |
95 String type) | |
96 { | |
97 | |
98 RiverContext flysContext = context instanceof RiverContext | |
99 ? (RiverContext) context | |
100 : (RiverContext) context.globalContext(); | |
101 | |
102 Map<String, Class> generators = (Map<String, Class>) | |
103 flysContext.get(RiverContext.OUTGENERATORS_KEY); | |
104 | |
105 if (generators == null) { | |
106 return null; | |
107 } | |
108 | |
109 Class clazz = generators.get(name); | |
110 | |
111 try { | |
112 return clazz != null ? (OutGenerator) clazz.newInstance() : null; | |
113 } | |
114 catch (InstantiationException ie) { | |
115 logger.error(ie, ie); | |
116 } | |
117 catch (IllegalAccessException iae) { | |
118 logger.error(iae, iae); | |
119 } | |
120 | |
121 return null; | |
122 } | |
123 } | |
124 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |