comparison gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactDescriptionFactory.java @ 8203:238fc722f87a

sed 's/logger/log/g' src/**/*.java
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 13:19:22 +0200
parents b9decb8bfb21
children 5e38e2924c07
comparison
equal deleted inserted replaced
8202:e4606eae8ea5 8203:238fc722f87a
50 * 50 *
51 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 51 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
52 */ 52 */
53 public class ArtifactDescriptionFactory { 53 public class ArtifactDescriptionFactory {
54 54
55 private static final Logger logger = 55 private static final Logger log =
56 Logger.getLogger(ArtifactDescriptionFactory.class); 56 Logger.getLogger(ArtifactDescriptionFactory.class);
57 57
58 58
59 public static final String XPATH_STATE_NAME = "@art:name"; 59 public static final String XPATH_STATE_NAME = "@art:name";
60 60
80 * @param doc A DESCRIBE document. 80 * @param doc A DESCRIBE document.
81 * 81 *
82 * @return the {@link ArtifactDescription}. 82 * @return the {@link ArtifactDescription}.
83 */ 83 */
84 public static ArtifactDescription createArtifactDescription(Document doc) { 84 public static ArtifactDescription createArtifactDescription(Document doc) {
85 logger.debug("ArtifactDescriptionFactory.createArtifactDescription"); 85 log.debug("ArtifactDescriptionFactory.createArtifactDescription");
86 86
87 Node currentState = ClientProtocolUtils.getCurrentState(doc); 87 Node currentState = ClientProtocolUtils.getCurrentState(doc);
88 Node staticNode = ClientProtocolUtils.getStaticUI(doc); 88 Node staticNode = ClientProtocolUtils.getStaticUI(doc);
89 Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc); 89 Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc);
90 Node reachable = ClientProtocolUtils.getReachableStates(doc); 90 Node reachable = ClientProtocolUtils.getReachableStates(doc);
94 currentState, 94 currentState,
95 XPATH_STATE_NAME, 95 XPATH_STATE_NAME,
96 XPathConstants.STRING, 96 XPathConstants.STRING,
97 ArtifactNamespaceContext.INSTANCE); 97 ArtifactNamespaceContext.INSTANCE);
98 98
99 logger.debug("Current state name: " + state); 99 log.debug("Current state name: " + state);
100 100
101 DataList currentData = extractCurrentData(dynamicNode, state); 101 DataList currentData = extractCurrentData(dynamicNode, state);
102 DataList[] old = extractOldData(staticNode); 102 DataList[] old = extractOldData(staticNode);
103 String[] states = extractReachableStates(reachable); 103 String[] states = extractReachableStates(reachable);
104 OutputMode[] outs = extractOutputModes(outputs); 104 OutputMode[] outs = extractOutputModes(outputs);
124 * @return A {@link Data} object that represents the data which might be 124 * @return A {@link Data} object that represents the data which might be
125 * entered by the user in the current state or null, if no data might be 125 * entered by the user in the current state or null, if no data might be
126 * entered. 126 * entered.
127 */ 127 */
128 protected static DataList extractCurrentData(Node dynamicNode, String state) { 128 protected static DataList extractCurrentData(Node dynamicNode, String state) {
129 logger.debug("ArtifactDescriptionFactory.extractCurrentData"); 129 log.debug("ArtifactDescriptionFactory.extractCurrentData");
130 130
131 NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode); 131 NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode);
132 String help = extractHelpText(dynamicNode); 132 String help = extractHelpText(dynamicNode);
133 String uiProvider = extractUIProvider(dynamicNode); 133 String uiProvider = extractUIProvider(dynamicNode);
134 134
145 String name = XMLUtils.xpathString( 145 String name = XMLUtils.xpathString(
146 d, "@art:name", ArtifactNamespaceContext.INSTANCE); 146 d, "@art:name", ArtifactNamespaceContext.INSTANCE);
147 String type = XMLUtils.xpathString( 147 String type = XMLUtils.xpathString(
148 d, "@art:type", ArtifactNamespaceContext.INSTANCE); 148 d, "@art:type", ArtifactNamespaceContext.INSTANCE);
149 149
150 logger.debug("Create new IntegerRangeData object for: " + name); 150 log.debug("Create new IntegerRangeData object for: " + name);
151 logger.debug("New Data is from type: " + type); 151 log.debug("New Data is from type: " + type);
152 152
153 // TODO replace with DataFactory. 153 // TODO replace with DataFactory.
154 154
155 if (type == null || type.length() == 0) { 155 if (type == null || type.length() == 0) {
156 NodeList choices = ClientProtocolUtils.getItemNodes(d); 156 NodeList choices = ClientProtocolUtils.getItemNodes(d);
181 list.add( 181 list.add(
182 new IntegerRangeData(name, label, lower, upper)); 182 new IntegerRangeData(name, label, lower, upper));
183 } 183 }
184 } 184 }
185 catch (NumberFormatException nfe) { 185 catch (NumberFormatException nfe) {
186 logger.warn("NumberFormatException: ", nfe); 186 log.warn("NumberFormatException: ", nfe);
187 } 187 }
188 } 188 }
189 else if (type.equals("longrange")) { 189 else if (type.equals("longrange")) {
190 String min = ClientProtocolUtils.getMinNode(d); 190 String min = ClientProtocolUtils.getMinNode(d);
191 String max = ClientProtocolUtils.getMaxNode(d); 191 String max = ClientProtocolUtils.getMaxNode(d);
204 Long.valueOf(defMin), 204 Long.valueOf(defMin),
205 Long.valueOf(defMax))); 205 Long.valueOf(defMax)));
206 } 206 }
207 } 207 }
208 catch (NumberFormatException nfe) { 208 catch (NumberFormatException nfe) {
209 logger.warn("NumberFormatException: ", nfe); 209 log.warn("NumberFormatException: ", nfe);
210 } 210 }
211 } 211 }
212 else if (type.equals("intarray")) { 212 else if (type.equals("intarray")) {
213 list.add(new IntegerArrayData(name, label, null)); 213 list.add(new IntegerArrayData(name, label, null));
214 } 214 }
229 } 229 }
230 else if (type.equals("multiattribute")) { 230 else if (type.equals("multiattribute")) {
231 list.add(DataFactory.createMultiAttributeData(d, name, label)); 231 list.add(DataFactory.createMultiAttributeData(d, name, label));
232 } 232 }
233 else { 233 else {
234 logger.warn("Unrecognized Dynamic data type."); 234 log.warn("Unrecognized Dynamic data type.");
235 NodeList choices = ClientProtocolUtils.getItemNodes(d); 235 NodeList choices = ClientProtocolUtils.getItemNodes(d);
236 DataItem[] dataItems = extractCurrentDataItems(choices); 236 DataItem[] dataItems = extractCurrentDataItems(choices);
237 DataItem def = extractDefaultDataItem(d); 237 DataItem def = extractDefaultDataItem(d);
238 238
239 String min = ClientProtocolUtils.getMinNode(d); 239 String min = ClientProtocolUtils.getMinNode(d);
260 * @param data The data object node. 260 * @param data The data object node.
261 * 261 *
262 * @return the default DataItem. 262 * @return the default DataItem.
263 */ 263 */
264 protected static DataItem extractDefaultDataItem(Node data) { 264 protected static DataItem extractDefaultDataItem(Node data) {
265 logger.debug("ArtifactDescriptionFactory.extractDefaultDataItem"); 265 log.debug("ArtifactDescriptionFactory.extractDefaultDataItem");
266 266
267 String value = XMLUtils.xpathString( 267 String value = XMLUtils.xpathString(
268 data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE); 268 data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE);
269 269
270 String label = XMLUtils.xpathString( 270 String label = XMLUtils.xpathString(
284 * @param items The items in the DESCRIBE document. 284 * @param items The items in the DESCRIBE document.
285 * 285 *
286 * @return the {@link DataItem}s. 286 * @return the {@link DataItem}s.
287 */ 287 */
288 protected static DataItem[] extractCurrentDataItems(NodeList items) { 288 protected static DataItem[] extractCurrentDataItems(NodeList items) {
289 logger.debug("ArtifactDescriptionFactory.extractCurrentDataItems"); 289 log.debug("ArtifactDescriptionFactory.extractCurrentDataItems");
290 290
291 if (items == null || items.getLength() == 0) { 291 if (items == null || items.getLength() == 0) {
292 logger.debug("No data items found."); 292 log.debug("No data items found.");
293 return null; 293 return null;
294 } 294 }
295 295
296 int count = items.getLength(); 296 int count = items.getLength();
297 297
316 return dataItems.toArray(new DataItem[count]); 316 return dataItems.toArray(new DataItem[count]);
317 } 317 }
318 318
319 319
320 protected static double[] extractMinMaxQValues(Node item) { 320 protected static double[] extractMinMaxQValues(Node item) {
321 logger.debug("ArtifactDescriptionFactory.extractMinMaxQValues"); 321 log.debug("ArtifactDescriptionFactory.extractMinMaxQValues");
322 322
323 if (item == null) { 323 if (item == null) {
324 logger.debug("This node is empty - no min/max Q values."); 324 log.debug("This node is empty - no min/max Q values.");
325 return null; 325 return null;
326 } 326 }
327 327
328 Node node = (Node) XMLUtils.xpath( 328 Node node = (Node) XMLUtils.xpath(
329 item, 329 item,
330 "art:range[@art:type='Q']", 330 "art:range[@art:type='Q']",
331 XPathConstants.NODE, 331 XPathConstants.NODE,
332 ArtifactNamespaceContext.INSTANCE); 332 ArtifactNamespaceContext.INSTANCE);
333 333
334 if (node == null) { 334 if (node == null) {
335 logger.debug("No min/max Q values found."); 335 log.debug("No min/max Q values found.");
336 return null; 336 return null;
337 } 337 }
338 338
339 return extractMinMaxValues(node); 339 return extractMinMaxValues(node);
340 } 340 }
341 341
342 342
343 protected static double[] extractMinMaxWValues(Node item) { 343 protected static double[] extractMinMaxWValues(Node item) {
344 logger.debug("ArtifactDescriptionFactory.extractMinMaxWValues"); 344 log.debug("ArtifactDescriptionFactory.extractMinMaxWValues");
345 345
346 if (item == null) { 346 if (item == null) {
347 logger.debug("This node is empty - no min/max W values."); 347 log.debug("This node is empty - no min/max W values.");
348 return null; 348 return null;
349 } 349 }
350 350
351 Node node = (Node) XMLUtils.xpath( 351 Node node = (Node) XMLUtils.xpath(
352 item, 352 item,
353 "art:range[@art:type='W']", 353 "art:range[@art:type='W']",
354 XPathConstants.NODE, 354 XPathConstants.NODE,
355 ArtifactNamespaceContext.INSTANCE); 355 ArtifactNamespaceContext.INSTANCE);
356 356
357 if (node == null) { 357 if (node == null) {
358 logger.debug("No min/max W values found."); 358 log.debug("No min/max W values found.");
359 return null; 359 return null;
360 } 360 }
361 361
362 return extractMinMaxValues(node); 362 return extractMinMaxValues(node);
363 } 363 }
364 364
365 365
366 protected static double[] extractMinMaxValues(Node node) { 366 protected static double[] extractMinMaxValues(Node node) {
367 logger.debug("ArtifactDescriptionFactory.extractMinMaxValues"); 367 log.debug("ArtifactDescriptionFactory.extractMinMaxValues");
368 368
369 String minStr = XMLUtils.xpathString( 369 String minStr = XMLUtils.xpathString(
370 node, "art:min/text()", ArtifactNamespaceContext.INSTANCE); 370 node, "art:min/text()", ArtifactNamespaceContext.INSTANCE);
371 371
372 String maxStr = XMLUtils.xpathString( 372 String maxStr = XMLUtils.xpathString(
373 node, "art:max/text()", ArtifactNamespaceContext.INSTANCE); 373 node, "art:max/text()", ArtifactNamespaceContext.INSTANCE);
374 374
375 if (maxStr == null || minStr == null) { 375 if (maxStr == null || minStr == null) {
376 logger.debug("No min/max values found."); 376 log.debug("No min/max values found.");
377 return null; 377 return null;
378 } 378 }
379 379
380 try { 380 try {
381 double min = Double.valueOf(minStr); 381 double min = Double.valueOf(minStr);
382 double max = Double.valueOf(maxStr); 382 double max = Double.valueOf(maxStr);
383 383
384 return new double[] { min, max }; 384 return new double[] { min, max };
385 } 385 }
386 catch (NumberFormatException nfe) { 386 catch (NumberFormatException nfe) {
387 logger.debug("Error while parsing min/max values."); 387 log.debug("Error while parsing min/max values.");
388 } 388 }
389 389
390 return null; 390 return null;
391 } 391 }
392 392
398 * @param staticNode The static ui node of the DESCRIBE. 398 * @param staticNode The static ui node of the DESCRIBE.
399 * 399 *
400 * @return the DataList objects. 400 * @return the DataList objects.
401 */ 401 */
402 protected static DataList[] extractOldData(Node staticNode) { 402 protected static DataList[] extractOldData(Node staticNode) {
403 logger.debug("ArtifactDescriptionFactory.extractOldData()"); 403 log.debug("ArtifactDescriptionFactory.extractOldData()");
404 404
405 NodeList stateNodes = (NodeList) XMLUtils.xpath( 405 NodeList stateNodes = (NodeList) XMLUtils.xpath(
406 staticNode, 406 staticNode,
407 XPATH_STATIC_STATE_NODE, 407 XPATH_STATIC_STATE_NODE,
408 XPathConstants.NODESET, 408 XPathConstants.NODESET,
409 ArtifactNamespaceContext.INSTANCE); 409 ArtifactNamespaceContext.INSTANCE);
410 410
411 if (stateNodes == null || stateNodes.getLength() == 0) { 411 if (stateNodes == null || stateNodes.getLength() == 0) {
412 logger.debug("No old items found."); 412 log.debug("No old items found.");
413 return null; 413 return null;
414 } 414 }
415 415
416 int count = stateNodes.getLength(); 416 int count = stateNodes.getLength();
417 DataList[] data = new DataList[count]; 417 DataList[] data = new DataList[count];
492 * @param reachable The reachable states node. 492 * @param reachable The reachable states node.
493 * 493 *
494 * @return an array with identifiers of reachable states. 494 * @return an array with identifiers of reachable states.
495 */ 495 */
496 protected static String[] extractReachableStates(Node reachable) { 496 protected static String[] extractReachableStates(Node reachable) {
497 logger.debug("ArtifactDescriptionFactory.extractReachableStates()"); 497 log.debug("ArtifactDescriptionFactory.extractReachableStates()");
498 498
499 NodeList list = (NodeList) XMLUtils.xpath( 499 NodeList list = (NodeList) XMLUtils.xpath(
500 reachable, 500 reachable,
501 XPATH_REACHABLE_STATE, 501 XPATH_REACHABLE_STATE,
502 XPathConstants.NODESET, 502 XPathConstants.NODESET,
530 * modes. 530 * modes.
531 * 531 *
532 * @return an array of Output modes. 532 * @return an array of Output modes.
533 */ 533 */
534 protected static OutputMode[] extractOutputModes(NodeList outputs) { 534 protected static OutputMode[] extractOutputModes(NodeList outputs) {
535 logger.debug("ArtifactDescriptionFactory.extractOutputModes"); 535 log.debug("ArtifactDescriptionFactory.extractOutputModes");
536 536
537 if (outputs == null || outputs.getLength() == 0) { 537 if (outputs == null || outputs.getLength() == 0) {
538 return null; 538 return null;
539 } 539 }
540 540
554 554
555 if (name != null) { 555 if (name != null) {
556 outs.add(new DefaultOutputMode(name, desc, mimeType)); 556 outs.add(new DefaultOutputMode(name, desc, mimeType));
557 } 557 }
558 else { 558 else {
559 logger.debug("Found an invalid output mode."); 559 log.debug("Found an invalid output mode.");
560 } 560 }
561 } 561 }
562 562
563 return (OutputMode[]) outs.toArray(new OutputMode[size]); 563 return (OutputMode[]) outs.toArray(new OutputMode[size]);
564 } 564 }
565 565
566 566
567 protected static Recommendation[] extractRecommendedArtifacts(Document doc){ 567 protected static Recommendation[] extractRecommendedArtifacts(Document doc){
568 logger.debug("ArtifactDescriptionFactory.extractRecommendedArtifacts."); 568 log.debug("ArtifactDescriptionFactory.extractRecommendedArtifacts.");
569 569
570 NodeList list = (NodeList) XMLUtils.xpath( 570 NodeList list = (NodeList) XMLUtils.xpath(
571 doc, 571 doc,
572 XPATH_RECOMMENDED_ARTIFACTS, 572 XPATH_RECOMMENDED_ARTIFACTS,
573 XPathConstants.NODESET, 573 XPathConstants.NODESET,
582 String factory = e.getAttribute("factory"); 582 String factory = e.getAttribute("factory");
583 String index = e.getAttribute("ids"); 583 String index = e.getAttribute("ids");
584 String targetOut = e.getAttribute("target_out"); 584 String targetOut = e.getAttribute("target_out");
585 585
586 if (factory != null && factory.length() > 0) { 586 if (factory != null && factory.length() > 0) {
587 logger.debug("Adding Recommendation. Factory: " + factory + 587 log.debug("Adding Recommendation. Factory: " + factory +
588 " IDs: " + index + " target out " + targetOut); 588 " IDs: " + index + " target out " + targetOut);
589 rec[i] = new Recommendation(factory, index, null, null, targetOut); 589 rec[i] = new Recommendation(factory, index, null, null, targetOut);
590 } 590 }
591 } 591 }
592 592

http://dive4elements.wald.intevation.org