comparison gwt-client/src/main/java/org/dive4elements/river/client/server/DataFactory.java @ 9074:766890addcb2

state To client communication;
author gernotbelger
date Fri, 18 May 2018 17:26:26 +0200
parents 5e38e2924c07
children
comparison
equal deleted inserted replaced
9073:cd650cacc926 9074:766890addcb2
12 import java.util.HashMap; 12 import java.util.HashMap;
13 import java.util.Map; 13 import java.util.Map;
14 14
15 import javax.xml.xpath.XPathConstants; 15 import javax.xml.xpath.XPathConstants;
16 16
17 import org.w3c.dom.Attr;
18 import org.w3c.dom.Element;
19 import org.w3c.dom.NamedNodeMap;
20 import org.w3c.dom.Node;
21 import org.w3c.dom.NodeList;
22 import org.apache.log4j.Logger; 17 import org.apache.log4j.Logger;
23 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; 18 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
24 import org.dive4elements.artifacts.common.utils.XMLUtils; 19 import org.dive4elements.artifacts.common.utils.XMLUtils;
25 import org.dive4elements.river.client.shared.model.Data; 20 import org.dive4elements.river.client.shared.model.Data;
26 import org.dive4elements.river.client.shared.model.DataItem; 21 import org.dive4elements.river.client.shared.model.DataItem;
27 import org.dive4elements.river.client.shared.model.DefaultData; 22 import org.dive4elements.river.client.shared.model.DefaultData;
28 import org.dive4elements.river.client.shared.model.DefaultDataItem; 23 import org.dive4elements.river.client.shared.model.DefaultDataItem;
29 import org.dive4elements.river.client.shared.model.DoubleArrayData; 24 import org.dive4elements.river.client.shared.model.DoubleArrayData;
25 import org.dive4elements.river.client.shared.model.IntDataItem;
30 import org.dive4elements.river.client.shared.model.IntegerArrayData; 26 import org.dive4elements.river.client.shared.model.IntegerArrayData;
31 import org.dive4elements.river.client.shared.model.IntegerData; 27 import org.dive4elements.river.client.shared.model.IntegerData;
32 import org.dive4elements.river.client.shared.model.IntegerOptionsData; 28 import org.dive4elements.river.client.shared.model.IntegerOptionsData;
33 import org.dive4elements.river.client.shared.model.IntegerRangeData; 29 import org.dive4elements.river.client.shared.model.IntegerRangeData;
30 import org.dive4elements.river.client.shared.model.LongRangeData;
34 import org.dive4elements.river.client.shared.model.MultiAttributeData; 31 import org.dive4elements.river.client.shared.model.MultiAttributeData;
35 import org.dive4elements.river.client.shared.model.MultiDataItem; 32 import org.dive4elements.river.client.shared.model.MultiDataItem;
36 import org.dive4elements.river.client.shared.model.StringData; 33 import org.dive4elements.river.client.shared.model.StringData;
37 import org.dive4elements.river.client.shared.model.StringOptionsData; 34 import org.dive4elements.river.client.shared.model.StringOptionsData;
38 import org.dive4elements.river.client.shared.model.LongRangeData; 35 import org.w3c.dom.Attr;
39 import org.dive4elements.river.client.shared.model.IntDataItem; 36 import org.w3c.dom.Element;
37 import org.w3c.dom.NamedNodeMap;
38 import org.w3c.dom.Node;
39 import org.w3c.dom.NodeList;
40 40
41 /** 41 /**
42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
43 */ 43 */
44 public class DataFactory { 44 public class DataFactory {
45 45
46 private static final Logger log = Logger.getLogger(DataFactory.class); 46 private static final Logger log = Logger.getLogger(DataFactory.class);
47 47
48 public static final String NS_URI = ArtifactNamespaceContext.NAMESPACE_URI; 48 public static final String NS_URI = ArtifactNamespaceContext.NAMESPACE_URI;
49 49
50
51 /** 50 /**
52 * Creates a new Data instance based on the <i>art:type</i> attribute of 51 * Creates a new Data instance based on the <i>art:type</i> attribute of
53 * <i>element</i>. 52 * <i>element</i>.
54 * 53 *
55 * @param element The Data element. 54 * @param element
55 * The Data element.
56 * 56 *
57 * @return a Data instance. 57 * @return a Data instance.
58 */ 58 */
59 public static Data createDataFromElement(Element element) { 59 public static Data createDataFromElement(final Element element) {
60 String name = element.getAttributeNS(NS_URI, "name"); 60 final String name = element.getAttributeNS(NS_URI, "name");
61 String type = element.getAttributeNS(NS_URI, "type"); 61 String type = element.getAttributeNS(NS_URI, "type");
62 String label = element.getAttributeNS(NS_URI, "label"); 62 String label = element.getAttributeNS(NS_URI, "label");
63 63
64 label = label != null && label.length() > 0 ? label : name; 64 label = label != null && label.length() > 0 ? label : name;
65 65
66 try { 66 try {
72 72
73 type = type.toLowerCase(); 73 type = type.toLowerCase();
74 74
75 if (type.equals(StringData.TYPE)) { 75 if (type.equals(StringData.TYPE)) {
76 return createStringData(element, name, label); 76 return createStringData(element, name, label);
77 } 77 } else if (type.equals(IntegerData.TYPE)) {
78 else if (type.equals(IntegerData.TYPE)) {
79 return createIntegerData(element, name, label); 78 return createIntegerData(element, name, label);
80 } 79 } else if (type.equals(StringOptionsData.TYPE)) {
81 else if (type.equals(StringOptionsData.TYPE)) {
82 return createStringOptionsData(element, name, label); 80 return createStringOptionsData(element, name, label);
83 } 81 } else if (type.equals(IntegerOptionsData.TYPE)) {
84 else if (type.equals(IntegerOptionsData.TYPE)) {
85 return createIntegerOptionsData(element, name, label); 82 return createIntegerOptionsData(element, name, label);
86 } 83 } else if (type.equals(IntegerRangeData.TYPE)) {
87 else if (type.equals(IntegerRangeData.TYPE)) {
88 return createIntegerRangeData(element, name, label); 84 return createIntegerRangeData(element, name, label);
89 } 85 } else if (type.equals(IntegerArrayData.TYPE)) {
90 else if (type.equals(IntegerArrayData.TYPE)) {
91 return createIntegerArrayData(element, name, label); 86 return createIntegerArrayData(element, name, label);
92 } 87 } else if (type.equals(DoubleArrayData.TYPE)) {
93 else if (type.equals(DoubleArrayData.TYPE)) {
94 return createDoubleArrayData(element, name, label); 88 return createDoubleArrayData(element, name, label);
95 } 89 } else if (type.equals(LongRangeData.TYPE)) {
96 else if (type.equals(LongRangeData.TYPE)) {
97 return createLongRangeData(element, name, label); 90 return createLongRangeData(element, name, label);
98 } 91 } else if (type.equals(MultiAttributeData.TYPE)) {
99 else if (type.equals(MultiAttributeData.TYPE)) {
100 return createMultiAttributeData(element, name, label); 92 return createMultiAttributeData(element, name, label);
101 } 93 } else {
102 else {
103 return createDefaultData(element, name, label); 94 return createDefaultData(element, name, label);
104 } 95 }
105 } 96 }
106 catch (Exception e) { 97 catch (final Exception e) {
107 log.error("Error while data creation for: " + name); 98 log.error("Error while data creation for: " + name);
108 } 99 }
109 100
110 return null; 101 return null;
111 } 102 }
112 103
113 104 public static Data createMultiAttributeData(final Element element, final String name, final String label) {
114 public static Data createMultiAttributeData( 105 return new MultiAttributeData(name, label, extractMultiDataItems(element), extractMeta(element));
115 Element element, 106 }
116 String name, 107
117 String label) { 108 private static Map<String, Map<String, String>> extractMeta(final Element element) {
118 return new MultiAttributeData( 109 final NodeList nl = element.getElementsByTagName("art:meta");
119 name, 110 final int N = nl.getLength();
120 label, 111 if (N != 1) {
121 extractMultiDataItems(element), 112 log.debug("No or too much meta data found for multi attribute data");
122 extractMeta(element));
123 }
124
125
126 private static Map<String, Map<String, String>> extractMeta(
127 Element element
128 ) {
129 NodeList nl = element.getElementsByTagName("meta");
130 int N = nl.getLength();
131 if (N < 1) {
132 log.debug("No meta data found for multi attribute data");
133 return Collections.<String, Map<String, String>>emptyMap(); 113 return Collections.<String, Map<String, String>>emptyMap();
134 } 114 }
135 Map<String, Map<String, String>> map = 115 final Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
136 new HashMap<String, Map<String, String>>(); 116
137 117 final Element metaElement = (Element) nl.item(0);
138 for (int i = 0; i < N; ++i) { 118 final NodeList metaChildren = metaElement.getChildNodes();
139 Element e = (Element)nl.item(i); 119
140 NamedNodeMap attrs = e.getAttributes(); 120 for (int i = 0; i < metaChildren.getLength(); ++i) {
141 Map<String, String> kvs = new HashMap<String, String>(); 121
142 for (int j = 0, A = attrs.getLength(); j < A; ++j) { 122 final Node childNode = metaChildren.item(i);
143 Attr attr = (Attr)attrs.item(j); 123 if (childNode instanceof Element) {
144 kvs.put(attr.getName(), attr.getValue()); 124
145 } 125 final Element e = (Element) childNode;
146 map.put(e.getTagName(), kvs); 126 final NamedNodeMap attrs = e.getAttributes();
127 final Map<String, String> kvs = new HashMap<String, String>();
128 for (int j = 0, A = attrs.getLength(); j < A; ++j) {
129 final Attr attr = (Attr) attrs.item(j);
130 kvs.put(attr.getName(), attr.getValue());
131 }
132 map.put(e.getLocalName(), kvs);
133 }
147 } 134 }
148 135
149 return map; 136 return map;
150 } 137 }
151 138
152 139 protected static DataItem[] extractMultiDataItems(final Element element) {
153 protected static DataItem[] extractMultiDataItems(Element element) { 140 final NodeList itemList = (NodeList) XMLUtils.xpath(element, "art:item", XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
154 NodeList itemList = (NodeList) XMLUtils.xpath(
155 element,
156 "art:item",
157 XPathConstants.NODESET,
158 ArtifactNamespaceContext.INSTANCE);
159 141
160 if (itemList == null || itemList.getLength() == 0) { 142 if (itemList == null || itemList.getLength() == 0) {
161 log.debug("No old data items found."); 143 log.debug("No old data items found.");
162 return null; 144 return null;
163 } 145 }
164 146
165 int count = itemList.getLength(); 147 final int count = itemList.getLength();
166 148
167 MultiDataItem[] items = new MultiDataItem[count]; 149 final MultiDataItem[] items = new MultiDataItem[count];
168 150
169 for (int i = 0; i < count; i++) { 151 for (int i = 0; i < count; i++) {
170 Element tmp = (Element) itemList.item(i); 152 final Element tmp = (Element) itemList.item(i);
171 153
172 HashMap<String, String> data = new HashMap<String, String>(); 154 final HashMap<String, String> data = new HashMap<String, String>();
173 String label = tmp.getAttributeNS(NS_URI, "label"); 155 final String label = tmp.getAttributeNS(NS_URI, "label");
174 NamedNodeMap attributes = tmp.getAttributes(); 156 final NamedNodeMap attributes = tmp.getAttributes();
175 for (int j = 0, L = attributes.getLength(); j < L; j++) { 157 for (int j = 0, L = attributes.getLength(); j < L; j++) {
176 Node n = attributes.item(j); 158 final Node n = attributes.item(j);
177 if (n.getNodeName().equals("label")) { 159 if (n.getNodeName().equals("label")) {
178 continue; 160 continue;
179 } 161 }
180 data.put(n.getNodeName(), n.getNodeValue()); 162 data.put(n.getNodeName(), n.getNodeValue());
181 } 163 }
182 items[i] = new MultiDataItem(label, label, data); 164 items[i] = new MultiDataItem(label, label, data);
183 } 165 }
184 return items; 166 return items;
185 } 167 }
186
187 168
188 /** 169 /**
189 * This method creates a new instance of DefaultData which has no real type 170 * This method creates a new instance of DefaultData which has no real type
190 * set. 171 * set.
191 * 172 *
192 * @param ele The Data element. 173 * @param ele
193 * @param name The name of the Data instance. 174 * The Data element.
175 * @param name
176 * The name of the Data instance.
194 * 177 *
195 * @return an instance of DefaultData. 178 * @return an instance of DefaultData.
196 */ 179 */
197 protected static Data createDefaultData( 180 protected static Data createDefaultData(final Element ele, final String name, final String label) {
198 Element ele,
199 String name,
200 String label
201 ) {
202 log.debug("Create new DefaultData"); 181 log.debug("Create new DefaultData");
203 return new DefaultData(name, label, "default", extractDataItems(ele)); 182 return new DefaultData(name, label, "default", extractDataItems(ele));
204 } 183 }
205 184
206
207 /** 185 /**
208 * This method creates a new instance of StringData which has a type 186 * This method creates a new instance of StringData which has a type
209 * "string" set. 187 * "string" set.
210 * 188 *
211 * @param ele The Data element. 189 * @param ele
212 * @param name The name of the Data instance. 190 * The Data element.
191 * @param name
192 * The name of the Data instance.
213 * 193 *
214 * @return an instance of StringData. 194 * @return an instance of StringData.
215 */ 195 */
216 protected static Data createStringData( 196 protected static Data createStringData(final Element ele, final String name, final String label) {
217 Element ele,
218 String name,
219 String label
220 ) {
221 return new StringData(name, label, extractDataItems(ele)); 197 return new StringData(name, label, extractDataItems(ele));
222 } 198 }
223
224 199
225 /** 200 /**
226 * This method creates a new instance of DefaultData which has a type 201 * This method creates a new instance of DefaultData which has a type
227 * "integer" set. 202 * "integer" set.
228 * 203 *
229 * @param ele The Data element. 204 * @param ele
230 * @param name The name of the Data instance. 205 * The Data element.
206 * @param name
207 * The name of the Data instance.
231 * 208 *
232 * @return an instance of IntegerData. 209 * @return an instance of IntegerData.
233 */ 210 */
234 protected static Data createIntegerData( 211 protected static Data createIntegerData(final Element ele, final String name, final String label) {
235 Element ele,
236 String name,
237 String label
238 ) {
239 return new IntegerData(name, label, extractDataItems(ele)); 212 return new IntegerData(name, label, extractDataItems(ele));
240 } 213 }
241
242 214
243 /** 215 /**
244 * This method creates a new instance of StringOptionsData which has a type 216 * This method creates a new instance of StringOptionsData which has a type
245 * "options" set. 217 * "options" set.
246 * 218 *
247 * @param ele The Data element. 219 * @param ele
248 * @param name The name of the Data instance. 220 * The Data element.
221 * @param name
222 * The name of the Data instance.
249 * 223 *
250 * @return an instance of StringOptionsData. 224 * @return an instance of StringOptionsData.
251 */ 225 */
252 protected static Data createStringOptionsData( 226 protected static Data createStringOptionsData(final Element ele, final String name, final String label) {
253 Element ele,
254 String name,
255 String label
256 ) {
257 return new StringOptionsData(name, label, extractDataItems(ele)); 227 return new StringOptionsData(name, label, extractDataItems(ele));
258 } 228 }
259
260 229
261 /** 230 /**
262 * This method creates a new instance of DefaultData which has a type 231 * This method creates a new instance of DefaultData which has a type
263 * "intoptions" set. 232 * "intoptions" set.
264 * 233 *
265 * @param ele The Data element. 234 * @param ele
266 * @param name The name of the Data instance. 235 * The Data element.
236 * @param name
237 * The name of the Data instance.
267 * 238 *
268 * @return an instance of IntegerOptionsData. 239 * @return an instance of IntegerOptionsData.
269 */ 240 */
270 protected static Data createIntegerOptionsData( 241 protected static Data createIntegerOptionsData(final Element ele, final String name, final String label) {
271 Element ele,
272 String name,
273 String label
274 ) {
275 return new IntegerOptionsData(name, label, extractDataItems(ele)); 242 return new IntegerOptionsData(name, label, extractDataItems(ele));
276 } 243 }
277
278 244
279 /** 245 /**
280 * This method creates a new instance of DefaultData which has a type 246 * This method creates a new instance of DefaultData which has a type
281 * "intrange" set. 247 * "intrange" set.
282 * 248 *
283 * @param ele The Data element. 249 * @param ele
284 * @param name The name of the Data instance. 250 * The Data element.
251 * @param name
252 * The name of the Data instance.
285 * 253 *
286 * @return an instance of IntegerRangeData. 254 * @return an instance of IntegerRangeData.
287 */ 255 */
288 protected static Data createIntegerRangeData( 256 protected static Data createIntegerRangeData(final Element ele, final String name, final String label) {
289 Element ele, 257 final DataItem[] items = extractDataItems(ele);
290 String name, 258 final String rawValue = items[0].getStringValue();
291 String label 259
292 ) { 260 final String[] minmax = rawValue.split(";");
293 DataItem[] items = extractDataItems(ele); 261
294 String rawValue = items[0].getStringValue(); 262 return new IntegerRangeData(name, label, Integer.valueOf(minmax[0]), Integer.valueOf(minmax[1]));
295 263 }
296 String[] minmax = rawValue.split(";");
297
298 return new IntegerRangeData(
299 name,
300 label,
301 Integer.valueOf(minmax[0]),
302 Integer.valueOf(minmax[1]));
303 }
304
305 264
306 /** 265 /**
307 * This method creates a new instance of DefaultData which has a type 266 * This method creates a new instance of DefaultData which has a type
308 * "integerarray" set. 267 * "integerarray" set.
309 * 268 *
310 * @param ele The Data element. 269 * @param ele
311 * @param name The name of the Data instance. 270 * The Data element.
271 * @param name
272 * The name of the Data instance.
312 * 273 *
313 * @return an instance of IntegerArrayData. 274 * @return an instance of IntegerArrayData.
314 */ 275 */
315 protected static Data createIntegerArrayData( 276 protected static Data createIntegerArrayData(final Element ele, final String name, final String label) {
316 Element ele, 277 final IntDataItem[] items = extractIntDataItems(ele);
317 String name,
318 String label
319 ) {
320 IntDataItem[] items = extractIntDataItems(ele);
321 return new IntegerArrayData(name, label, items); 278 return new IntegerArrayData(name, label, items);
322 } 279 }
323
324 280
325 /** 281 /**
326 * This method creates a new instance of DefaultData which has a type 282 * This method creates a new instance of DefaultData which has a type
327 * "doublearray" set. 283 * "doublearray" set.
328 * 284 *
329 * @param ele The Data element. 285 * @param ele
330 * @param name The name of the Data instance. 286 * The Data element.
287 * @param name
288 * The name of the Data instance.
331 * 289 *
332 * @return an instance of DoubleArrayData. 290 * @return an instance of DoubleArrayData.
333 */ 291 */
334 protected static Data createDoubleArrayData( 292 protected static Data createDoubleArrayData(final Element ele, final String name, final String label) {
335 Element ele, 293 final DataItem[] items = extractDataItems(ele);
336 String name, 294 final String rawValue = items[0].getStringValue();
337 String label 295
338 ) { 296 final String[] values = rawValue.split(";");
339 DataItem[] items = extractDataItems(ele); 297 final double[] doubles = new double[values.length];
340 String rawValue = items[0].getStringValue();
341
342 String[] values = rawValue.split(";");
343 double[] doubles = new double[values.length];
344 298
345 for (int i = 0; i < values.length; i++) { 299 for (int i = 0; i < values.length; i++) {
346 try { 300 try {
347 doubles[i] = Double.valueOf(values[i]); 301 doubles[i] = Double.valueOf(values[i]);
348 } 302 }
349 catch (NumberFormatException nfe) { 303 catch (final NumberFormatException nfe) {
350 log.warn("Error while parsing DoubleArrayData: " + nfe); 304 log.warn("Error while parsing DoubleArrayData: " + nfe);
351 } 305 }
352 } 306 }
353 307
354 return new DoubleArrayData(name, label, doubles); 308 return new DoubleArrayData(name, label, doubles);
355 } 309 }
356 310
357
358 /** 311 /**
359 * This method extracts the art:item elements placed under <i>elements</i>. 312 * This method extracts the art:item elements placed under <i>elements</i>.
360 * 313 *
361 * @param element A data node that contains items. 314 * @param element
315 * A data node that contains items.
362 * 316 *
363 * @return a list of DataItems. 317 * @return a list of DataItems.
364 */ 318 */
365 protected static DataItem[] extractDataItems(Element element) { 319 protected static DataItem[] extractDataItems(final Element element) {
366 NodeList itemList = (NodeList) XMLUtils.xpath( 320 final NodeList itemList = (NodeList) XMLUtils.xpath(element, "art:item", XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
367 element,
368 "art:item",
369 XPathConstants.NODESET,
370 ArtifactNamespaceContext.INSTANCE);
371 321
372 if (itemList == null || itemList.getLength() == 0) { 322 if (itemList == null || itemList.getLength() == 0) {
373 log.debug("No data items found."); 323 log.debug("No data items found.");
374 return null; 324 return null;
375 } 325 }
376 326
377 int count = itemList.getLength(); 327 final int count = itemList.getLength();
378 328
379 DataItem[] items = new DataItem[count]; 329 final DataItem[] items = new DataItem[count];
380 330
381 log.debug("There are " + count + " data items in element."); 331 log.debug("There are " + count + " data items in element.");
382 332
383 for (int i = 0; i < count; i++) { 333 for (int i = 0; i < count; i++) {
384 Element tmp = (Element) itemList.item(i); 334 final Element tmp = (Element) itemList.item(i);
385 335
386 String value = tmp.getAttributeNS(NS_URI, "value"); 336 final String value = tmp.getAttributeNS(NS_URI, "value");
387 String label = tmp.getAttributeNS(NS_URI, "label"); 337 final String label = tmp.getAttributeNS(NS_URI, "label");
388 338
389 log.debug("Found data item:"); 339 log.debug("Found data item:");
390 log.debug(" label: " + label); 340 log.debug(" label: " + label);
391 log.debug(" value: " + value); 341 log.debug(" value: " + value);
392 342
394 } 344 }
395 345
396 return items; 346 return items;
397 } 347 }
398 348
399
400 /** 349 /**
401 * This method extracts the art:item elements placed under <i>elements</i>. 350 * This method extracts the art:item elements placed under <i>elements</i>.
402 * 351 *
403 * @param element A data node that contains items. 352 * @param element
353 * A data node that contains items.
404 * 354 *
405 * @return a list of DataItems. 355 * @return a list of DataItems.
406 */ 356 */
407 protected static IntDataItem[] extractIntDataItems(Element element) { 357 protected static IntDataItem[] extractIntDataItems(final Element element) {
408 NodeList itemList = (NodeList) XMLUtils.xpath( 358 final NodeList itemList = (NodeList) XMLUtils.xpath(element, "art:item", XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
409 element,
410 "art:item",
411 XPathConstants.NODESET,
412 ArtifactNamespaceContext.INSTANCE);
413 359
414 if (itemList == null || itemList.getLength() == 0) { 360 if (itemList == null || itemList.getLength() == 0) {
415 log.debug("No old data items found."); 361 log.debug("No old data items found.");
416 return null; 362 return null;
417 } 363 }
418 364
419 int count = itemList.getLength(); 365 final int count = itemList.getLength();
420 366
421 IntDataItem[] items = new IntDataItem[count]; 367 final IntDataItem[] items = new IntDataItem[count];
422 368
423 for (int i = 0; i < count; i++) { 369 for (int i = 0; i < count; i++) {
424 Element tmp = (Element) itemList.item(i); 370 final Element tmp = (Element) itemList.item(i);
425 371
426 String value = tmp.getAttributeNS(NS_URI, "value"); 372 final String value = tmp.getAttributeNS(NS_URI, "value");
427 String label = tmp.getAttributeNS(NS_URI, "label"); 373 final String label = tmp.getAttributeNS(NS_URI, "label");
428 374
429 try { 375 try {
430 int data = Integer.parseInt(value); 376 final int data = Integer.parseInt(value);
431 items[i] = new IntDataItem(label, label, data); 377 items[i] = new IntDataItem(label, label, data);
432 } 378 }
433 catch(NumberFormatException nfe) { 379 catch (final NumberFormatException nfe) {
434 log.debug(nfe, nfe); 380 log.debug(nfe, nfe);
435 } 381 }
436 } 382 }
437 return items; 383 return items;
438 } 384 }
439 385
440 /** 386 /**
441 * This method creates a new instance of LongRangeData which has a type 387 * This method creates a new instance of LongRangeData which has a type
442 * "longrange" set. 388 * "longrange" set.
443 * 389 *
444 * @param ele The Data element. 390 * @param ele
445 * @param name The name of the Data instance. 391 * The Data element.
392 * @param name
393 * The name of the Data instance.
446 * 394 *
447 * @return an instance of IntegerRangeData. 395 * @return an instance of IntegerRangeData.
448 */ 396 */
449 protected static Data createLongRangeData( 397 protected static Data createLongRangeData(final Element ele, final String name, final String label) {
450 Element ele, 398 final DataItem[] items = extractDataItems(ele);
451 String name, 399 final String rawValue = items[0].getStringValue();
452 String label 400
453 ) { 401 final String[] minmax = rawValue.split(";");
454 DataItem[] items = extractDataItems(ele); 402
455 String rawValue = items[0].getStringValue(); 403 return new LongRangeData(name, label, Long.valueOf(minmax[0]), Long.valueOf(minmax[1]));
456
457 String[] minmax = rawValue.split(";");
458
459 return new LongRangeData(
460 name,
461 label,
462 Long.valueOf(minmax[0]),
463 Long.valueOf(minmax[1]));
464 } 404 }
465 405
466 } 406 }
467 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 407 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org