Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java @ 223:964abeb76771
Added more i18n error messages.
flys-client/trunk@1668 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 12 Apr 2011 10:51:39 +0000 |
parents | 7523faf567e5 |
children | 924da6695800 |
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 javax.xml.xpath.XPathConstants; |
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 |
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.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
|
9 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
|
10 import org.w3c.dom.Node; |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 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
|
12 |
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 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
|
14 |
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.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
|
16 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
|
17 |
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.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
|
19 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
|
20 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
|
21 |
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.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
|
23 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
|
24 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
|
25 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
|
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 /** |
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 * @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
|
30 */ |
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 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
|
32 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
|
33 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
|
34 { |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 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
|
36 "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
|
37 |
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 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
|
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 |
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 public DistanceInfoObject[] getDistanceInfo(String url, String 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
|
42 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
|
43 { |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 System.out.println("DistanceInfoServiceImpl.getDistanceInfo"); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
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 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
|
47 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
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 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
|
54 |
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 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
|
56 |
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 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
|
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 HttpClient client = new HttpClientImpl(url); |
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 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
|
62 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
|
63 |
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 System.out.println("Extract distance info objects now."); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 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
|
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 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
|
68 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
|
69 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 } |
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 catch (ConnectionException ce) { |
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 System.err.println(ce.getLocalizedMessage()); |
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 } |
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 |
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 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
|
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 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 |
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 * 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
|
81 * |
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 * @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
|
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 * @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
|
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 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
|
87 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
|
88 { |
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 NodeList list = (NodeList) XMLUtils.xpath( |
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 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
|
91 XPATH_DISTANCES, |
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 XPathConstants.NODESET, |
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 ArtifactNamespaceContext.INSTANCE); |
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 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 if (list == null || list.getLength() == 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
|
96 System.err.println("No distance info 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
|
97 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 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
|
99 } |
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 int num = list.getLength(); |
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 System.out.println("Response contains " + num + " 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
|
103 |
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 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
|
105 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
|
106 |
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 for (int i = 0; i < num; i++) { |
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 DistanceInfoObject obj = buildDistanceInfoObject(list.item(i)); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 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
|
111 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
|
112 } |
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 } |
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 System.out.println("Retrieved " + objects.size() + " distances."); |
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 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 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
|
118 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
|
119 } |
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 |
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 * 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
|
124 * 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
|
125 * |
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 * @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
|
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 * @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
|
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 protected DistanceInfoObject buildDistanceInfoObject(Node node) { |
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 String desc = XMLUtils.xpathString( |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 node, "@art:description", ArtifactNamespaceContext.INSTANCE); |
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 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 String from = XMLUtils.xpathString( |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 node, "@art:from", ArtifactNamespaceContext.INSTANCE); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 String to = XMLUtils.xpathString( |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 node, "@art:to", ArtifactNamespaceContext.INSTANCE); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 String riverside = XMLUtils.xpathString( |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 node, "@art:riverside", ArtifactNamespaceContext.INSTANCE); |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 if (desc != null && from != 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
|
144 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
|
145 return new 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
|
146 desc, |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 new Double(from), |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 to != null && to.trim().length() > 0 ? new Double(to) : 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
|
149 riverside); |
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 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 catch (NumberFormatException nfe) { |
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 System.err.println(nfe.getLocalizedMessage()); |
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 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
155 |
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 System.err.println("Invalid distance info object 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
|
157 |
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 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
|
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 } |
7523faf567e5
Implemented a service to fetch distance information of a river from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |