comparison flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java @ 2528:33e2a1e23ae8

Implemented ParameterMatrixPanel.createOld() and added a real 'description' to Data instances in DataFactory. flys-client/trunk@4421 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 May 2012 10:45:57 +0000
parents 6a65694bdcc2
children 261347ea60b8
comparison
equal deleted inserted replaced
2527:c8413741339f 2528:33e2a1e23ae8
40 * @param element The Data element. 40 * @param element The Data element.
41 * 41 *
42 * @return a Data instance. 42 * @return a Data instance.
43 */ 43 */
44 public static Data createDataFromElement(Element element) { 44 public static Data createDataFromElement(Element element) {
45 String name = element.getAttributeNS(NS_URI, "name"); 45 String name = element.getAttributeNS(NS_URI, "name");
46 String type = element.getAttributeNS(NS_URI, "type"); 46 String type = element.getAttributeNS(NS_URI, "type");
47 String label = element.getAttributeNS(NS_URI, "label");
48
49 label = label != null && label.length() > 0 ? label : name;
47 50
48 try { 51 try {
49 logger.debug("Create Data instance for: " + name + " | " + type); 52 logger.debug("Create Data instance for: " + name + " | " + type);
50 53
51 if (type == null || type.length() == 0) { 54 if (type == null || type.length() == 0) {
52 return createDefaultData(element, name); 55 return createDefaultData(element, name, label);
53 } 56 }
54 57
55 type = type.toLowerCase(); 58 type = type.toLowerCase();
56 59
57 if (type.equals(StringData.TYPE)) { 60 if (type.equals(StringData.TYPE)) {
58 return createStringData(element, name); 61 return createStringData(element, name, label);
59 } 62 }
60 else if (type.equals(IntegerData.TYPE)) { 63 else if (type.equals(IntegerData.TYPE)) {
61 return createIntegerData(element, name); 64 return createIntegerData(element, name, label);
62 } 65 }
63 else if (type.equals(IntegerOptionsData.TYPE)) { 66 else if (type.equals(IntegerOptionsData.TYPE)) {
64 return createIntegerOptionsData(element, name); 67 return createIntegerOptionsData(element, name, label);
65 } 68 }
66 else if (type.equals(IntegerRangeData.TYPE)) { 69 else if (type.equals(IntegerRangeData.TYPE)) {
67 return createIntegerRangeData(element, name); 70 return createIntegerRangeData(element, name, label);
68 } 71 }
69 else if (type.equals(IntegerArrayData.TYPE)) { 72 else if (type.equals(IntegerArrayData.TYPE)) {
70 return createIntegerArrayData(element, name); 73 return createIntegerArrayData(element, name, label);
71 } 74 }
72 else if (type.equals(DoubleArrayData.TYPE)) { 75 else if (type.equals(DoubleArrayData.TYPE)) {
73 return createDoubleArrayData(element, name); 76 return createDoubleArrayData(element, name, label);
74 } 77 }
75 else if (type.equals(LongRangeData.TYPE)) { 78 else if (type.equals(LongRangeData.TYPE)) {
76 return createLongRangeData(element, name); 79 return createLongRangeData(element, name, label);
77 } 80 }
78 else { 81 else {
79 return createDefaultData(element, name); 82 return createDefaultData(element, name, label);
80 } 83 }
81 } 84 }
82 catch (Exception e) { 85 catch (Exception e) {
83 logger.error("Error while data creation for: " + name); 86 logger.error("Error while data creation for: " + name);
84 } 87 }
94 * @param ele The Data element. 97 * @param ele The Data element.
95 * @param name The name of the Data instance. 98 * @param name The name of the Data instance.
96 * 99 *
97 * @return an instance of DefaultData. 100 * @return an instance of DefaultData.
98 */ 101 */
99 protected static Data createDefaultData(Element ele, String name) { 102 protected static Data createDefaultData(Element ele, String name, String label) {
100 logger.debug("Create new DefaultData"); 103 logger.debug("Create new DefaultData");
101 return new DefaultData(name, name, "default", extractDataItems(ele)); 104 return new DefaultData(name, label, "default", extractDataItems(ele));
102 } 105 }
103 106
104 107
105 /** 108 /**
106 * This method creates a new instance of StringData which has a type 109 * This method creates a new instance of StringData which has a type
109 * @param ele The Data element. 112 * @param ele The Data element.
110 * @param name The name of the Data instance. 113 * @param name The name of the Data instance.
111 * 114 *
112 * @return an instance of StringData. 115 * @return an instance of StringData.
113 */ 116 */
114 protected static Data createStringData(Element ele, String name) { 117 protected static Data createStringData(Element ele, String name, String label) {
115 return new StringData(name, name, extractDataItems(ele)); 118 return new StringData(name, label, extractDataItems(ele));
116 } 119 }
117 120
118 121
119 /** 122 /**
120 * This method creates a new instance of DefaultData which has a type 123 * This method creates a new instance of DefaultData which has a type
123 * @param ele The Data element. 126 * @param ele The Data element.
124 * @param name The name of the Data instance. 127 * @param name The name of the Data instance.
125 * 128 *
126 * @return an instance of IntegerData. 129 * @return an instance of IntegerData.
127 */ 130 */
128 protected static Data createIntegerData(Element ele, String name) { 131 protected static Data createIntegerData(Element ele, String name, String label) {
129 return new IntegerData(name, name, extractDataItems(ele)); 132 return new IntegerData(name, label, extractDataItems(ele));
130 } 133 }
131 134
132 135
133 /** 136 /**
134 * This method creates a new instance of DefaultData which has a type 137 * This method creates a new instance of DefaultData which has a type
137 * @param ele The Data element. 140 * @param ele The Data element.
138 * @param name The name of the Data instance. 141 * @param name The name of the Data instance.
139 * 142 *
140 * @return an instance of IntegerOptionsData. 143 * @return an instance of IntegerOptionsData.
141 */ 144 */
142 protected static Data createIntegerOptionsData(Element ele, String name) { 145 protected static Data createIntegerOptionsData(Element ele, String name, String label) {
143 return new IntegerOptionsData(name, name, extractDataItems(ele)); 146 return new IntegerOptionsData(name, label, extractDataItems(ele));
144 } 147 }
145 148
146 149
147 /** 150 /**
148 * This method creates a new instance of DefaultData which has a type 151 * This method creates a new instance of DefaultData which has a type
151 * @param ele The Data element. 154 * @param ele The Data element.
152 * @param name The name of the Data instance. 155 * @param name The name of the Data instance.
153 * 156 *
154 * @return an instance of IntegerRangeData. 157 * @return an instance of IntegerRangeData.
155 */ 158 */
156 protected static Data createIntegerRangeData(Element ele, String name) { 159 protected static Data createIntegerRangeData(Element ele, String name, String label) {
157 DataItem[] items = extractDataItems(ele); 160 DataItem[] items = extractDataItems(ele);
158 String rawValue = items[0].getStringValue(); 161 String rawValue = items[0].getStringValue();
159 162
160 String[] minmax = rawValue.split(";"); 163 String[] minmax = rawValue.split(";");
161 164
162 return new IntegerRangeData( 165 return new IntegerRangeData(
163 name, 166 name,
164 name, 167 label,
165 Integer.valueOf(minmax[0]), 168 Integer.valueOf(minmax[0]),
166 Integer.valueOf(minmax[1])); 169 Integer.valueOf(minmax[1]));
167 } 170 }
168 171
169 172
174 * @param ele The Data element. 177 * @param ele The Data element.
175 * @param name The name of the Data instance. 178 * @param name The name of the Data instance.
176 * 179 *
177 * @return an instance of IntegerArrayData. 180 * @return an instance of IntegerArrayData.
178 */ 181 */
179 protected static Data createIntegerArrayData(Element ele, String name) { 182 protected static Data createIntegerArrayData(Element ele, String name, String label) {
180 DataItem[] items = extractDataItems(ele); 183 DataItem[] items = extractDataItems(ele);
181 String rawValue = items[0].getStringValue(); 184 String rawValue = items[0].getStringValue();
182 185
183 String[] values = rawValue.split(";"); 186 String[] values = rawValue.split(";");
184 int[] integers = new int[values.length]; 187 int[] integers = new int[values.length];
190 catch (NumberFormatException nfe) { 193 catch (NumberFormatException nfe) {
191 logger.warn("Error while parsing IntegerArrayData: " + nfe); 194 logger.warn("Error while parsing IntegerArrayData: " + nfe);
192 } 195 }
193 } 196 }
194 197
195 return new IntegerArrayData(name, items[0].getLabel(), integers); 198 return new IntegerArrayData(name, label, integers);
196 } 199 }
197 200
198 201
199 /** 202 /**
200 * This method creates a new instance of DefaultData which has a type 203 * This method creates a new instance of DefaultData which has a type
203 * @param ele The Data element. 206 * @param ele The Data element.
204 * @param name The name of the Data instance. 207 * @param name The name of the Data instance.
205 * 208 *
206 * @return an instance of DoubleArrayData. 209 * @return an instance of DoubleArrayData.
207 */ 210 */
208 protected static Data createDoubleArrayData(Element ele, String name) { 211 protected static Data createDoubleArrayData(Element ele, String name, String label) {
209 DataItem[] items = extractDataItems(ele); 212 DataItem[] items = extractDataItems(ele);
210 String rawValue = items[0].getStringValue(); 213 String rawValue = items[0].getStringValue();
211 214
212 String[] values = rawValue.split(";"); 215 String[] values = rawValue.split(";");
213 double[] doubles = new double[values.length]; 216 double[] doubles = new double[values.length];
219 catch (NumberFormatException nfe) { 222 catch (NumberFormatException nfe) {
220 logger.warn("Error while parsing DoubleArrayData: " + nfe); 223 logger.warn("Error while parsing DoubleArrayData: " + nfe);
221 } 224 }
222 } 225 }
223 226
224 return new DoubleArrayData(name, items[0].getLabel(), doubles); 227 return new DoubleArrayData(name, label, doubles);
225 } 228 }
226 229
227 230
228 /** 231 /**
229 * This method extracts the art:item elements placed under <i>elements</i>. 232 * This method extracts the art:item elements placed under <i>elements</i>.
268 * @param ele The Data element. 271 * @param ele The Data element.
269 * @param name The name of the Data instance. 272 * @param name The name of the Data instance.
270 * 273 *
271 * @return an instance of IntegerRangeData. 274 * @return an instance of IntegerRangeData.
272 */ 275 */
273 protected static Data createLongRangeData(Element ele, String name) { 276 protected static Data createLongRangeData(Element ele, String name, String label) {
274 DataItem[] items = extractDataItems(ele); 277 DataItem[] items = extractDataItems(ele);
275 String rawValue = items[0].getStringValue(); 278 String rawValue = items[0].getStringValue();
276 279
277 String[] minmax = rawValue.split(";"); 280 String[] minmax = rawValue.split(";");
278 281
279 return new LongRangeData( 282 return new LongRangeData(
280 name, 283 name,
281 name, 284 label,
282 Long.valueOf(minmax[0]), 285 Long.valueOf(minmax[0]),
283 Long.valueOf(minmax[1])); 286 Long.valueOf(minmax[1]));
284 } 287 }
285 288
286 } 289 }

http://dive4elements.wald.intevation.org