annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeInfoService.java @ 3592:da60327f6d7c

Do not hard-recommend gauge-discharges for fix wq. flys-artifacts/trunk@5213 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 15 Aug 2012 14:45:55 +0000
parents f1f798b5f14a
children 5e7da178daa6
rev   line source
2599
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.util.List;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import org.w3c.dom.Document;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import org.w3c.dom.Element;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import org.apache.log4j.Logger;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.common.ArtifactNamespaceContext;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.common.utils.XMLUtils;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import de.intevation.artifacts.CallMeta;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import de.intevation.artifacts.GlobalContext;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.model.Gauge;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import de.intevation.flys.model.Range;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import de.intevation.flys.model.River;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import de.intevation.flys.artifacts.model.RiverFactory;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 /**
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 */
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 public class GaugeInfoService extends FLYSService {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 interface Filter {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 boolean apply(Gauge gauge);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 protected class ReferenceNumberFilter implements Filter {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 private long refNr;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 public ReferenceNumberFilter(long refNr) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 this.refNr = refNr;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 @Override
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 public boolean apply(Gauge gauge) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 logger.debug("Test gauge '" + gauge.getName() + "'");
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 if (gauge != null && gauge.getOfficialNumber() == refNr) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 return true;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 else {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 return false;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 } // end of ReferenceNumberFilter class
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 /** The logger that is used by this service.*/
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 private static Logger logger = Logger.getLogger(GaugeInfoService.class);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 public static final String XPATH_RIVERNAME = "/art:river/@name";
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 public static final String XPATH_REFERENCE_NR
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 = "/art:river/art:filter/art:gauge/text()";
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 public GaugeInfoService() {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 @Override
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 public Document doProcess(
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 Document data,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 GlobalContext context,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 CallMeta callMeta
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 ) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 logger.debug("GaugeInfoService.process");
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
3557
f1f798b5f14a Made expensive XMLUtils.toString() debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2599
diff changeset
78 if (logger.isDebugEnabled()) {
f1f798b5f14a Made expensive XMLUtils.toString() debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2599
diff changeset
79 logger.debug(XMLUtils.toString(data));
f1f798b5f14a Made expensive XMLUtils.toString() debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2599
diff changeset
80 }
2599
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 River river = getRiverFromRequest(data);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 List<Filter> filters = getFilters(data);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 List<Gauge> allGauges = river.getGauges();
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 List<Gauge> filtered = new ArrayList<Gauge>();
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 for (Gauge g: allGauges) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 for (Filter f: filters) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 if (f.apply(g)) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 filtered.add(g);
3557
f1f798b5f14a Made expensive XMLUtils.toString() debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2599
diff changeset
92 break;
2599
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 return buildInfoDocument(filtered);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 protected River getRiverFromRequest(Document data) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 String rivername = XMLUtils.xpathString(
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 data,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 XPATH_RIVERNAME,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 ArtifactNamespaceContext.INSTANCE);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 logger.debug("Return Gauge info for River '" + rivername + "'");
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 return rivername != null ? RiverFactory.getRiver(rivername) : null;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 protected List<Filter> getFilters(Document data) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 List<Filter> filters = new ArrayList<Filter>();
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 String refNr = XMLUtils.xpathString(
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 data,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 XPATH_REFERENCE_NR,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 ArtifactNamespaceContext.INSTANCE);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 if (refNr != null && refNr.length() > 0) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 try {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 filters.add(new ReferenceNumberFilter(Long.valueOf(refNr)));
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 catch (NumberFormatException nfe) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 logger.warn(nfe, nfe);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 return filters;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 protected Document buildInfoDocument(List<Gauge> gauges) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 Document doc = XMLUtils.newDocument();
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 ElementCreator cr = new ElementCreator(
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 doc,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 ArtifactNamespaceContext.NAMESPACE_URI,
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 ArtifactNamespaceContext.NAMESPACE_PREFIX);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 Element service = cr.create("service");
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 logger.debug("Append " + gauges.size() + " gauges to info doc.");
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 for (Gauge g: gauges) {
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 Range r = g.getRange();
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 Element el = cr.create("gauge");
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 cr.addAttr(el, "name", g.getName());
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 cr.addAttr(el, "lower", String.valueOf(r.getA().doubleValue()));
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 cr.addAttr(el, "upper", String.valueOf(r.getB().doubleValue()));
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 service.appendChild(el);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 doc.appendChild(service);
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 return doc;
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 }
fb7975828ffa #544 Added a service that allows querying gauge information.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org