comparison flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java @ 29:44c63e7fd0d0

Added a service to list the supported rivers of the artifact server. The FLYS instance serves a method that retrieves this list. flys-client/trunk@1431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 09 Mar 2011 08:00:06 +0000
parents
children 907b61e4d702
comparison
equal deleted inserted replaced
28:dfdb927b137d 29:44c63e7fd0d0
1 package de.intevation.flys.client.server;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.xml.xpath.XPathConstants;
7
8 import org.w3c.dom.Document;
9 import org.w3c.dom.NodeList;
10 import org.w3c.dom.Node;
11
12 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
13
14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
15 import de.intevation.artifacts.common.utils.XMLUtils;
16
17 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
18 import de.intevation.artifacts.httpclient.http.HttpClient;
19 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
20
21 import de.intevation.flys.client.shared.model.DefaultRiver;
22 import de.intevation.flys.client.shared.model.River;
23 import de.intevation.flys.client.client.services.RiverService;
24
25
26 /**
27 * This interface provides a method to list the supported rivers of the artifact
28 * server.
29 *
30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
31 */
32 public class RiverServiceImpl
33 extends RemoteServiceServlet
34 implements RiverService
35 {
36 /** The XPath string that points to the rivers in the resulting document.*/
37 public static final String XPATH_RIVERS = "/art:rivers/art:river";
38
39
40 public River[] list(String serverUrl) {
41 Document doc = XMLUtils.newDocument();
42
43 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
44 doc,
45 ArtifactNamespaceContext.NAMESPACE_URI,
46 ArtifactNamespaceContext.NAMESPACE_PREFIX);
47
48 doc.appendChild(ec.create("action"));
49
50 HttpClient client = new HttpClientImpl(serverUrl);
51
52 try {
53 Document res = client.callService(serverUrl, "rivers", doc);
54
55 NodeList rivers = (NodeList) XMLUtils.xpath(
56 res,
57 XPATH_RIVERS,
58 XPathConstants.NODESET,
59 ArtifactNamespaceContext.INSTANCE);
60
61 int count = rivers.getLength();
62
63 List<River> theRivers = new ArrayList<River>(count);
64
65 for (int i = 0; i < count; i++) {
66 Node tmp = rivers.item(i);
67
68 String name = XMLUtils.xpathString(
69 tmp, "@art:name", ArtifactNamespaceContext.INSTANCE);
70
71 theRivers.add(new DefaultRiver(name));
72 }
73
74 return (River[]) theRivers.toArray(new River[count]);
75 }
76 catch (ConnectionException ce) {
77 System.err.println(ce.getLocalizedMessage());
78 }
79
80 return null;
81 }
82 }
83 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org