Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java @ 8251:c7ca9c228314
Added context injectors for discharge curves.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 10 Sep 2014 10:01:11 +0200 |
parents | |
children | b5bef15c982e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java Wed Sep 10 10:01:11 2014 +0200 @@ -0,0 +1,40 @@ +package org.dive4elements.river.exports.injector; + +import org.apache.log4j.Logger; +import org.dive4elements.artifacts.Artifact; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.artifacts.ContextInjector; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.RangeAccess; +import org.dive4elements.river.model.Gauge; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; +import static org.dive4elements.river.exports.injector.InjectorConstants.GAUGE_EPSILON;; + + +public class DischargeInjector +implements ContextInjector +{ + + private static Logger log = Logger.getLogger(DischargeInjector.class); + + @Override + public void setup(Element cfg) { + } + + @Override + public void injectContext(CallContext ctx, Artifact artifact, Document doc) { + RangeAccess access = new RangeAccess((D4EArtifact)artifact); + double km = access.getFrom(); + Gauge gauge = access.getRiver().determineGaugeByStation( + km - GAUGE_EPSILON, km + GAUGE_EPSILON); + if (gauge == null) { + log.error("No Gauge could be found at station " + km + "!"); + return; + } + ctx.putContextValue(CURRENT_KM, km); + } + +}