gvsig-raster / org.gvsig.raster.wms / branches / org.gvsig.raster.wms_dataaccess_refactoring / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / WMSServerExplorer.java @ 2317
History | View | Annotate | Download (8.89 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.raster.wms.io; |
29 |
|
30 |
import java.awt.geom.Rectangle2D; |
31 |
import java.io.IOException; |
32 |
import java.io.InputStream; |
33 |
import java.net.MalformedURLException; |
34 |
import java.net.URL; |
35 |
import java.net.URLConnection; |
36 |
import java.util.ArrayList; |
37 |
import java.util.Hashtable; |
38 |
import java.util.List; |
39 |
import java.util.Vector; |
40 |
|
41 |
import org.gvsig.compat.net.ICancellable; |
42 |
import org.gvsig.fmap.dal.DALLocator; |
43 |
import org.gvsig.fmap.dal.DataManager; |
44 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
45 |
import org.gvsig.fmap.dal.DataStoreParameters; |
46 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
47 |
import org.gvsig.fmap.dal.coverage.exception.ConnectException; |
48 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
49 |
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer; |
50 |
import org.gvsig.fmap.dal.exception.DataException; |
51 |
import org.gvsig.fmap.dal.exception.InitializeException; |
52 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
53 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
54 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
55 |
import org.gvsig.i18n.Messages; |
56 |
|
57 |
/**
|
58 |
* Explorer for a WMS server
|
59 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
60 |
*/
|
61 |
public class WMSServerExplorer implements RasterDataServerExplorer, DataServerExplorerProvider { |
62 |
public static final String NAME = WMSProvider.NAME; |
63 |
private WMSConnector connector = null; |
64 |
private WMSServerExplorerParameters parameters = null; |
65 |
|
66 |
public WMSServerExplorer(
|
67 |
WMSServerExplorerParameters parameters, |
68 |
DataServerExplorerProviderServices services) |
69 |
throws InitializeException {
|
70 |
this.parameters = parameters;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Gets the provider's name
|
75 |
* @return
|
76 |
*/
|
77 |
public String getDataStoreProviderName() { |
78 |
return WMSProvider.NAME;
|
79 |
} |
80 |
|
81 |
public String getDescription() { |
82 |
return WMSProvider.DESCRIPTION;
|
83 |
} |
84 |
|
85 |
public boolean add(String provider, NewDataStoreParameters parameters, |
86 |
boolean overwrite) throws DataException { |
87 |
return false; |
88 |
} |
89 |
|
90 |
public boolean canAdd() { |
91 |
return false; |
92 |
} |
93 |
|
94 |
public boolean canAdd(String storeName) throws DataException { |
95 |
return false; |
96 |
} |
97 |
|
98 |
public NewDataStoreParameters getAddParameters(String storeName) |
99 |
throws DataException {
|
100 |
return null; |
101 |
} |
102 |
|
103 |
public List<?> getDataStoreProviderNames() { |
104 |
return null; |
105 |
} |
106 |
|
107 |
public DataServerExplorerParameters getParameters() {
|
108 |
return parameters;
|
109 |
} |
110 |
|
111 |
public List<?> list() throws DataException { |
112 |
return null; |
113 |
} |
114 |
|
115 |
public List<?> list(int mode) throws DataException { |
116 |
return null; |
117 |
} |
118 |
|
119 |
public void remove(DataStoreParameters parameters) throws DataException { |
120 |
|
121 |
} |
122 |
|
123 |
public void dispose() { |
124 |
|
125 |
} |
126 |
|
127 |
public String getProviderName() { |
128 |
return null; |
129 |
} |
130 |
|
131 |
//**********************************************
|
132 |
//Connector
|
133 |
//**********************************************
|
134 |
|
135 |
public DataStoreParameters getStoredParameters() {
|
136 |
DataManager manager = DALLocator.getDataManager(); |
137 |
WMSDataParameters params = null;
|
138 |
try {
|
139 |
params = (WMSDataParameters) manager.createStoreParameters(this.getDataStoreProviderName());
|
140 |
params.setURI(parameters.getHost()); |
141 |
|
142 |
/*if(WMSProvider.TILED) {
|
143 |
TileDataParameters tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
|
144 |
tileParams.setDataParameters(params);
|
145 |
return tileParams;
|
146 |
} */
|
147 |
} catch (InitializeException e) {
|
148 |
e.printStackTrace(); |
149 |
} catch (ProviderNotRegisteredException e) {
|
150 |
e.printStackTrace(); |
151 |
} |
152 |
|
153 |
return params;
|
154 |
} |
155 |
|
156 |
public void connect(ICancellable cancellable) throws ConnectException { |
157 |
connect(cancellable, false);
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* Connects to the server and throws a getCapabilities. This loads
|
162 |
* the basic information to make requests.
|
163 |
* @throws RemoteServiceException
|
164 |
*/
|
165 |
public void connect(ICancellable cancellable, boolean updateCache) throws ConnectException { |
166 |
URL url = null; |
167 |
|
168 |
try {
|
169 |
url = new URL(parameters.getHost()); |
170 |
} catch (Exception e) { |
171 |
throw new ConnectException(Messages.getText("malformed_url"), e); |
172 |
} |
173 |
try {
|
174 |
connector = WMSProvider.getConnectorFromURL(url, updateCache); |
175 |
if (!connector.connect(updateCache, cancellable))
|
176 |
throw new ConnectException(Messages.getText("error_connecting")); |
177 |
} catch (IOException e) { |
178 |
throw new ConnectException(Messages.getText("error_connecting"), e); |
179 |
} |
180 |
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Checks if the network and host are reachable
|
185 |
* @param timeout for the host
|
186 |
* @return true if both are reachable and false if they are not
|
187 |
*/
|
188 |
public boolean isHostReachable(int timeout) { |
189 |
URL url = null; |
190 |
try {
|
191 |
url = new URL(parameters.getHost()); |
192 |
URLConnection con = url.openConnection();
|
193 |
if(con == null) |
194 |
return false; |
195 |
con.connect(); |
196 |
InputStream stream = con.getInputStream();
|
197 |
if(stream == null) |
198 |
return false; |
199 |
} catch (MalformedURLException e) { |
200 |
return false; |
201 |
} catch (IOException e) { |
202 |
return false; |
203 |
} |
204 |
|
205 |
return true; |
206 |
} |
207 |
|
208 |
/**
|
209 |
* Checks if the network and host are reachable
|
210 |
* @return true if both are reachable and false if they are not
|
211 |
*/
|
212 |
public boolean isHostReachable() { |
213 |
int timeout = 10000; |
214 |
return isHostReachable(timeout);
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Returns true if this provider is connected to the server
|
219 |
* @return
|
220 |
*/
|
221 |
public boolean isConnected() { |
222 |
if(connector != null) |
223 |
return true; |
224 |
return false; |
225 |
} |
226 |
|
227 |
/**
|
228 |
* Gets the description of this service
|
229 |
* @return
|
230 |
*/
|
231 |
public String getAbstract() { |
232 |
if(connector != null) |
233 |
return connector.getAbstract();
|
234 |
return null; |
235 |
} |
236 |
|
237 |
/**
|
238 |
* Gets the list of raster formats supported by the server
|
239 |
* @return
|
240 |
*/
|
241 |
@SuppressWarnings("unchecked") |
242 |
public String[] getFormats() { |
243 |
if(connector != null) { |
244 |
Vector f = connector.getFormats();
|
245 |
ArrayList formatos = new ArrayList(); |
246 |
for (int i = 0; i < f.size(); i++) { |
247 |
formatos.add(f.elementAt(i)); |
248 |
} |
249 |
return (String[]) formatos.toArray(new String[0]); |
250 |
} |
251 |
return null; |
252 |
} |
253 |
|
254 |
/**
|
255 |
* Gets the list of raster information formats supported by the server
|
256 |
* @return
|
257 |
*/
|
258 |
@SuppressWarnings("unchecked") |
259 |
public String[] getInfoFormats() { |
260 |
if(connector != null) { |
261 |
Vector f = connector.getInfoFormats();
|
262 |
ArrayList formatos = new ArrayList(); |
263 |
for (int i = 0; i < f.size(); i++) { |
264 |
formatos.add(f.elementAt(i)); |
265 |
} |
266 |
return (String[]) formatos.toArray(new String[0]); |
267 |
} |
268 |
return null; |
269 |
} |
270 |
|
271 |
/**
|
272 |
* Gets a tree of nodes which represents the server information
|
273 |
* @return
|
274 |
*/
|
275 |
public WMSLayerNode getLayerTree() {
|
276 |
if(connector != null) { |
277 |
return connector.getLayersTree();
|
278 |
} |
279 |
return null; |
280 |
} |
281 |
|
282 |
/**
|
283 |
* Gets the server title
|
284 |
* @return
|
285 |
*/
|
286 |
public String getServerType() { |
287 |
if (getVersion() == null) |
288 |
return "WMS"; |
289 |
return "WMS "+ getVersion(); |
290 |
} |
291 |
|
292 |
/**
|
293 |
* Gets the online resources
|
294 |
* @return
|
295 |
*/
|
296 |
public Hashtable getOnlineResources() { |
297 |
if(connector != null) { |
298 |
return connector.getOnlineResources();
|
299 |
} |
300 |
return null; |
301 |
} |
302 |
|
303 |
/**
|
304 |
* Gets the protocol supported by the server
|
305 |
* @return
|
306 |
*/
|
307 |
public String getVersion() { |
308 |
if(connector != null) { |
309 |
return (connector.getVersion() == null) ? "" : connector.getVersion(); |
310 |
} |
311 |
return null; |
312 |
} |
313 |
|
314 |
public Rectangle2D getLayersExtent(String[] layerName, String srs) { |
315 |
return connector.getLayersExtent(layerName, srs);
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* Gets a layer using its name
|
320 |
* @param layerName
|
321 |
* @return
|
322 |
*/
|
323 |
public WMSLayerNode getLayer(String layerName) { |
324 |
return connector.getLayer(layerName);
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* Gets the host URI
|
329 |
* @return
|
330 |
*/
|
331 |
public String getHost() { |
332 |
return parameters.getHost();
|
333 |
} |
334 |
|
335 |
public Rectangle2D getBoundingBox(String[] layerNames, String srs) { |
336 |
return connector.getLayersExtent(layerNames, srs);
|
337 |
} |
338 |
|
339 |
public boolean isQueryable() { |
340 |
return connector.isQueryable();
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* Gets the title
|
345 |
* @return
|
346 |
*/
|
347 |
public String getTitle() { |
348 |
return null; |
349 |
} |
350 |
|
351 |
/**
|
352 |
* @return The title of the service offered by the WMS server.
|
353 |
*/
|
354 |
public String getServiceTitle() { |
355 |
return connector.getServiceTitle();
|
356 |
} |
357 |
|
358 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() {
|
359 |
return null; |
360 |
} |
361 |
} |