comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENCalculation.java @ 3806:881fcd01e056

merged flys-artifacts/pre2.6-2011-11-04
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:50 +0200
parents 64b465699a24
children da35b8a23ffb
comparison
equal deleted inserted replaced
3802:e831dc29e572 3806:881fcd01e056
1 package de.intevation.flys.artifacts.model;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.Set;
6
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9
10 import org.apache.log4j.Logger;
11
12 import de.intevation.artifacts.CallMeta;
13
14
15 public class WSPLGENCalculation extends Calculation {
16
17 private static final Logger log = Logger.getLogger(WSPLGENCalculation.class);
18
19 protected Map<Integer, String> errors;
20 protected Map<Integer, String> warnings;
21
22
23 public WSPLGENCalculation() {
24 errors = new HashMap<Integer, String>();
25 warnings = new HashMap<Integer, String>();
26 }
27
28
29 public void addError(Integer key, String msg) {
30 log.debug("New error: (" + key + ") " + msg);
31 errors.put(key, msg);
32 }
33
34
35 public void addWarning(Integer key, String msg) {
36 log.debug("New warning: (" + key + ") " + msg);
37 warnings.put(key, msg);
38 }
39
40
41 public int numErrors() {
42 return errors.size();
43 }
44
45
46 public int numWarnings() {
47 return warnings.size();
48 }
49
50
51 public void toXML(Document document, CallMeta meta) {
52 Element root = document.createElement("problems");
53
54 if (numErrors() > 0) {
55 Set<Map.Entry<Integer, String>> entrySet = errors.entrySet();
56
57 for (Map.Entry<Integer, String> entry: entrySet) {
58 Element problem = document.createElement("problem");
59 problem.setAttribute("error", String.valueOf(entry.getKey()));
60 problem.setTextContent(entry.getValue());
61
62 root.appendChild(problem);
63 }
64 }
65
66 if (numWarnings() > 0) {
67 Set<Map.Entry<Integer, String>> entrySet = warnings.entrySet();
68
69 for (Map.Entry<Integer, String> entry: entrySet) {
70 Element problem = document.createElement("problem");
71 problem.setAttribute("error", String.valueOf(entry.getKey()));
72 problem.setTextContent(entry.getValue());
73
74 root.appendChild(problem);
75 }
76 }
77
78 document.appendChild(root);
79 }
80 }
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org