comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java @ 3295:4fc442f1b4f6

Refactored FLYSArtifactCollection. flys-artifacts/trunk@4976 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 13 Jul 2012 09:33:16 +0000
parents 368040e5c400
children 28be160b5870
comparison
equal deleted inserted replaced
3294:5e52202302e5 3295:4fc442f1b4f6
1 package de.intevation.flys.artifacts.context; 1 package de.intevation.flys.artifacts.context;
2
3 import java.util.Map;
2 4
3 import org.apache.log4j.Logger; 5 import org.apache.log4j.Logger;
4 6
5 import org.w3c.dom.Document; 7 import org.w3c.dom.Document;
6 8
7 import de.intevation.artifactdatabase.DefaultArtifactContext; 9 import de.intevation.artifactdatabase.DefaultArtifactContext;
10 import de.intevation.artifacts.CallContext;
11 import de.intevation.flys.exports.OutGenerator;
8 12
9 13
10 /** 14 /**
11 * This class is used to store application wide information in a global context. 15 * This class is used to store application wide information in a global context.
12 * 16 *
63 * A constructor with a config document. 67 * A constructor with a config document.
64 */ 68 */
65 public FLYSContext(Document config) { 69 public FLYSContext(Document config) {
66 super(config); 70 super(config);
67 } 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 }
68 } 112 }
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org