Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Fri Jul 13 08:25:13 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Fri Jul 13 09:33:16 2012 +0000 @@ -1,10 +1,14 @@ package de.intevation.flys.artifacts.context; +import java.util.Map; + import org.apache.log4j.Logger; import org.w3c.dom.Document; import de.intevation.artifactdatabase.DefaultArtifactContext; +import de.intevation.artifacts.CallContext; +import de.intevation.flys.exports.OutGenerator; /** @@ -65,5 +69,45 @@ public FLYSContext(Document config) { super(config); } + + /** + * Returns the OutGenerator for a specified <i>type</i>. + * + * @param name The name of the output type. + * @param type Defines the type of the desired OutGenerator. + * + * @return Instance of an OutGenerator for specified <i>type</i>. + */ + public static OutGenerator getOutGenerator( + CallContext context, + String name, + String type) + { + + FLYSContext flysContext = context instanceof FLYSContext + ? (FLYSContext) context + : (FLYSContext) context.globalContext(); + + Map<String, Class> generators = (Map<String, Class>) + flysContext.get(FLYSContext.OUTGENERATORS_KEY); + + if (generators == null) { + return null; + } + + Class clazz = generators.get(name); + + try { + return clazz != null ? (OutGenerator) clazz.newInstance() : null; + } + catch (InstantiationException ie) { + logger.error(ie, ie); + } + catch (IllegalAccessException iae) { + logger.error(iae, iae); + } + + return null; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :