Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/injector/KmFromGaugeNameInjector.java @ 8349:7341bebc79d0
Let injectors be strictly distinct from each other and give more meaningful names (they know what they do, not where they will be used. The latter is configuration).
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 01 Oct 2014 12:23:39 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/exports/injector/DischargeInjector.java@31272d799dad |
children | 16dc2da05aef |
comparison
equal
deleted
inserted
replaced
8348:dc3f55141299 | 8349:7341bebc79d0 |
---|---|
1 package org.dive4elements.river.exports.injector; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 import org.dive4elements.artifacts.Artifact; | |
5 import org.dive4elements.artifacts.CallContext; | |
6 import org.dive4elements.artifacts.ContextInjector; | |
7 import org.dive4elements.river.artifacts.D4EArtifact; | |
8 import org.dive4elements.river.artifacts.access.RangeAccess; | |
9 import org.dive4elements.river.model.Gauge; | |
10 import org.w3c.dom.Document; | |
11 import org.w3c.dom.Element; | |
12 | |
13 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; | |
14 | |
15 | |
16 public class KmFromGaugeNameInjector | |
17 implements ContextInjector | |
18 { | |
19 | |
20 private static Logger log = Logger.getLogger(KmFromGaugeNameInjector.class); | |
21 | |
22 @Override | |
23 public void setup(Element cfg) { | |
24 } | |
25 | |
26 @Override | |
27 public void injectContext(CallContext ctx, Artifact artifact, Document doc) { | |
28 D4EArtifact d4e = (D4EArtifact)artifact; | |
29 RangeAccess access = new RangeAccess(d4e); | |
30 String name = d4e.getDataAsString("gauge_name"); | |
31 if (name == null || name.equals("")) { | |
32 return; | |
33 } | |
34 Gauge gauge = access.getRiver().determineGaugeByName(name); | |
35 if (gauge == null) { | |
36 log.error("No Gauge could be found for name " + name + "!"); | |
37 return; | |
38 } | |
39 ctx.putContextValue(CURRENT_KM, gauge.getStation()); | |
40 return; | |
41 } | |
42 | |
43 } |