ingo@106: package de.intevation.flys.artifacts.context; ingo@106: raimund@3295: import java.util.Map; raimund@3295: ingo@106: import org.apache.log4j.Logger; ingo@106: ingo@106: import org.w3c.dom.Document; ingo@106: ingo@106: import de.intevation.artifactdatabase.DefaultArtifactContext; raimund@3295: import de.intevation.artifacts.CallContext; raimund@3295: import de.intevation.flys.exports.OutGenerator; ingo@106: ingo@106: ingo@106: /** ingo@106: * This class is used to store application wide information in a global context. ingo@106: * ingo@106: * @author Ingo Weinzierl ingo@106: */ ingo@106: public class FLYSContext extends DefaultArtifactContext { ingo@106: felix@1821: /** The logger used in this class. */ ingo@106: private static Logger logger = Logger.getLogger(FLYSContext.class); ingo@106: felix@1821: /** The key that is used to store the StateEngine in the context. */ felix@1821: public static final String ARTIFACT_KEY = felix@1821: "artifact"; felix@1821: felix@1821: /** The key that is used to store the TransitionEngine in the context. */ ingo@106: public static final String TRANSITION_ENGINE_KEY = ingo@106: "artifact.transition.engine"; ingo@106: felix@1821: /** The key that is used to store the StateEngine in the context. */ ingo@107: public static final String STATE_ENGINE_KEY = ingo@107: "artifact.state.engine"; ingo@107: ingo@295: /** The key that is used to store the Map of OutGenerator classes in the felix@1821: * context. */ ingo@295: public static final String OUTGENERATORS_KEY = ingo@295: "flys.export.outgenerators"; ingo@295: felix@1821: /** The key that is used to store the map of themes in the context. */ ingo@341: public static final String THEMES = ingo@341: "flys.themes.map"; ingo@341: felix@1821: /** The key that is used to store a map of theme mappings in the context. */ ingo@345: public static final String THEME_MAPPING = ingo@345: "flys.themes.mapping.map"; ingo@345: felix@1821: /** The key that is used to store a map of WMS urls for each river. */ ingo@958: public static final String RIVER_WMS = ingo@958: "flys.floodmap.river.wms"; ingo@958: ingo@1970: /** The key that is used to store an instance of Scheduler in the context.*/ ingo@1970: public static final String SCHEDULER = ingo@1970: "flys.wsplgen.scheduler"; ingo@1970: bjoern@3630: /** Key to store the configured modules in the context. */ bjoern@3630: public static final String MODULES = "flys.modules"; bjoern@3630: ingo@106: ingo@106: /** ingo@106: * The default constructor. ingo@106: */ ingo@106: public FLYSContext() { ingo@106: super(); ingo@106: } ingo@106: ingo@106: ingo@106: /** ingo@106: * A constructor with a config document. ingo@106: */ ingo@106: public FLYSContext(Document config) { ingo@106: super(config); ingo@106: } raimund@3295: raimund@3295: /** raimund@3295: * Returns the OutGenerator for a specified type. raimund@3295: * raimund@3295: * @param name The name of the output type. raimund@3295: * @param type Defines the type of the desired OutGenerator. raimund@3295: * raimund@3295: * @return Instance of an OutGenerator for specified type. raimund@3295: */ raimund@3295: public static OutGenerator getOutGenerator( raimund@3295: CallContext context, raimund@3295: String name, raimund@3295: String type) raimund@3295: { raimund@3295: raimund@3295: FLYSContext flysContext = context instanceof FLYSContext raimund@3295: ? (FLYSContext) context raimund@3295: : (FLYSContext) context.globalContext(); raimund@3295: raimund@3295: Map generators = (Map) raimund@3295: flysContext.get(FLYSContext.OUTGENERATORS_KEY); raimund@3295: raimund@3295: if (generators == null) { raimund@3295: return null; raimund@3295: } raimund@3295: raimund@3295: Class clazz = generators.get(name); raimund@3295: raimund@3295: try { raimund@3295: return clazz != null ? (OutGenerator) clazz.newInstance() : null; raimund@3295: } raimund@3295: catch (InstantiationException ie) { raimund@3295: logger.error(ie, ie); raimund@3295: } raimund@3295: catch (IllegalAccessException iae) { raimund@3295: logger.error(iae, iae); raimund@3295: } raimund@3295: raimund@3295: return null; raimund@3295: } ingo@106: } ingo@106: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :