comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java @ 399:53cc794fee07

Improved the transition model and added states to enable the 'discharge longitudinal section' computation - NOTE: the work in this computation has not finished yet. flys-artifacts/trunk@1830 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 05 May 2011 06:12:44 +0000
parents
children 34de11dcf355
comparison
equal deleted inserted replaced
398:435058da0eae 399:53cc794fee07
1 package de.intevation.flys.artifacts.states;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import org.w3c.dom.Element;
8
9 import de.intevation.artifacts.Artifact;
10 import de.intevation.artifacts.CallContext;
11
12 import de.intevation.artifactdatabase.ProtocolUtils;
13
14 import de.intevation.artifacts.common.utils.XMLUtils;
15
16 import de.intevation.flys.model.Gauge;
17 import de.intevation.flys.model.Range;
18
19 import de.intevation.flys.artifacts.FLYSArtifact;
20
21
22 /**
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
24 */
25 public class WQAdapted extends DefaultState {
26
27 /** The logger used in this state.*/
28 private static Logger logger = Logger.getLogger(WQAdapted.class);
29
30
31 /**
32 * This method creates one element for each gauge of the selected river that
33 * is intersected by the given kilometer range. Each element is a tuple of
34 * (from;to) where <i>from</i> is the lower bounds of the gauge or the lower
35 * kilometer range. <i>to</i> is the upper bounds of the gauge or the upper
36 * kilometer range.
37 *
38 * @param cr The ElementCreator.
39 * @param artifact The FLYS artifact.
40 * @param name The name of the data item.
41 * @param context The CallContext.
42 *
43 * @return a list of elements that consist of tuples of the intersected
44 * gauges of the selected river.
45 */
46 protected Element[] createItems(
47 XMLUtils.ElementCreator cr,
48 Artifact artifact,
49 String name,
50 CallContext context)
51 {
52 logger.debug("WQAdapted.createItems");
53
54 FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
55
56 double[] dist = flysArtifact.getDistance();
57 List<Gauge> gauges = flysArtifact.getGauges();
58
59 int num = gauges != null ? gauges.size() : 0;
60
61 if (num == 0) {
62 logger.warn("Selected distance matches no gauges.");
63 return null;
64 }
65
66 Element[] elements = new Element[num];
67
68 int idx = 0;
69
70 for (Gauge gauge: gauges) {
71 Range range = gauge.getRange();
72 double lower = range.getA().doubleValue();
73 double upper = range.getB().doubleValue();
74
75 double from = dist[0] < lower ? lower : dist[0];
76 double to = dist[1] > upper ? upper : dist[1];
77
78 String key = Double.toString(from) + ";" + Double.toString(to);
79
80 elements[idx++] = createItem(cr, new String[] {key, ""});
81 }
82
83 return elements;
84 }
85
86
87 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) {
88 Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
89 Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
90 Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
91
92 String[] arr = (String[]) obj;
93
94 label.setTextContent(arr[0]);
95 value.setTextContent(arr[1]);
96
97 item.appendChild(label);
98 item.appendChild(value);
99
100 return item;
101 }
102
103
104 @Override
105 protected String getUIProvider() {
106 return "wq_panel_adapted";
107 }
108 }
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org