teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5863: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5863: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.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: teichmann@5831: import org.dive4elements.artifactdatabase.DefaultArtifactContext; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.river.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: */ teichmann@5866: public class RiverContext extends DefaultArtifactContext { ingo@106: felix@1821: /** The logger used in this class. */ teichmann@5866: private static Logger logger = Logger.getLogger(RiverContext.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: */ teichmann@5866: public RiverContext() { ingo@106: super(); ingo@106: } ingo@106: ingo@106: ingo@106: /** ingo@106: * A constructor with a config document. ingo@106: */ teichmann@5866: public RiverContext(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: teichmann@5866: RiverContext flysContext = context instanceof RiverContext teichmann@5866: ? (RiverContext) context teichmann@5866: : (RiverContext) context.globalContext(); raimund@3295: raimund@3295: Map generators = (Map) teichmann@5866: flysContext.get(RiverContext.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 :