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