Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java @ 3820:8a75cf0841b1 pre2.7-2012-03-16
merged flys-backend/pre2.7-2012-03-16
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:59 +0200 |
parents | 6bb6d43eeb2d |
children |
rev | line source |
---|---|
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import org.w3c.dom.Document; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Element; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.NodeList; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
10 import org.apache.log4j.Logger; |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
11 |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.common.utils.XMLUtils; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.artifacts.httpclient.http.HttpClient; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.flys.client.shared.exceptions.ServerException; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.client.client.services.DistanceInfoService; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.flys.client.shared.model.DistanceInfoObject; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.flys.client.shared.model.DistanceInfoObjectImpl; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 /** |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 */ |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 public class DistanceInfoServiceImpl |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 extends RemoteServiceServlet |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 implements DistanceInfoService |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
34 private static final Logger logger = |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
35 Logger.getLogger(DistanceInfoServiceImpl.class); |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
36 |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 public static final String ERROR_NO_DISTANCEINFO_FOUND = |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 "error_no_distanceinfo_found"; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 public static final String XPATH_DISTANCES = "art:distances/art:distance"; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
229
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
219
diff
changeset
|
43 public DistanceInfoObject[] getDistanceInfo( |
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
219
diff
changeset
|
44 String locale, |
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
219
diff
changeset
|
45 String river) |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 throws ServerException |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
48 logger.info("DistanceInfoServiceImpl.getDistanceInfo"); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
50 String url = getServletContext().getInitParameter("server-url"); |
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
51 |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 Document doc = XMLUtils.newDocument(); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 doc, |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 ArtifactNamespaceContext.NAMESPACE_URI, |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 Element riverEl = ec.create("river"); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 riverEl.setTextContent(river); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 doc.appendChild(riverEl); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
229
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
219
diff
changeset
|
65 HttpClient client = new HttpClientImpl(url, locale); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 try { |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 Document result = client.callService(url, "distanceinfo", doc); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
70 logger.debug("Extract distance info objects now."); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 DistanceInfoObject[] objects = extractDistanceInfoObjects(result); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 if (objects != null && objects.length > 0) { |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 return objects; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 catch (ConnectionException ce) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
78 logger.error(ce, ce); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 /** |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 * Extracts all distance info objects from <i>result</i> document. |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 * |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 * @param result The document retrieved by the server. |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 * |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 * @return a list of DistanceInfoObjects. |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 */ |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 protected DistanceInfoObject[] extractDistanceInfoObjects(Document result) |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 throws ServerException |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 { |
569
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
95 NodeList list = result.getElementsByTagName("distance"); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 if (list == null || list.getLength() == 0) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
98 logger.warn("No distance info found."); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 int num = list.getLength(); |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
103 logger.debug("Response contains " + num + " objects."); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 List<DistanceInfoObject> objects = |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 new ArrayList<DistanceInfoObject>(num); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 for (int i = 0; i < num; i++) { |
569
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
109 DistanceInfoObject obj = buildDistanceInfoObject( |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
110 (Element)list.item(i)); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 if (obj != null) { |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 objects.add(obj); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
117 logger.debug("Retrieved " + objects.size() + " distances."); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 return (DistanceInfoObject[]) |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 objects.toArray(new DistanceInfoObject[num]); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 /** |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 * Extracts information for a single distance info object and intializes an |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 * DistanceInfoObject with them. |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 * |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 * @param node The node that contains the information. |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 * |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 * @return a valid DistanceInfoObject. |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 */ |
569
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
132 protected DistanceInfoObject buildDistanceInfoObject(Element node) { |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 |
569
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
134 String desc = node.getAttribute("description").trim(); |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
135 String from = node.getAttribute("from").trim(); |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
136 String to = node.getAttribute("to").trim(); |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
137 String riverside = node.getAttribute("riverside").trim(); |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
138 String bottom = node.getAttribute("bottom").trim(); |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
139 String top = node.getAttribute("top").trim(); |
567
d9fc58e30a53
Loop through 'Unterkante' 'Oberkante' from service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
229
diff
changeset
|
140 |
569
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
141 if (desc.length() > 0 && from.length() > 0) { |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
142 try { |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
143 Double f = new Double(from); |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
144 Double t = to .length() > 0 ? new Double(to) : null; |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
145 Double b = bottom.length() > 0 ? new Double(bottom) : null; |
c7301a701da9
DistanceInfoService: Got rid of namespace. Use DOM instead of XPath.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
567
diff
changeset
|
146 Double tp = top .length() > 0 ? new Double(top) : null; |
567
d9fc58e30a53
Loop through 'Unterkante' 'Oberkante' from service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
229
diff
changeset
|
147 |
d9fc58e30a53
Loop through 'Unterkante' 'Oberkante' from service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
229
diff
changeset
|
148 return new DistanceInfoObjectImpl(desc, f, t, riverside, b, tp); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 catch (NumberFormatException nfe) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
151 logger.warn(nfe.getLocalizedMessage()); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
154 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
582
diff
changeset
|
155 logger.warn("Invalid distance info object found."); |
219
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
157 return null; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
159 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
160 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |