svn-gvsig-desktop / tags / v1_0_2_Build_900 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / GazetteerClient.java @ 10562
History | View | Annotate | Download (7.15 KB)
1 | 3566 | jorpiell | |
---|---|---|---|
2 | 2921 | jorpiell | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 | *
|
||
4 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * Generalitat Valenciana
|
||
23 | * Conselleria d'Infraestructures i Transport
|
||
24 | * Av. Blasco Ib??ez, 50
|
||
25 | * 46010 VALENCIA
|
||
26 | * SPAIN
|
||
27 | *
|
||
28 | * +34 963862235
|
||
29 | * gvsig@gva.es
|
||
30 | * www.gvsig.gva.es
|
||
31 | *
|
||
32 | * or
|
||
33 | *
|
||
34 | * IVER T.I. S.A
|
||
35 | * Salamanca 50
|
||
36 | * 46005 Valencia
|
||
37 | * Spain
|
||
38 | *
|
||
39 | * +34 963163400
|
||
40 | * dac@iver.es
|
||
41 | */
|
||
42 | package es.gva.cit.gazetteer; |
||
43 | import java.io.IOException; |
||
44 | import java.net.MalformedURLException; |
||
45 | import java.net.Socket; |
||
46 | import java.net.URL; |
||
47 | import java.net.UnknownHostException; |
||
48 | 3566 | jorpiell | import java.util.Collection; |
49 | 2921 | jorpiell | |
50 | 4302 | jorpiell | import com.iver.utiles.swing.jcomboServer.ServerData; |
51 | 3664 | jorpiell | import es.gva.cit.gazetteer.adl.drivers.ADLGazetteerServiceDriver; |
52 | import es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver; |
||
53 | import es.gva.cit.gazetteer.idec.drivers.IDECGazetteerServiceDriver; |
||
54 | import es.gva.cit.gazetteer.querys.Query; |
||
55 | import es.gva.cit.gazetteer.wfsg.drivers.WFSGazetteerServiceDriver; |
||
56 | |||
57 | 2921 | jorpiell | /**
|
58 | * This class represents a gazetteer client. It must be created to
|
||
59 | * use the gazetteer service
|
||
60 | *
|
||
61 | 3566 | jorpiell | *
|
62 | 2921 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
63 | */
|
||
64 | public class GazetteerClient { |
||
65 | 3566 | jorpiell | |
66 | /**
|
||
67 | *
|
||
68 | *
|
||
69 | */
|
||
70 | 2921 | jorpiell | private URL url = null; |
71 | 3566 | jorpiell | |
72 | /**
|
||
73 | *
|
||
74 | *
|
||
75 | */
|
||
76 | 3227 | jorpiell | private String sURL = null; |
77 | 3566 | jorpiell | |
78 | /**
|
||
79 | *
|
||
80 | *
|
||
81 | */
|
||
82 | 2921 | jorpiell | private String protocol = null; |
83 | 3566 | jorpiell | /**
|
84 | *
|
||
85 | *
|
||
86 | */
|
||
87 | 2921 | jorpiell | private IGazetteerServiceDriver lnkIGazetteerDriver;
|
88 | |||
89 | 3566 | jorpiell | /**
|
90 | *
|
||
91 | *
|
||
92 | */
|
||
93 | private String serverStatus = null; |
||
94 | |||
95 | /**
|
||
96 | *
|
||
97 | *
|
||
98 | *
|
||
99 | * @param url
|
||
100 | * @param protocol
|
||
101 | */
|
||
102 | public GazetteerClient(String url, String protocol) { |
||
103 | 8765 | jjdelcerro | if (!(url.regionMatches(0, "http://", 0, 7))) { |
104 | url = "http://" + url;
|
||
105 | } |
||
106 | |||
107 | setProtocol(protocol); |
||
108 | 3227 | jorpiell | setSURL(url); |
109 | |||
110 | 2921 | jorpiell | try {
|
111 | setUrl(new URL(url)); |
||
112 | |||
113 | |||
114 | if (getUrl().getPort() == -1) { |
||
115 | setUrl(new URL("http", getUrl().getHost(), 80, getUrl().getFile())); |
||
116 | } else {
|
||
117 | setUrl(new URL("http", getUrl().getHost(), getUrl().getPort(),getUrl().getFile())); |
||
118 | } |
||
119 | |||
120 | |||
121 | |||
122 | } catch (MalformedURLException e) { |
||
123 | // TODO Auto-generated catch block
|
||
124 | e.printStackTrace(); |
||
125 | } |
||
126 | |||
127 | //Casting to the respective driver
|
||
128 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_WFSG)) || |
129 | protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_WFS))) { |
||
130 | 2921 | jorpiell | lnkIGazetteerDriver = new WFSGazetteerServiceDriver();
|
131 | } |
||
132 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_ADL))) { |
133 | 2921 | jorpiell | lnkIGazetteerDriver = new ADLGazetteerServiceDriver();
|
134 | } |
||
135 | 3069 | jorpiell | |
136 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_GAZETTEER_IDEC))) { |
137 | 3069 | jorpiell | lnkIGazetteerDriver = new IDECGazetteerServiceDriver();
|
138 | } |
||
139 | |||
140 | |||
141 | 3566 | jorpiell | } |
142 | 2921 | jorpiell | |
143 | 3566 | jorpiell | /**
|
144 | *
|
||
145 | *
|
||
146 | *
|
||
147 | * @return
|
||
148 | */
|
||
149 | public boolean getCapabilities() { |
||
150 | if (!serverReady()) {
|
||
151 | serverStatus = ("errorServerNotFound");
|
||
152 | } else if (!getLnkIGazetteerDriver().isProtocolSupported(getUrl())) { |
||
153 | serverStatus = "errorNotSupportedProtocol";
|
||
154 | } else {
|
||
155 | //getCapabilities
|
||
156 | Collection nodesCapabilities = getLnkIGazetteerDriver()
|
||
157 | .getCapabilities(getUrl()); |
||
158 | if (nodesCapabilities == null) { |
||
159 | serverStatus = "errorNotSupportedCapabilities";
|
||
160 | } else {
|
||
161 | //Configure the client
|
||
162 | if (!getLnkIGazetteerDriver().setParameters(nodesCapabilities)) {
|
||
163 | if (!(getLnkIGazetteerDriver()
|
||
164 | .getServerAnswerReady().equals(""))) {
|
||
165 | serverStatus = getLnkIGazetteerDriver().getServerAnswerReady(); |
||
166 | } else {
|
||
167 | serverStatus = "errorNotParsedReply";
|
||
168 | } |
||
169 | } else {
|
||
170 | serverStatus = getLnkIGazetteerDriver().getServerAnswerReady(); |
||
171 | return true; |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | |||
176 | return false; |
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | 3613 | jorpiell | * This method implements the getFeature operation
|
181 | 3566 | jorpiell | *
|
182 | *
|
||
183 | 3613 | jorpiell | * @return
|
184 | * @param url
|
||
185 | * @param query
|
||
186 | */
|
||
187 | public Collection getFeature(URL url, Query query) { |
||
188 | return lnkIGazetteerDriver.getFeature(url, query);
|
||
189 | } |
||
190 | |||
191 | /**
|
||
192 | 3566 | jorpiell | *
|
193 | 3613 | jorpiell | *
|
194 | *
|
||
195 | 3566 | jorpiell | * @return Returns the lnkIGazetteerDriver.
|
196 | */
|
||
197 | public IGazetteerServiceDriver getLnkIGazetteerDriver() {
|
||
198 | 2921 | jorpiell | return lnkIGazetteerDriver;
|
199 | 3566 | jorpiell | } |
200 | 2921 | jorpiell | |
201 | 3566 | jorpiell | /**
|
202 | *
|
||
203 | *
|
||
204 | *
|
||
205 | * @param lnkIGazetteerDriver The lnkIGazetteerDriver to set.
|
||
206 | */
|
||
207 | public void setLnkICatalogServerDriver(IGazetteerServiceDriver lnkIGazetteerDriver) { |
||
208 | 2921 | jorpiell | this.lnkIGazetteerDriver = lnkIGazetteerDriver;
|
209 | 3566 | jorpiell | } |
210 | 2921 | jorpiell | |
211 | 3566 | jorpiell | /**
|
212 | * This method is used to create a new Query
|
||
213 | *
|
||
214 | *
|
||
215 | * @return
|
||
216 | */
|
||
217 | public Query createNewQuery() { |
||
218 | return new Query(); |
||
219 | } |
||
220 | |||
221 | /**
|
||
222 | *
|
||
223 | *
|
||
224 | *
|
||
225 | * @return
|
||
226 | */
|
||
227 | public String getProtocol() { |
||
228 | 2921 | jorpiell | return protocol;
|
229 | 3566 | jorpiell | } |
230 | |||
231 | /**
|
||
232 | *
|
||
233 | *
|
||
234 | *
|
||
235 | * @param protocol The protocol to set.
|
||
236 | */
|
||
237 | public void setProtocol(String protocol) { |
||
238 | 2921 | jorpiell | this.protocol = protocol;
|
239 | 3566 | jorpiell | } |
240 | 2921 | jorpiell | |
241 | 3566 | jorpiell | /**
|
242 | *
|
||
243 | *
|
||
244 | *
|
||
245 | * @return Returns the url.
|
||
246 | */
|
||
247 | public URL getUrl() { |
||
248 | 2921 | jorpiell | return url;
|
249 | 3566 | jorpiell | } |
250 | 2921 | jorpiell | |
251 | 3566 | jorpiell | /**
|
252 | *
|
||
253 | *
|
||
254 | *
|
||
255 | * @param url The url to set.
|
||
256 | */
|
||
257 | public void setUrl(URL url) { |
||
258 | 2921 | jorpiell | this.url = url;
|
259 | 3566 | jorpiell | } |
260 | 2921 | jorpiell | |
261 | 3566 | jorpiell | /**
|
262 | * It tries if the server is ready
|
||
263 | *
|
||
264 | *
|
||
265 | * @return boolean
|
||
266 | * true --> server is ready
|
||
267 | * false --> server is not ready
|
||
268 | */
|
||
269 | public boolean serverReady() { |
||
270 | 2921 | jorpiell | try {
|
271 | 3566 | jorpiell | new Socket(this.getUrl().getHost(), |
272 | 2921 | jorpiell | this.getUrl().getPort());
|
273 | } catch (UnknownHostException e) { |
||
274 | // TODO Auto-generated catch block
|
||
275 | return false; |
||
276 | } catch (IOException e) { |
||
277 | // TODO Auto-generated catch block
|
||
278 | return false; |
||
279 | } |
||
280 | 3566 | jorpiell | return true; |
281 | } |
||
282 | 2921 | jorpiell | |
283 | 3566 | jorpiell | /**
|
284 | *
|
||
285 | *
|
||
286 | *
|
||
287 | * @return Returns the sURL.
|
||
288 | */
|
||
289 | public String getSURL() { |
||
290 | 3227 | jorpiell | return sURL;
|
291 | 3566 | jorpiell | } |
292 | |||
293 | /**
|
||
294 | *
|
||
295 | *
|
||
296 | *
|
||
297 | * @param surl The sURL to set.
|
||
298 | */
|
||
299 | public void setSURL(String surl) { |
||
300 | 3227 | jorpiell | sURL = surl; |
301 | 3566 | jorpiell | } |
302 | |||
303 | /**
|
||
304 | *
|
||
305 | *
|
||
306 | *
|
||
307 | * @return Returns the serverStatus.
|
||
308 | */
|
||
309 | public String getServerStatus() { |
||
310 | return serverStatus;
|
||
311 | } |
||
312 | } |