2176
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 import java.util.HashMap; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 import net.sf.jasperreports.engine.JRDataSource; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 import net.sf.jasperreports.engine.JRException; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import net.sf.jasperreports.engine.JRField; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 /** |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 */ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 public class WKmsJRDataSource implements JRDataSource |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 /** The logger used in this exporter.*/ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 private static Logger logger = Logger.getLogger(WKmsJRDataSource.class); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 /** |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 * |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 */ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 private ArrayList<String[]> data; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 private HashMap<String, String> metaData; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 private int index = -1; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 /** |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 * |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 */ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 public WKmsJRDataSource() |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 data = new ArrayList<String[]>(); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 metaData = new HashMap<String, String>(); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 /** |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 * |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 */ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 public void addData(String[] data) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 this.data.add(data); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 /** |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 * |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 */ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 public void addMetaData(String key, String value) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 this.metaData.put(key, value); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 /** |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 * |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 */ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 public boolean next() throws JRException |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 index++; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 return (index < data.size()); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 /** |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 * |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 */ |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 public Object getFieldValue(JRField field) throws JRException |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 Object value = ""; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 String fieldName = field.getName(); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 if ("river".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 value = metaData.get("river"); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 if ("date".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 value = metaData.get("date"); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 if ("range".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 value = metaData.get("range"); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 if ("gauge".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 value = metaData.get("gauge"); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 if ("calculation".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 value = metaData.get("calculation"); |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 } |
2180
|
88 if ("differences".equals(fieldName)) { |
|
89 value = metaData.get("differences"); |
|
90 } |
2176
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 if ("km".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 value = data.get(index)[0]; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 if ("W".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 value = data.get(index)[1]; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 if ("Q".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 value = data.get(index)[2]; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 if ("description".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 value = data.get(index)[3]; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
102 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 if ("location".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 value = data.get(index)[4]; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 if ("gaugename".equals(fieldName)) { |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 value = data.get(index)[5]; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 } |
2178
|
109 if ("day".equals(fieldName)) { |
|
110 value = data.get(index)[6]; |
|
111 } |
2176
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 return value; |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 } |
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 } |