Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.io / src / main / java / org / gvsig / raster / wcs / io / WCSServerExplorer.java @ 1979

History | View | Annotate | Download (7.84 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.wcs.io;
29

    
30
import java.awt.geom.Point2D;
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.net.InetAddress;
34
import java.net.MalformedURLException;
35
import java.net.URL;
36
import java.net.URLConnection;
37
import java.net.UnknownHostException;
38
import java.util.Hashtable;
39
import java.util.List;
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.RemoteServiceException;
48
import org.gvsig.fmap.dal.exception.DataException;
49
import org.gvsig.fmap.dal.exception.InitializeException;
50
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
51
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
52
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
53
import org.gvsig.i18n.Messages;
54

    
55
/**
56
 * Explorer for a WCS server
57
 * @author Nacho Brodin (nachobrodin@gmail.com)
58
 */
59
public class WCSServerExplorer implements DataServerExplorerProvider {
60
        public static final String          NAME                     = "WCSRemoteServerExplorer";
61
        private WCSConnector                connector                = null;
62
        private WCSServerExplorerParameters parameters               = null;
63
        
64
        public WCSServerExplorer(
65
                        WCSServerExplorerParameters parameters,
66
                        DataServerExplorerProviderServices services)
67
                        throws InitializeException {
68
                this.parameters = parameters;
69
        }
70
        
71
        /**
72
         * Gets the provider's name
73
         * @return
74
         */
75
        public String getDataStoreProviderName() {
76
                return WCSProvider.NAME;
77
        }
78
        
79
        /*
80
         * (non-Javadoc)
81
         * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteServerExplorerProvider#getDescription()
82
         */
83
        public String getDescription() {
84
                return WCSProvider.DESCRIPTION;
85
        }
86
        
87
        public DataStoreParameters getStoreParameters() {
88
                DataManager manager = DALLocator.getDataManager();
89
                WCSDataParametersImpl params = null;
90
                try {
91
                        params = (WCSDataParametersImpl) manager.createStoreParameters(this.getDataStoreProviderName());
92

    
93
                        /*if(WCSProvider.TILED) {
94
                                TileDataParameters tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
95
                                tileParams.setDataParameters(params);
96
                                return tileParams;
97
                        } */
98
                        
99
                } catch (InitializeException e) {
100
                        e.printStackTrace();
101
                } catch (ProviderNotRegisteredException e) {
102
                        e.printStackTrace();
103
                }
104
                params.setURI(parameters.getHost());
105
                return params;
106
        }
107

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

    
113
        public boolean canAdd() {
114
                return false;
115
        }
116

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

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

    
126
        public List getDataStoreProviderNames() {
127
                return null;
128
        }
129

    
130
        /*
131
         * (non-Javadoc)
132
         * @see org.gvsig.fmap.dal.DataServerExplorer#getParameters()
133
         */
134
        public DataServerExplorerParameters getParameters() {
135
                return parameters;
136
        }
137

    
138
        public List list() throws DataException {
139
                return null;
140
        }
141

    
142
        public List list(int mode) throws DataException {
143
                return null;
144
        }
145

    
146
        public void remove(DataStoreParameters parameters) throws DataException {
147
                
148
        }
149

    
150
        public void dispose() {
151
                
152
        }
153

    
154
        public String getProviderName() {
155
                return null;
156
        }
157
        
158
        /**
159
         * Gets the online resources
160
         * @return
161
         */
162
        public Hashtable getOnlineResources() {
163
                /*if(connector != null) {
164
                        return connector.getOnlineResources();
165
                }*/
166
                return null;
167
        }
168
        
169
        //**********************************************
170
        //Connector
171
        //**********************************************
172

    
173
        /**
174
         * Connects to the server and throws a getCapabilities. This loads 
175
         * the basic information to make requests.
176
         * @throws RemoteServiceException 
177
         */
178
        public void connect(ICancellable cancellable) throws RemoteServiceException {
179
                URL url = null;
180
                boolean override = false;
181
                
182
                try {
183
                        url = new URL(parameters.getHost());
184
                } catch (Exception e) {
185
                        throw new RemoteServiceException(Messages.getText("malformed_url"), e);
186
                }
187
        try {
188
                connector = WCSProvider.getConnectorFromURL(url);
189
                if (!connector.connect(override, cancellable))
190
                        throw new RemoteServiceException(Messages.getText("error_connecting"));
191
        } catch (IOException e) {
192
                        throw new RemoteServiceException(Messages.getText("error_connecting"), e);
193
                }
194
                
195
        }
196
        
197
        /**
198
         * Checks if the network and host are reachable
199
         * @param timeout for the host
200
         * @return true if both are reachable and false if they are not
201
         */
202
        public boolean isHostReachable(int timeout) {
203
                URL url = null;
204
                try {
205
                        url = new URL(parameters.getHost());
206
                        URLConnection con = url.openConnection();
207
                        if(con == null)
208
                                return false;
209
                        con.connect();
210
                        InputStream stream = con.getInputStream();
211
                        if(stream == null)
212
                                return false;
213
                } catch (MalformedURLException e) {
214
                        return false;
215
                } catch (IOException e) {
216
                        return false;
217
                }
218
                
219
                return true;
220
        }
221

    
222
        /**
223
         * Checks if the network and host are reachable
224
         * @return true if both are reachable and false if they are not
225
         */
226
        public boolean isHostReachable() {
227
                int timeout = 10000;
228
                return isHostReachable(timeout);
229
        }
230

    
231
        /**
232
         * Returns true if this provider is connected to the server
233
         * @return
234
         */
235
        public boolean isConnected() {
236
                if(connector != null)
237
                        return true;
238
                return false;
239
        }
240

    
241
        /**
242
         * Gets the description of this service
243
         * @return
244
         */
245
        public String getAbstract() {
246
                if(connector != null)
247
                        return connector.getDescription();
248
                return null;
249
        }
250

    
251
        /**
252
         * Gets the server title
253
         * @return
254
         */
255
        public String getServerType() {
256
                if (getVersion() == null) 
257
                        return "WCS";
258
        return "WCS "+ getVersion();
259
        }
260

    
261
        /**
262
         * Gets the protocol supported by the server
263
         * @return
264
         */
265
        public String getVersion() {
266
                if(connector != null) {
267
                        return (connector.getVersion() == null) ? "" : connector.getVersion();
268
                }
269
                return null;
270
        }
271

    
272
        /**
273
         * Gets the host URI
274
         * @return
275
         */
276
        public String getHost() {
277
                return parameters.getHost();
278
        }
279
        
280
        /**
281
         * Gets the title
282
         * @return
283
         */
284
        public String getTitle() {
285
                return null;
286
        }
287

    
288
        public DataServerExplorerProviderServices getServerExplorerProviderServices() {
289
                // TODO Auto-generated method stub
290
                return null;
291
        }
292

    
293
        /*
294
         * (non-Javadoc)
295
         * @see org.gvsig.fmap.dal.coverage.explorer.WCSServerExplorer#getMaxResolution(java.lang.String)
296
         */
297
        public Point2D getMaxResolution(String layerName) {
298
                return connector.getMaxResolution(layerName);
299
        }
300

    
301
        /**
302
         * Gets the coverage list
303
         * @return
304
         */
305
        public WCSLayerNode[] getCoverageList() {
306
                return connector.getLayerList();
307
        }
308
        
309
        /**
310
         * Gets a layer searching by its name 
311
         * @return
312
         */
313
        public WCSLayerNode getCoverageByName(String name) {
314
                WCSLayerNode[] list = getCoverageList();
315
                for (int i = 0; i < list.length; i++) {
316
                        if(list[i].getName().compareTo(name) == 0)
317
                                return list[i];
318
                }
319
                return null;
320
        }
321
}