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 @ 483
History | View | Annotate | Download (8.13 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.net.URL; |
33 |
import java.util.ArrayList; |
34 |
import java.util.Hashtable; |
35 |
import java.util.List; |
36 |
import java.util.Vector; |
37 |
|
38 |
import org.gvsig.compat.net.ICancellable; |
39 |
import org.gvsig.fmap.dal.DALLocator; |
40 |
import org.gvsig.fmap.dal.DataManager; |
41 |
import org.gvsig.fmap.dal.DataServerExplorer; |
42 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
43 |
import org.gvsig.fmap.dal.DataStoreParameters; |
44 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
45 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
46 |
import org.gvsig.fmap.dal.exception.DataException; |
47 |
import org.gvsig.fmap.dal.exception.InitializeException; |
48 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
49 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
50 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
51 |
|
52 |
/**
|
53 |
* Explorer for a WMS server
|
54 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
55 |
*/
|
56 |
public class WMSServerExplorer implements DataServerExplorer, DataServerExplorerProvider { |
57 |
public static final String NAME = "WMSRemoteServerExplorer"; |
58 |
private WMSConnector connector = null; |
59 |
private WMSServerExplorerParameters parameters = null; |
60 |
|
61 |
public WMSServerExplorer(
|
62 |
WMSServerExplorerParameters parameters, |
63 |
DataServerExplorerProviderServices services) |
64 |
throws InitializeException {
|
65 |
this.parameters = parameters;
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* Gets the provider's name
|
70 |
* @return
|
71 |
*/
|
72 |
public String getDataStoreProviderName() { |
73 |
return WMSProvider.NAME;
|
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
* @see org.gvsig.fmap.dal.coverage.store.remote.RemoteServerExplorerProvider#getDescription()
|
79 |
*/
|
80 |
public String getDescription() { |
81 |
return WMSProvider.DESCRIPTION;
|
82 |
} |
83 |
|
84 |
/*
|
85 |
* (non-Javadoc)
|
86 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getParameters(java.lang.String, int)
|
87 |
*/
|
88 |
public DataStoreParameters getStoreParameters() {
|
89 |
/*WMSDataParametersImpl params = new WMSDataParametersImpl();
|
90 |
params.setHost(parameters.getHost());
|
91 |
return params;*/
|
92 |
|
93 |
DataManager manager = DALLocator.getDataManager(); |
94 |
WMSDataParameters params = null;
|
95 |
try {
|
96 |
params = (WMSDataParameters) manager |
97 |
.createStoreParameters(this.getDataStoreProviderName());
|
98 |
} catch (InitializeException e) {
|
99 |
e.printStackTrace(); |
100 |
} catch (ProviderNotRegisteredException e) {
|
101 |
e.printStackTrace(); |
102 |
} |
103 |
params.setURI(parameters.getHost()); |
104 |
return params;
|
105 |
} |
106 |
|
107 |
public boolean add(String provider, NewDataStoreParameters parameters, |
108 |
boolean overwrite) throws DataException { |
109 |
return false; |
110 |
} |
111 |
|
112 |
public boolean canAdd() { |
113 |
return false; |
114 |
} |
115 |
|
116 |
public boolean canAdd(String storeName) throws DataException { |
117 |
return false; |
118 |
} |
119 |
|
120 |
public NewDataStoreParameters getAddParameters(String storeName) |
121 |
throws DataException {
|
122 |
return null; |
123 |
} |
124 |
|
125 |
@SuppressWarnings("unchecked") |
126 |
public List getDataStoreProviderNames() { |
127 |
return null; |
128 |
} |
129 |
|
130 |
|
131 |
/*
|
132 |
* (non-Javadoc)
|
133 |
* @see org.gvsig.fmap.dal.DataServerExplorer#getParameters()
|
134 |
*/
|
135 |
public DataServerExplorerParameters getParameters() {
|
136 |
return parameters;
|
137 |
} |
138 |
|
139 |
@SuppressWarnings("unchecked") |
140 |
public List list() throws DataException { |
141 |
return null; |
142 |
} |
143 |
|
144 |
@SuppressWarnings("unchecked") |
145 |
public List list(int mode) throws DataException { |
146 |
return null; |
147 |
} |
148 |
|
149 |
public void remove(DataStoreParameters parameters) throws DataException { |
150 |
|
151 |
} |
152 |
|
153 |
public void dispose() { |
154 |
|
155 |
} |
156 |
|
157 |
public String getProviderName() { |
158 |
return null; |
159 |
} |
160 |
|
161 |
//**********************************************
|
162 |
//Connector
|
163 |
//**********************************************
|
164 |
|
165 |
/**
|
166 |
* Connects to the server and throws a getCapabilities. This loads
|
167 |
* the basic information to make requests.
|
168 |
* @throws RemoteServiceException
|
169 |
*/
|
170 |
public void connect(ICancellable cancellable) throws RemoteServiceException { |
171 |
URL url = null; |
172 |
boolean override = false; |
173 |
|
174 |
try {
|
175 |
url = new URL(parameters.getHost()); |
176 |
} catch (Exception e) { |
177 |
throw new RemoteServiceException("Malformed URL",e); |
178 |
} |
179 |
try {
|
180 |
connector = WMSProvider.getConnectorFromURL(url); |
181 |
if (!connector.connect(override, cancellable))
|
182 |
throw new RemoteServiceException("Error connecting"); |
183 |
} catch (IOException e) { |
184 |
throw new RemoteServiceException("Error connecting",e); |
185 |
} |
186 |
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* Returns true if this provider is connected to the server
|
191 |
* @return
|
192 |
*/
|
193 |
public boolean isConnected() { |
194 |
if(connector != null) |
195 |
return true; |
196 |
return false; |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Gets the description of this service
|
201 |
* @return
|
202 |
*/
|
203 |
public String getAbstract() { |
204 |
if(connector != null) |
205 |
return connector.getAbstract();
|
206 |
return null; |
207 |
} |
208 |
|
209 |
/**
|
210 |
* Gets the list of raster formats supported by the server
|
211 |
* @return
|
212 |
*/
|
213 |
@SuppressWarnings("unchecked") |
214 |
public String[] getFormats() { |
215 |
if(connector != null) { |
216 |
Vector f = connector.getFormats();
|
217 |
ArrayList formatos = new ArrayList(); |
218 |
for (int i = 0; i < f.size(); i++) { |
219 |
formatos.add(f.elementAt(i)); |
220 |
} |
221 |
return (String[]) formatos.toArray(new String[0]); |
222 |
} |
223 |
return null; |
224 |
} |
225 |
|
226 |
/**
|
227 |
* Gets a tree of nodes which represents the server information
|
228 |
* @return
|
229 |
*/
|
230 |
public WMSLayerNode getLayerTree() {
|
231 |
if(connector != null) { |
232 |
return connector.getLayersTree();
|
233 |
} |
234 |
return null; |
235 |
} |
236 |
|
237 |
/**
|
238 |
* Gets the server title
|
239 |
* @return
|
240 |
*/
|
241 |
public String getServerType() { |
242 |
if (getVersion() == null) |
243 |
return "WMS"; |
244 |
return "WMS "+ getVersion(); |
245 |
} |
246 |
|
247 |
/**
|
248 |
* Gets the online resources
|
249 |
* @return
|
250 |
*/
|
251 |
@SuppressWarnings("unchecked") |
252 |
public Hashtable getOnlineResources() { |
253 |
if(connector != null) { |
254 |
return connector.getOnlineResources();
|
255 |
} |
256 |
return null; |
257 |
} |
258 |
|
259 |
/**
|
260 |
* Gets the protocol supported by the server
|
261 |
* @return
|
262 |
*/
|
263 |
public String getVersion() { |
264 |
if(connector != null) { |
265 |
return (connector.getVersion() == null) ? "" : connector.getVersion(); |
266 |
} |
267 |
return null; |
268 |
} |
269 |
|
270 |
/*
|
271 |
* (non-Javadoc)
|
272 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getLayersExtent(java.lang.String[], java.lang.String)
|
273 |
*/
|
274 |
public Rectangle2D getLayersExtent(String[] layerName, String srs) { |
275 |
return connector.getLayersExtent(layerName, srs);
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* Gets a layer using its name
|
280 |
* @param layerName
|
281 |
* @return
|
282 |
*/
|
283 |
public WMSLayerNode getLayer(String layerName) { |
284 |
return connector.getLayer(layerName);
|
285 |
} |
286 |
|
287 |
/**
|
288 |
* Gets the host URI
|
289 |
* @return
|
290 |
*/
|
291 |
public String getHost() { |
292 |
return parameters.getHost();
|
293 |
} |
294 |
|
295 |
/*
|
296 |
* (non-Javadoc)
|
297 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getBoundingBox(java.lang.String[], java.lang.String)
|
298 |
*/
|
299 |
public Rectangle2D getBoundingBox(String[] layerNames, String srs) { |
300 |
return connector.getLayersExtent(layerNames, srs);
|
301 |
} |
302 |
|
303 |
/*
|
304 |
* (non-Javadoc)
|
305 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#isQueryable()
|
306 |
*/
|
307 |
public boolean isQueryable() { |
308 |
return connector.isQueryable();
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* Gets the title
|
313 |
* @return
|
314 |
*/
|
315 |
public String getTitle() { |
316 |
return null; |
317 |
} |
318 |
|
319 |
/**
|
320 |
* @return The title of the service offered by the WMS server.
|
321 |
*/
|
322 |
public String getServiceTitle() { |
323 |
return connector.getServiceTitle();
|
324 |
} |
325 |
|
326 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() {
|
327 |
// TODO Auto-generated method stub
|
328 |
return null; |
329 |
} |
330 |
|
331 |
} |