teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.artifacts.context;
ingo@106:
tom@9726: import org.apache.logging.log4j.Logger;
tom@9726: import org.apache.logging.log4j.LogManager;
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@7226: import org.dive4elements.river.exports.GeneratorLookup;
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:
teichmann@8202: /** The log used in this class. */
tom@9726: private static Logger log = LogManager.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:
teichmann@7227: public static final String FACETFILTER_KEY =
teichmann@7227: "flys.export.facetfilter";
teichmann@7227:
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,
teichmann@8220: String name
teichmann@8220: ) {
teichmann@5866: RiverContext flysContext = context instanceof RiverContext
teichmann@5866: ? (RiverContext) context
teichmann@5866: : (RiverContext) context.globalContext();
raimund@3295:
teichmann@7226: GeneratorLookup generators =
teichmann@7226: (GeneratorLookup)flysContext.get(RiverContext.OUTGENERATORS_KEY);
raimund@3295:
raimund@3295: if (generators == null) {
raimund@3295: return null;
raimund@3295: }
raimund@3295:
teichmann@8219: GeneratorLookup.Item item = generators.getGenerator(name);
teichmann@7037:
teichmann@8219: if (item == null) {
tom@8271: log.error("No generator class found for " + name);
teichmann@7037: return null;
teichmann@7037: }
raimund@3295:
raimund@3295: try {
teichmann@8219: Class clazz = item.getGenerator();
teichmann@7037: OutGenerator generator = clazz.newInstance();
teichmann@8219: generator.setup(item.getContext());
teichmann@7037: return generator;
raimund@3295: }
raimund@3295: catch (InstantiationException ie) {
teichmann@8202: log.error(ie, ie);
raimund@3295: }
raimund@3295: catch (IllegalAccessException iae) {
teichmann@8202: log.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 :