comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/map/WSPLGENCalculation.java @ 3300:e1cf76b3ecb4

Moved map and WSPLGEN code to subpackage 'map' in the model package. flys-artifacts/trunk@4985 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 13 Jul 2012 10:19:23 +0000
parents
children 975f608dd254
comparison
equal deleted inserted replaced
3299:d76a889bc30d 3300:e1cf76b3ecb4
1 package de.intevation.flys.artifacts.model.map;
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 import de.intevation.flys.artifacts.model.Calculation;
14
15
16 public class WSPLGENCalculation extends Calculation {
17
18 private static final Logger log = Logger.getLogger(WSPLGENCalculation.class);
19
20 protected Map<Integer, String> errors;
21 protected Map<Integer, String> warnings;
22
23
24 public WSPLGENCalculation() {
25 errors = new HashMap<Integer, String>();
26 warnings = new HashMap<Integer, String>();
27 }
28
29
30 public void addError(Integer key, String msg) {
31 log.debug("New error: (" + key + ") " + msg);
32 errors.put(key, msg);
33 }
34
35
36 public void addWarning(Integer key, String msg) {
37 log.debug("New warning: (" + key + ") " + msg);
38 warnings.put(key, msg);
39 }
40
41
42 public int numErrors() {
43 return errors.size();
44 }
45
46
47 public int numWarnings() {
48 return warnings.size();
49 }
50
51
52 @Override
53 public void toXML(Document document, CallMeta meta) {
54 Element root = document.createElement("problems");
55
56 if (numErrors() > 0) {
57 Set<Map.Entry<Integer, String>> entrySet = errors.entrySet();
58
59 for (Map.Entry<Integer, String> entry: entrySet) {
60 Element problem = document.createElement("problem");
61 problem.setAttribute("error", String.valueOf(entry.getKey()));
62 problem.setTextContent(entry.getValue());
63
64 root.appendChild(problem);
65 }
66 }
67
68 if (numWarnings() > 0) {
69 Set<Map.Entry<Integer, String>> entrySet = warnings.entrySet();
70
71 for (Map.Entry<Integer, String> entry: entrySet) {
72 Element problem = document.createElement("problem");
73 problem.setAttribute("error", String.valueOf(entry.getKey()));
74 problem.setTextContent(entry.getValue());
75
76 root.appendChild(problem);
77 }
78 }
79
80 document.appendChild(root);
81 }
82 }
83 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org