Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/injector/PNPInjector.java @ 8337:f5461750e5c7
Avoid NPE if river is not accessible.
author | "Tom Gottfried <tom@intevation.de>" |
---|---|
date | Fri, 26 Sep 2014 17:22:51 +0200 |
parents | 10917ec29625 |
children | 47199406994a |
comparison
equal
deleted
inserted
replaced
8336:b9fa8124583c | 8337:f5461750e5c7 |
---|---|
4 import org.dive4elements.artifacts.Artifact; | 4 import org.dive4elements.artifacts.Artifact; |
5 import org.dive4elements.artifacts.CallContext; | 5 import org.dive4elements.artifacts.CallContext; |
6 import org.dive4elements.artifacts.ContextInjector; | 6 import org.dive4elements.artifacts.ContextInjector; |
7 import org.dive4elements.river.artifacts.D4EArtifact; | 7 import org.dive4elements.river.artifacts.D4EArtifact; |
8 import org.dive4elements.river.artifacts.access.RiverAccess; | 8 import org.dive4elements.river.artifacts.access.RiverAccess; |
9 import org.dive4elements.river.model.River; | |
9 import org.dive4elements.river.model.Gauge; | 10 import org.dive4elements.river.model.Gauge; |
10 import org.w3c.dom.Document; | 11 import org.w3c.dom.Document; |
11 import org.w3c.dom.Element; | 12 import org.w3c.dom.Element; |
12 | 13 |
13 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; | 14 import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; |
35 if (currentKm == null) { | 36 if (currentKm == null) { |
36 log.debug("no current km. not injecting pnp"); | 37 log.debug("no current km. not injecting pnp"); |
37 return; | 38 return; |
38 } | 39 } |
39 | 40 |
40 RiverAccess access = new RiverAccess((D4EArtifact)artifact); | |
41 Double km = Double.valueOf(currentKm.toString()); | 41 Double km = Double.valueOf(currentKm.toString()); |
42 if (Double.isNaN(km) || Double.isInfinite(km)) { | 42 if (Double.isNaN(km) || Double.isInfinite(km)) { |
43 log.debug("current km is NAN or infinte. not injecting pnp."); | 43 log.debug("current km is NAN or infinte. not injecting pnp."); |
44 return; | 44 return; |
45 } | 45 } |
46 | |
47 River river = new RiverAccess((D4EArtifact)artifact).getRiver(); | |
48 if (river == null) { | |
49 log.error("River not accessible from artifact. Not injecting PNP"); | |
50 return; | |
51 } | |
52 | |
46 Gauge gauge = | 53 Gauge gauge = |
47 access.getRiver().determineGaugeByStation( | 54 river.determineGaugeByStation( |
48 km - GAUGE_EPSILON, | 55 km - GAUGE_EPSILON, |
49 km + GAUGE_EPSILON); | 56 km + GAUGE_EPSILON); |
50 | 57 |
51 if (gauge == null) { | 58 if (gauge == null) { |
52 log.debug("no gauge found at current km. not injecting pnp"); | 59 log.debug("no gauge found at current km. not injecting pnp"); |