Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java @ 1575:0f2b94408bd1
Added further methods to DataFactory to create concrete Data instances.
flys-client/trunk@3841 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 31 Jan 2012 15:20:17 +0000 |
parents | 1227878665b5 |
children | dbdf954dbe94 |
comparison
equal
deleted
inserted
replaced
1574:465f72f68cee | 1575:0f2b94408bd1 |
---|---|
12 | 12 |
13 import de.intevation.flys.client.shared.model.Data; | 13 import de.intevation.flys.client.shared.model.Data; |
14 import de.intevation.flys.client.shared.model.DataItem; | 14 import de.intevation.flys.client.shared.model.DataItem; |
15 import de.intevation.flys.client.shared.model.DefaultData; | 15 import de.intevation.flys.client.shared.model.DefaultData; |
16 import de.intevation.flys.client.shared.model.DefaultDataItem; | 16 import de.intevation.flys.client.shared.model.DefaultDataItem; |
17 import de.intevation.flys.client.shared.model.DoubleArrayData; | |
18 import de.intevation.flys.client.shared.model.IntegerArrayData; | |
19 import de.intevation.flys.client.shared.model.IntegerData; | |
20 import de.intevation.flys.client.shared.model.IntegerOptionsData; | |
21 import de.intevation.flys.client.shared.model.IntegerRangeData; | |
22 import de.intevation.flys.client.shared.model.StringData; | |
17 | 23 |
18 | 24 |
19 /** | 25 /** |
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
21 */ | 27 */ |
37 */ | 43 */ |
38 public static Data createDataFromElement(Element element) { | 44 public static Data createDataFromElement(Element element) { |
39 String name = element.getAttributeNS(NS_URI, "name"); | 45 String name = element.getAttributeNS(NS_URI, "name"); |
40 String type = element.getAttributeNS(NS_URI, "type"); | 46 String type = element.getAttributeNS(NS_URI, "type"); |
41 | 47 |
42 logger.debug("Create new Data instance for: " + name + " | " + type); | 48 try { |
43 | 49 logger.debug("Create Data instance for: " + name + " | " + type); |
44 if (type == null || type.length() == 0) { | 50 |
45 return createDefaultData(element, name); | 51 if (type == null || type.length() == 0) { |
46 } | 52 return createDefaultData(element, name); |
47 else { | 53 } |
48 return createDefaultData(element, name); | 54 |
49 } | 55 type = type.toLowerCase(); |
56 | |
57 if (type.equals(StringData.TYPE)) { | |
58 return createStringData(element, name); | |
59 } | |
60 else if (type.equals(IntegerData.TYPE)) { | |
61 return createIntegerData(element, name); | |
62 } | |
63 else if (type.equals(IntegerOptionsData.TYPE)) { | |
64 return createIntegerOptionsData(element, name); | |
65 } | |
66 else if (type.equals(IntegerRangeData.TYPE)) { | |
67 return createIntegerRangeData(element, name); | |
68 } | |
69 else if (type.equals(IntegerArrayData.TYPE)) { | |
70 return createIntegerArrayData(element, name); | |
71 } | |
72 else if (type.equals(DoubleArrayData.TYPE)) { | |
73 return createDoubleArrayData(element, name); | |
74 } | |
75 else { | |
76 return createDefaultData(element, name); | |
77 } | |
78 } | |
79 catch (Exception e) { | |
80 logger.error("Error while data creation for: " + name); | |
81 } | |
82 | |
83 return null; | |
50 } | 84 } |
51 | 85 |
52 | 86 |
53 /** | 87 /** |
54 * This method creates a new instance of DefaultData which has no real type | 88 * This method creates a new instance of DefaultData which has no real type |
60 * @return an instance of DefaultData. | 94 * @return an instance of DefaultData. |
61 */ | 95 */ |
62 protected static Data createDefaultData(Element ele, String name) { | 96 protected static Data createDefaultData(Element ele, String name) { |
63 logger.debug("Create new DefaultData"); | 97 logger.debug("Create new DefaultData"); |
64 return new DefaultData(name, name, "default", extractDataItems(ele)); | 98 return new DefaultData(name, name, "default", extractDataItems(ele)); |
99 } | |
100 | |
101 | |
102 /** | |
103 * This method creates a new instance of StringData which has a type | |
104 * "string" set. | |
105 * | |
106 * @param ele The Data element. | |
107 * @param name The name of the Data instance. | |
108 * | |
109 * @return an instance of StringData. | |
110 */ | |
111 protected static Data createStringData(Element ele, String name) { | |
112 return new StringData(name, name, extractDataItems(ele)); | |
113 } | |
114 | |
115 | |
116 /** | |
117 * This method creates a new instance of DefaultData which has a type | |
118 * "integer" set. | |
119 * | |
120 * @param ele The Data element. | |
121 * @param name The name of the Data instance. | |
122 * | |
123 * @return an instance of IntegerData. | |
124 */ | |
125 protected static Data createIntegerData(Element ele, String name) { | |
126 return new IntegerData(name, name, extractDataItems(ele)); | |
127 } | |
128 | |
129 | |
130 /** | |
131 * This method creates a new instance of DefaultData which has a type | |
132 * "intoptions" set. | |
133 * | |
134 * @param ele The Data element. | |
135 * @param name The name of the Data instance. | |
136 * | |
137 * @return an instance of IntegerOptionsData. | |
138 */ | |
139 protected static Data createIntegerOptionsData(Element ele, String name) { | |
140 return new IntegerOptionsData(name, name, extractDataItems(ele)); | |
141 } | |
142 | |
143 | |
144 /** | |
145 * This method creates a new instance of DefaultData which has a type | |
146 * "intrange" set. | |
147 * | |
148 * @param ele The Data element. | |
149 * @param name The name of the Data instance. | |
150 * | |
151 * @return an instance of IntegerRangeData. | |
152 */ | |
153 protected static Data createIntegerRangeData(Element ele, String name) { | |
154 DataItem[] items = extractDataItems(ele); | |
155 String rawValue = items[0].getStringValue(); | |
156 | |
157 String[] minmax = rawValue.split(";"); | |
158 | |
159 return new IntegerRangeData( | |
160 name, | |
161 name, | |
162 Integer.valueOf(minmax[0]), | |
163 Integer.valueOf(minmax[1])); | |
164 } | |
165 | |
166 | |
167 /** | |
168 * This method creates a new instance of DefaultData which has a type | |
169 * "integerarray" set. | |
170 * | |
171 * @param ele The Data element. | |
172 * @param name The name of the Data instance. | |
173 * | |
174 * @return an instance of IntegerArrayData. | |
175 */ | |
176 protected static Data createIntegerArrayData(Element ele, String name) { | |
177 DataItem[] items = extractDataItems(ele); | |
178 String rawValue = items[0].getStringValue(); | |
179 | |
180 String[] values = rawValue.split(";"); | |
181 int[] integers = new int[values.length]; | |
182 | |
183 for (int i = 0; i < values.length; i++) { | |
184 try { | |
185 integers[i] = Integer.valueOf(values[i]); | |
186 } | |
187 catch (NumberFormatException nfe) { | |
188 logger.warn("Error while parsing IntegerArrayData: " + nfe); | |
189 } | |
190 } | |
191 | |
192 return new IntegerArrayData(name, name, integers); | |
193 } | |
194 | |
195 | |
196 /** | |
197 * This method creates a new instance of DefaultData which has a type | |
198 * "doublearray" set. | |
199 * | |
200 * @param ele The Data element. | |
201 * @param name The name of the Data instance. | |
202 * | |
203 * @return an instance of DoubleArrayData. | |
204 */ | |
205 protected static Data createDoubleArrayData(Element ele, String name) { | |
206 return new DoubleArrayData(name, name, extractDataItems(ele)); | |
65 } | 207 } |
66 | 208 |
67 | 209 |
68 /** | 210 /** |
69 * This method extracts the art:item elements placed under <i>elements</i>. | 211 * This method extracts the art:item elements placed under <i>elements</i>. |