Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / fmap / dal / serverexplorer / wfs / WFSServerExplorer.java @ 32880

History | View | Annotate | Download (8.41 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.fmap.dal.serverexplorer.wfs;
29

    
30
import java.io.IOException;
31
import java.net.ConnectException;
32
import java.util.ArrayList;
33
import java.util.Hashtable;
34
import java.util.Iterator;
35
import java.util.List;
36

    
37
import org.gvsig.fmap.dal.DALLocator;
38
import org.gvsig.fmap.dal.DataManager;
39
import org.gvsig.fmap.dal.DataServerExplorerParameters;
40
import org.gvsig.fmap.dal.DataStoreParameters;
41
import org.gvsig.fmap.dal.NewDataStoreParameters;
42
import org.gvsig.fmap.dal.exception.DataException;
43
import org.gvsig.fmap.dal.exception.InitializeException;
44
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
45
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
46
import org.gvsig.fmap.dal.store.wfs.WFSStoreParameters;
47
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider;
48
import org.gvsig.remoteclient.wfs.WFSClient;
49
import org.gvsig.remoteclient.wfs.WFSFeature;
50
import org.gvsig.remoteclient.wfs.WFSStatus;
51
import org.gvsig.remoteclient.wfs.exceptions.WFSException;
52
import org.gvsig.remoteclient.wms.ICancellable;
53
import org.gvsig.tools.dispose.impl.AbstractDisposable;
54
import org.gvsig.tools.exception.BaseException;
55

    
56
/**
57
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
58
 */
59
public class WFSServerExplorer extends AbstractDisposable implements
60
                DataServerExplorerProvider {
61
        public static final String NAME = "WFSServerExplorer";
62
        private WFSServerExplorerParameters parameters = null;
63
        private DataManager dataManager = DALLocator.getDataManager();
64
        private String url = null;
65
        
66
        //WFS Parameters
67
        private WFSStatus status = null;
68
        private WFSClient wfsClient = null;
69

    
70
        /**
71
         * @param parameters
72
         */
73
        public WFSServerExplorer(WFSServerExplorerParameters parameters, DataServerExplorerProviderServices services) throws InitializeException{
74
                super();
75
                this.parameters = parameters;
76
                this.url = parameters.getUrl();
77
                if (wfsClient == null){
78
                        try {
79
                                wfsClient = new WFSClient(url);
80
                                if (status == null){
81
                                        status = new WFSStatus(null);                                        
82
                                }
83
                                wfsClient.getCapabilities(status, false, null);
84
                        } catch (ConnectException e) {
85
                                throw new InitializeException("Not possible to connect with " + url, e);
86
                        } catch (IOException e) {
87
                                throw new InitializeException("Not possible to connect with " + url, e);
88
                        } catch (WFSException e) {
89
                                throw new InitializeException("Not possible to connect with " + url, e);
90
                        }
91
                }
92
        }
93
        
94
        /**
95
         * Returns all the feature information retrieved using a
96
         * describeFeatureTypeOpearion
97
         * @param layerName
98
         * Feature name
99
         * @return
100
         * @throws WFSException 
101
         */
102
        public WFSFeature getFeatureInfo(String nameSpace, String layerName) throws WFSException{
103
                describeFeatureType(layerName, nameSpace, null);
104
                return (WFSFeature) wfsClient.getFeatures().get(layerName);                        
105
        }
106
        
107
        private void describeFeatureType(String featureType, String nameSpace, ICancellable cancel) throws WFSException {
108
                status = new WFSStatus(featureType, nameSpace);
109
                wfsClient.describeFeatureType(status, false, cancel);
110
        }
111
        
112
        /**
113
         * Returns an array of WFSLayerNode's with the descriptors of
114
         * all features (retrieved using the getCapabilities operation)
115
         * @return WFSLayerNode[]
116
         */
117
        public Hashtable getFeatures(){
118
                return wfsClient.getFeatures();
119
        }
120

    
121
        /* (non-Javadoc)
122
         * @see org.gvsig.fmap.dal.DataServerExplorer#add(org.gvsig.fmap.dal.NewDataStoreParameters, boolean)
123
         */
124
        public boolean add(String providerName, NewDataStoreParameters parameters, boolean overwrite)
125
        throws DataException {
126
                // TODO Auto-generated method stub
127
                return false;
128
        }
129

    
130
        /* (non-Javadoc)
131
         * @see org.gvsig.fmap.dal.DataServerExplorer#canAdd()
132
         */
133
        public boolean canAdd() {
134
                // TODO Auto-generated method stub
135
                return false;
136
        }
137

    
138
        /* (non-Javadoc)
139
         * @see org.gvsig.fmap.dal.DataServerExplorer#canAdd(java.lang.String)
140
         */
141
        public boolean canAdd(String storeName) throws DataException {
142
                // TODO Auto-generated method stub
143
                return false;
144
        }
145

    
146
        @Override
147
        protected void doDispose() throws BaseException {
148
                // Nothing to do
149
        }
150

    
151
        /* (non-Javadoc)
152
         * @see org.gvsig.fmap.dal.DataServerExplorer#getAddParameters(java.lang.String)
153
         */
154
        public NewDataStoreParameters getAddParameters(String storeName)
155
        throws DataException {
156
                // TODO Auto-generated method stub
157
                return null;
158
        }
159

    
160
        /* (non-Javadoc)
161
         * @see org.gvsig.fmap.dal.DataServerExplorer#getName()
162
         */
163
        public String getName() {
164
                return NAME;
165
        }
166

    
167
        /* (non-Javadoc)
168
         * @see org.gvsig.fmap.dal.DataServerExplorer#getParameters()
169
         */
170
        public DataServerExplorerParameters getParameters() {
171
                return parameters;
172
        }
173

    
174
        /* (non-Javadoc)
175
         * @see org.gvsig.fmap.dal.DataServerExplorer#list()
176
         */
177
        public List list() throws DataException {
178
                ArrayList list = new ArrayList();
179
                Hashtable features = wfsClient.getFeatures();
180
                Iterator it = features.keySet().iterator();
181
                DataStoreParameters dsp = null;
182
                while (it.hasNext()){
183
                        String key = (String)it.next();
184
                        WFSFeature feature = (WFSFeature)features.get(key);
185
                        list.add(getParametersFor(feature));
186
                }
187
                return list;
188
        }
189

    
190
        public DataStoreParameters getParametersFor(WFSFeature feature)
191
        throws DataException {
192
                WFSStoreParameters params = (WFSStoreParameters)dataManager
193
                .createStoreParameters(WFSStoreProvider.NAME);
194
                params.setUrl(url);
195
                params.setFeatureType(feature.getNamespace().getName(), 
196
                                feature.getNamespace().getLocation(),
197
                                feature.getName());
198
                return params;
199
        }
200

    
201
        /* (non-Javadoc)
202
         * @see org.gvsig.fmap.dal.DataServerExplorer#list(int)
203
         */
204
        public List list(int mode) throws DataException {
205
                return list();
206
        }
207

    
208
        /* (non-Javadoc)
209
         * @see org.gvsig.fmap.dal.DataServerExplorer#remove(org.gvsig.fmap.dal.DataStoreParameters)
210
         */
211
        public void remove(DataStoreParameters parameters) throws DataException {
212
                // TODO Auto-generated method stub
213

    
214
        }
215

    
216
        /* (non-Javadoc)
217
         * @see org.gvsig.fmap.dal.spi.DataServerExplorerProvider#getServerExplorerProviderServices()
218
         */
219
        public DataServerExplorerProviderServices getServerExplorerProviderServices() {
220
                // TODO Auto-generated method stub
221
                return null;
222
        }
223

    
224
        /* (non-Javadoc)
225
         * @see org.gvsig.fmap.dal.spi.DataServerExplorerProvider#initialize(org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices)
226
         */
227
        public void initialize(
228
                        DataServerExplorerProviderServices dataServerExplorerProviderServices) {
229
                // TODO Auto-generated method stub
230
                
231
        }
232

    
233
        /**
234
         * @return
235
         */
236
        public String getTitle() {
237
                String title = wfsClient.getServiceInformation().title;
238
                if (title == null){
239
                        return "None";
240
                }
241
                return title;                
242
        }
243

    
244
        /**
245
         * @return
246
         */
247
        public String getAbstract() {
248
                String _abstract = wfsClient.getServiceInformation().abstr;
249
                if (_abstract == null){
250
                        return "None";
251
                }
252
                return _abstract;
253
        }
254

    
255
        /**
256
         * @return
257
         */
258
        public String getServerType() {
259
                String serverVersion = wfsClient.getVersion();
260
                if (serverVersion == null) {
261
                        return "WFS";
262
                }
263
                return "WFS "+ serverVersion;
264
        }
265

    
266
        /**
267
         * @return
268
         */
269
        public String getUrl() {
270
                return wfsClient.getHost();
271
        }
272

    
273
        /**
274
         * @return
275
         */
276
        public int getBuffer() {
277
                return status.getBuffer();
278
        }
279

    
280
        /**
281
         * @return
282
         */
283
        public int getTimeOut() {
284
                return status.getTimeout();
285
        }
286

    
287
        /**
288
         * @param userName
289
         */
290
        public void setUserName(String userName) {
291
                status.setUserName(userName);                
292
        }
293

    
294
        /**
295
         * @param buffer
296
         */
297
        public void setBuffer(int buffer) {
298
                status.setBuffer(buffer);
299
        }
300

    
301
        /**
302
         * @param timeout
303
         */
304
        public void setTimeOut(int timeout) {
305
                status.setTimeout(timeout);                
306
        }
307

    
308
        /**
309
         * @return
310
         */
311
        public String getVersion() {
312
                return wfsClient.getVersion();
313
        }
314

    
315
        public List getDataStoreProviderNames() {
316
                List x = new ArrayList();
317
                x.add(WFSStoreProvider.NAME);
318
                return x;
319
        }        
320
}