Statistics
| Revision:

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 @ 1360

History | View | Annotate | Download (8.72 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
import org.gvsig.i18n.Messages;
52

    
53
/**
54
 * Explorer for a WMS server
55
 * @author Nacho Brodin (nachobrodin@gmail.com)
56
 */
57
public class WMSServerExplorer implements DataServerExplorer, DataServerExplorerProvider {
58
        public static final String          NAME                     = "WMSRemoteServerExplorer";
59
        private WMSConnector                connector                = null;
60
        private WMSServerExplorerParameters parameters               = null;
61
        
62
        public WMSServerExplorer(
63
                        WMSServerExplorerParameters parameters,
64
                        DataServerExplorerProviderServices services)
65
                        throws InitializeException {
66
                this.parameters = parameters;
67
        }
68
        
69
        /**
70
         * Gets the provider's name
71
         * @return
72
         */
73
        public String getDataStoreProviderName() {
74
                return WMSProvider.NAME;
75
        }
76
        
77
        /*
78
         * (non-Javadoc)
79
         * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteServerExplorerProvider#getDescription()
80
         */
81
        public String getDescription() {
82
                return WMSProvider.DESCRIPTION;
83
        }
84
        
85
        /*
86
         * (non-Javadoc)
87
         * @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getParameters(java.lang.String, int)
88
         */
89
        public DataStoreParameters getStoreParameters() {
90
                DataManager manager = DALLocator.getDataManager();
91
                WMSDataParameters params = null;
92
                try {
93
                        params = (WMSDataParameters) manager.createStoreParameters(this.getDataStoreProviderName());
94
                        params.setURI(parameters.getHost());
95
                        
96
                        /*if(WMSProvider.TILED) {
97
                                TileDataParameters tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
98
                                tileParams.setDataParameters(params);
99
                                return tileParams;
100
                        } */
101
                } catch (InitializeException e) {
102
                        e.printStackTrace();
103
                } catch (ProviderNotRegisteredException e) {
104
                        e.printStackTrace();
105
                }
106
                
107
                return params;
108
        }
109

    
110
        public boolean add(String provider, NewDataStoreParameters parameters,
111
                        boolean overwrite) throws DataException {
112
                return false;
113
        }
114

    
115
        public boolean canAdd() {
116
                return false;
117
        }
118

    
119
        public boolean canAdd(String storeName) throws DataException {
120
                return false;
121
        }
122

    
123
        public NewDataStoreParameters getAddParameters(String storeName)
124
                        throws DataException {
125
                return null;
126
        }
127

    
128
        @SuppressWarnings("unchecked")
129
        public List getDataStoreProviderNames() {
130
                return null;
131
        }
132

    
133

    
134
        /*
135
         * (non-Javadoc)
136
         * @see org.gvsig.fmap.dal.DataServerExplorer#getParameters()
137
         */
138
        public DataServerExplorerParameters getParameters() {
139
                return parameters;
140
        }
141

    
142
        @SuppressWarnings("unchecked")
143
        public List list() throws DataException {
144
                return null;
145
        }
146

    
147
        @SuppressWarnings("unchecked")
148
        public List list(int mode) throws DataException {
149
                return null;
150
        }
151

    
152
        public void remove(DataStoreParameters parameters) throws DataException {
153
                
154
        }
155

    
156
        public void dispose() {
157
                
158
        }
159

    
160
        public String getProviderName() {
161
                return null;
162
        }
163
        
164
        //**********************************************
165
        //Connector
166
        //**********************************************
167

    
168
        /**
169
         * Connects to the server and throws a getCapabilities. This loads 
170
         * the basic information to make requests.
171
         * @throws RemoteServiceException 
172
         */
173
        public void connect(ICancellable cancellable, boolean updateCache) throws RemoteServiceException {
174
                URL url = null;
175
                
176
                try {
177
                        url = new URL(parameters.getHost());
178
                } catch (Exception e) {
179
                        throw new RemoteServiceException(Messages.getText("malformed_url"), e);
180
                }
181
        try {
182
                connector = WMSProvider.getConnectorFromURL(url, updateCache);
183
                if (!connector.connect(updateCache, cancellable))
184
                        throw new RemoteServiceException(Messages.getText("error_connecting"));
185
        } catch (IOException e) {
186
                        throw new RemoteServiceException(Messages.getText("error_connecting"), e);
187
                }
188
                
189
        }
190

    
191
        /**
192
         * Returns true if this provider is connected to the server
193
         * @return
194
         */
195
        public boolean isConnected() {
196
                if(connector != null)
197
                        return true;
198
                return false;
199
        }
200

    
201
        /**
202
         * Gets the description of this service
203
         * @return
204
         */
205
        public String getAbstract() {
206
                if(connector != null)
207
                        return connector.getAbstract();
208
                return null;
209
        }
210

    
211
        /**
212
         * Gets the list of raster formats supported by the server
213
         * @return
214
         */
215
        @SuppressWarnings("unchecked")
216
        public String[] getFormats() {
217
                if(connector != null) {
218
                        Vector f = connector.getFormats();
219
                        ArrayList formatos = new ArrayList();
220
                        for (int i = 0; i < f.size(); i++) {
221
                                formatos.add(f.elementAt(i));
222
                        }
223
                        return (String[]) formatos.toArray(new String[0]);
224
                }
225
                return null;
226
        }
227
        
228
        /**
229
         * Gets the list of raster information formats supported by the server
230
         * @return
231
         */
232
        @SuppressWarnings("unchecked")
233
        public String[] getInfoFormats() {
234
                if(connector != null) {
235
                        Vector f = connector.getInfoFormats();
236
                        ArrayList formatos = new ArrayList();
237
                        for (int i = 0; i < f.size(); i++) {
238
                                formatos.add(f.elementAt(i));
239
                        }
240
                        return (String[]) formatos.toArray(new String[0]);
241
                }
242
                return null;
243
        }
244

    
245
        /**
246
         * Gets a tree of nodes which represents the server information
247
         * @return
248
         */
249
        public WMSLayerNode getLayerTree() {
250
                if(connector != null) {
251
                        return connector.getLayersTree();
252
                }
253
                return null;
254
        }
255

    
256
        /**
257
         * Gets the server title
258
         * @return
259
         */
260
        public String getServerType() {
261
                if (getVersion() == null) 
262
                        return "WMS";
263
        return "WMS "+ getVersion();
264
        }
265
        
266
        /**
267
         * Gets the online resources
268
         * @return
269
         */
270
        @SuppressWarnings("unchecked")
271
        public Hashtable getOnlineResources() {
272
                if(connector != null) {
273
                        return connector.getOnlineResources();
274
                }
275
                return null;
276
        }
277

    
278
        /**
279
         * Gets the protocol supported by the server
280
         * @return
281
         */
282
        public String getVersion() {
283
                if(connector != null) {
284
                        return (connector.getVersion() == null) ? "" : connector.getVersion();
285
                }
286
                return null;
287
        }
288
        
289
        /*
290
         * (non-Javadoc)
291
         * @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getLayersExtent(java.lang.String[], java.lang.String)
292
         */
293
    public Rectangle2D getLayersExtent(String[] layerName, String srs) {
294
            return connector.getLayersExtent(layerName, srs);
295
    }
296
    
297
    /**
298
         * Gets a layer using its name
299
         * @param layerName
300
         * @return
301
         */
302
    public WMSLayerNode getLayer(String layerName) {
303
            return connector.getLayer(layerName);
304
    }
305

    
306
    /**
307
         * Gets the host URI
308
         * @return
309
         */
310
        public String getHost() {
311
                return parameters.getHost();
312
        }
313
        
314
        /*
315
         * (non-Javadoc)
316
         * @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#getBoundingBox(java.lang.String[], java.lang.String)
317
         */
318
        public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
319
                return connector.getLayersExtent(layerNames, srs);
320
    }
321
        
322
        /*
323
         * (non-Javadoc)
324
         * @see org.gvsig.fmap.dal.coverage.explorer.WMSServerExplorer#isQueryable()
325
         */
326
        public boolean isQueryable() {
327
            return connector.isQueryable();
328
    }
329
        
330
        /**
331
         * Gets the title
332
         * @return
333
         */
334
        public String getTitle() {
335
                return null;
336
        }
337
        
338
    /**
339
     * @return The title of the service offered by the WMS server.
340
     */
341
    public String getServiceTitle() {
342
                return connector.getServiceTitle();
343
    }
344

    
345
        public DataServerExplorerProviderServices getServerExplorerProviderServices() {
346
                // TODO Auto-generated method stub
347
                return null;
348
        }
349

    
350
}