Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DataFromArtifactXPathFunction.java @ 9499:853f2dafc16e
VegetationZones in CrossSectionsDiagram
author | gernotbelger |
---|---|
date | Thu, 27 Sep 2018 18:06:26 +0200 |
parents | e511eb935ccd |
children |
rev | line source |
---|---|
9299 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.datacage.templating; | |
11 | |
12 import java.util.List; | |
13 import java.util.UUID; | |
14 | |
15 import javax.xml.xpath.XPathFunction; | |
16 import javax.xml.xpath.XPathFunctionException; | |
17 | |
18 import org.dive4elements.artifactdatabase.data.StateData; | |
19 import org.dive4elements.artifacts.CallContext; | |
20 import org.dive4elements.river.artifacts.D4EArtifact; | |
21 import org.dive4elements.river.utils.RiverUtils; | |
22 | |
23 /** | |
9402
e511eb935ccd
Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names
mschaefer
parents:
9299
diff
changeset
|
24 * Very specialized function that gets state data from an artifact |
9299 | 25 * |
26 * @author Gernot Belger | |
27 */ | |
28 public class DataFromArtifactXPathFunction implements XPathFunction { | |
29 | |
30 public static final String ID = "data_from_artifact"; | |
31 | |
32 public static final int ARITY = 2; | |
33 | |
34 private final CallContext context; | |
35 | |
36 public DataFromArtifactXPathFunction(final CallContext context) { | |
37 this.context = context; | |
38 } | |
39 | |
40 @Override | |
41 public Object evaluate(final List args) throws XPathFunctionException { | |
42 | |
43 final UUID uuid = (UUID) args.get(0); | |
44 if (uuid == null) | |
45 return null; | |
46 | |
47 final D4EArtifact artifact = RiverUtils.getArtifact(uuid.toString(), this.context); | |
48 if (!(args.get(1) instanceof String)) | |
49 return null; | |
50 | |
51 final StateData data = artifact.getData(args.get(1).toString()); | |
9499 | 52 final Object value = data.getValue(); |
53 if (value == null) | |
54 return null; | |
9299 | 55 |
9499 | 56 return value; |
9299 | 57 } |
58 } |