Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java @ 2535:d0a9acddbea2
Added an int data item used in int array data and added getter that returns
values as colon separated string to all data types.
flys-client/trunk@4445 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 21 May 2012 08:48:16 +0000 |
parents | 261347ea60b8 |
children |
comparison
equal
deleted
inserted
replaced
2534:05143379059e | 2535:d0a9acddbea2 |
---|---|
21 import de.intevation.flys.client.shared.model.IntegerRangeData; | 21 import de.intevation.flys.client.shared.model.IntegerRangeData; |
22 import de.intevation.flys.client.shared.model.StringData; | 22 import de.intevation.flys.client.shared.model.StringData; |
23 import de.intevation.flys.client.shared.model.StringOptionsData; | 23 import de.intevation.flys.client.shared.model.StringOptionsData; |
24 import de.intevation.flys.client.shared.model.LongRangeData; | 24 import de.intevation.flys.client.shared.model.LongRangeData; |
25 | 25 |
26 import de.intevation.flys.client.shared.model.IntDataItem; | |
26 | 27 |
27 /** | 28 /** |
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
29 */ | 30 */ |
30 public class DataFactory { | 31 public class DataFactory { |
196 * @param name The name of the Data instance. | 197 * @param name The name of the Data instance. |
197 * | 198 * |
198 * @return an instance of IntegerArrayData. | 199 * @return an instance of IntegerArrayData. |
199 */ | 200 */ |
200 protected static Data createIntegerArrayData(Element ele, String name, String label) { | 201 protected static Data createIntegerArrayData(Element ele, String name, String label) { |
201 DataItem[] items = extractDataItems(ele); | 202 IntDataItem[] items = extractIntDataItems(ele); |
202 String rawValue = items[0].getStringValue(); | 203 return new IntegerArrayData(name, label, items); |
203 | |
204 String[] values = rawValue.split(";"); | |
205 int[] integers = new int[values.length]; | |
206 | |
207 for (int i = 0; i < values.length; i++) { | |
208 try { | |
209 integers[i] = Integer.valueOf(values[i]); | |
210 } | |
211 catch (NumberFormatException nfe) { | |
212 logger.warn("Error while parsing IntegerArrayData: " + nfe); | |
213 } | |
214 } | |
215 | |
216 return new IntegerArrayData(name, label, integers); | |
217 } | 204 } |
218 | 205 |
219 | 206 |
220 /** | 207 /** |
221 * This method creates a new instance of DefaultData which has a type | 208 * This method creates a new instance of DefaultData which has a type |
287 return items; | 274 return items; |
288 } | 275 } |
289 | 276 |
290 | 277 |
291 /** | 278 /** |
279 * This method extracts the art:item elements placed under <i>elements</i>. | |
280 * | |
281 * @param element A data node that contains items. | |
282 * | |
283 * @return a list of DataItems. | |
284 */ | |
285 protected static IntDataItem[] extractIntDataItems(Element element) { | |
286 NodeList itemList = (NodeList) XMLUtils.xpath( | |
287 element, | |
288 "art:item", | |
289 XPathConstants.NODESET, | |
290 ArtifactNamespaceContext.INSTANCE); | |
291 | |
292 if (itemList == null || itemList.getLength() == 0) { | |
293 logger.debug("No old data items found."); | |
294 return null; | |
295 } | |
296 | |
297 int count = itemList.getLength(); | |
298 | |
299 IntDataItem[] items = new IntDataItem[count]; | |
300 | |
301 for (int i = 0; i < count; i++) { | |
302 Element tmp = (Element) itemList.item(i); | |
303 | |
304 String value = tmp.getAttributeNS(NS_URI, "value"); | |
305 String label = tmp.getAttributeNS(NS_URI, "label"); | |
306 | |
307 try { | |
308 int data = Integer.parseInt(value); | |
309 items[i] = new IntDataItem(label, label, data); | |
310 } | |
311 catch(NumberFormatException nfe) { | |
312 logger.debug(nfe, nfe); | |
313 } | |
314 } | |
315 return items; | |
316 } | |
317 | |
318 /** | |
292 * This method creates a new instance of LongRangeData which has a type | 319 * This method creates a new instance of LongRangeData which has a type |
293 * "longrange" set. | 320 * "longrange" set. |
294 * | 321 * |
295 * @param ele The Data element. | 322 * @param ele The Data element. |
296 * @param name The name of the Data instance. | 323 * @param name The name of the Data instance. |