comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java @ 295:53c155bfde07

Added code to parse the configured OutGenerators in the global configuration and to save a map of such in the FLYSContext. flys-artifacts/trunk@1633 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 31 Mar 2011 10:56:08 +0000
parents 1fa38d60a702
children eca7892bf8ff
comparison
equal deleted inserted replaced
294:e5e7af208857 295:53c155bfde07
1 package de.intevation.flys.artifacts.context; 1 package de.intevation.flys.artifacts.context;
2 2
3 import java.io.File; 3 import java.io.File;
4 import java.util.ArrayList; 4 import java.util.ArrayList;
5 import java.util.HashMap;
5 import java.util.List; 6 import java.util.List;
7 import java.util.Map;
6 8
7 import javax.xml.xpath.XPathConstants; 9 import javax.xml.xpath.XPathConstants;
8 10
9 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
10 12
11 import org.w3c.dom.Document; 13 import org.w3c.dom.Document;
12 import org.w3c.dom.Element; 14 import org.w3c.dom.Element;
15 import org.w3c.dom.Node;
13 import org.w3c.dom.NodeList; 16 import org.w3c.dom.NodeList;
14 17
15 import de.intevation.artifacts.ArtifactContextFactory; 18 import de.intevation.artifacts.ArtifactContextFactory;
16 19
17 import de.intevation.artifacts.common.utils.XMLUtils; 20 import de.intevation.artifacts.common.utils.XMLUtils;
53 56
54 /** The XPath to the states configured in the artifact config. */ 57 /** The XPath to the states configured in the artifact config. */
55 public static final String XPATH_STATES = 58 public static final String XPATH_STATES =
56 "/artifact/states/state"; 59 "/artifact/states/state";
57 60
61 public static final String XPATH_OUTPUT_GENERATORS =
62 "/artifact-database/output-generators/output-generator";
63
58 /** 64 /**
59 * Creates a new FLYSArtifactContext object and initialize all 65 * Creates a new FLYSArtifactContext object and initialize all
60 * components required by the application. 66 * components required by the application.
61 * 67 *
62 * @param config The artifact server configuration. 68 * @param config The artifact server configuration.
65 public Object createArtifactContext(Document config) { 71 public Object createArtifactContext(Document config) {
66 FLYSContext context = new FLYSContext(config); 72 FLYSContext context = new FLYSContext(config);
67 73
68 configureTransitions(config, context); 74 configureTransitions(config, context);
69 configureStates(config, context); 75 configureStates(config, context);
76 configureOutGenerators(config, context);
70 77
71 return context; 78 return context;
72 } 79 }
73 80
74 81
184 engine.addStates(artName, states); 191 engine.addStates(artName, states);
185 } 192 }
186 193
187 context.put(FLYSContext.STATE_ENGINE_KEY, engine); 194 context.put(FLYSContext.STATE_ENGINE_KEY, engine);
188 } 195 }
196
197
198 /**
199 * This method intializes the provided output generators.
200 *
201 * @param config the config document.
202 * @param context the FLYSContext.
203 */
204 protected void configureOutGenerators(Document config, FLYSContext context){
205 Map<String, Class> generators = new HashMap<String, Class>();
206
207 NodeList outGenerators = (NodeList) XMLUtils.xpath(
208 config,
209 XPATH_OUTPUT_GENERATORS,
210 XPathConstants.NODESET);
211
212 int num = outGenerators == null ? 0 : outGenerators.getLength();
213
214 if (num == 0) {
215 logger.warn("No output generators configured in this application.");
216 return;
217 }
218
219 logger.info("Found " + num + " configured output generators.");
220
221 int idx = 0;
222
223 for (int i = 0; i < num; i++) {
224 Node item = outGenerators.item(i);
225
226 String name = (String) XMLUtils.xpath(
227 item, "@name", XPathConstants.STRING);
228
229 String clazz = (String) XMLUtils.xpath(
230 item, "text()", XPathConstants.STRING);
231
232 if (name == null || clazz == null) {
233 continue;
234 }
235
236 try {
237 generators.put(name, Class.forName(clazz));
238
239 idx++;
240 }
241 catch (ClassNotFoundException cnfe) {
242 logger.warn(cnfe, cnfe);
243 }
244 }
245
246 logger.info("Successfully loaded " + idx + " output generators.");
247 context.put(FLYSContext.OUTGENERATORS_KEY, generators);
248 }
189 } 249 }
190 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 250 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org