comparison flys-aft/src/main/java/de/intevation/aft/SyncContext.java @ 4084:9178beeb7b05

Moved DIPS gauge number -> DIPS gauge index. flys-aft/trunk@3514 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 21 Dec 2011 15:16:58 +0000
parents 97de7a552b79
children 859b4781554a
comparison
equal deleted inserted replaced
4083:44dc38ca8492 4084:9178beeb7b05
1 package de.intevation.aft; 1 package de.intevation.aft;
2
3 import java.util.Map;
4 import java.util.HashMap;
5
6 import org.w3c.dom.Document;
2 7
3 import de.intevation.db.ConnectedStatements; 8 import de.intevation.db.ConnectedStatements;
4 9
5 import org.w3c.dom.Document; 10 import org.w3c.dom.NodeList;
11 import org.w3c.dom.Element;
12
13 import org.apache.log4j.Logger;
6 14
7 public class SyncContext 15 public class SyncContext
8 { 16 {
9 protected ConnectedStatements aftStatements; 17 private static Logger log = Logger.getLogger(SyncContext.class);
10 protected ConnectedStatements flysStatements; 18
11 protected Document dips; 19 protected ConnectedStatements aftStatements;
20 protected ConnectedStatements flysStatements;
21 protected Document dips;
22 protected Map<Long, DIPSGauge> numberToGauge;
12 23
13 public SyncContext() { 24 public SyncContext() {
14 } 25 }
15 26
16 public SyncContext( 27 public SyncContext(
19 Document dips 30 Document dips
20 ) { 31 ) {
21 this.aftStatements = aftStatements; 32 this.aftStatements = aftStatements;
22 this.flysStatements = flysStatements; 33 this.flysStatements = flysStatements;
23 this.dips = dips; 34 this.dips = dips;
35 numberToGauge = indexByNumber(dips);
24 } 36 }
25 37
26 public ConnectedStatements getAftStatements() { 38 public ConnectedStatements getAftStatements() {
27 return aftStatements; 39 return aftStatements;
28 } 40 }
49 61
50 void close() { 62 void close() {
51 aftStatements.close(); 63 aftStatements.close();
52 flysStatements.close(); 64 flysStatements.close();
53 } 65 }
66
67 public static Long numberToLong(String s) {
68 try {
69 return Long.valueOf(s.trim());
70 }
71 catch (NumberFormatException nfe) {
72 }
73 return null;
74 }
75
76 public Map<Long, DIPSGauge> getDIPSGauges() {
77 return numberToGauge;
78 }
79
80 protected static Map<Long, DIPSGauge> indexByNumber(Document document) {
81 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>();
82 NodeList nodes = document.getElementsByTagName("PEGELSTATION");
83 for (int i = nodes.getLength()-1; i >= 0; --i) {
84 Element element = (Element)nodes.item(i);
85 String numberString = element.getAttribute("NUMMER");
86 Long number = numberToLong(numberString);
87 if (number != null) {
88 DIPSGauge newG = new DIPSGauge(element);
89 DIPSGauge oldG = map.put(number, newG);
90 if (oldG != null) {
91 log.warn("DIPS: '" + newG.getName() +
92 "' collides with '" + oldG.getName() +
93 "' on gauge number " + number + ".");
94 }
95 }
96 else {
97 log.warn("DIPS: gauge '" + element.getAttribute("NAME") +
98 "' has invalid gauge number '" + numberString + "'");
99 }
100 }
101 return map;
102 }
103
54 } 104 }
55 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
56 106

http://dive4elements.wald.intevation.org