Statistics
| Revision:

root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / wfs / WFSServerExplorer.java @ 10

History | View | Annotate | Download (9.85 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.File;
31
import java.io.FileNotFoundException;
32
import java.io.IOException;
33
import java.net.ConnectException;
34
import java.util.ArrayList;
35
import java.util.Hashtable;
36
import java.util.Iterator;
37
import java.util.List;
38

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

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

    
69
    //WFS Parameters
70
    private WFSStatus status = null;
71
    private WFSClient wfsClient = null;
72

    
73
    /**
74
     * @param parameters
75
     */
76
    public WFSServerExplorer(WFSServerExplorerParameters parameters, DataServerExplorerProviderServices services) throws InitializeException{
77
        super();
78
        this.parameters = parameters;
79
        this.url = parameters.getUrl();
80
        if (wfsClient == null){
81
            try {
82
                wfsClient = new WFSClient(url);
83
                if (status == null){
84
                    status = new WFSStatus(null);                                        
85
                }
86
                wfsClient.getCapabilities(status, false, null);
87
            } catch (ConnectException e) {
88
                throw new InitializeException("Not possible to connect with " + url, e);
89
            } catch (IOException e) {
90
                throw new InitializeException("Not possible to connect with " + url, e);
91
            } catch (WFSException e) {
92
                throw new InitializeException("Not possible to connect with " + url, e);
93
            }
94
        }
95
    }
96

    
97
    /**
98
     * Returns all the feature information retrieved using a
99
     * describeFeatureTypeOpearion
100
     * @param layerName
101
     * Feature name
102
     * @return
103
     * @throws WFSException 
104
     */
105
    public WFSFeature getFeatureInfo(String nameSpace, String layerName) throws WFSException{
106
        status = new WFSStatus(layerName, nameSpace);
107
        WFSFeature feature = (WFSFeature) wfsClient.getFeature(nameSpace, layerName); 
108
        if (!feature.isCompleted()){
109
            File describeFeatureTypeFile = wfsClient.describeFeatureType(status, false, null);
110

    
111
            WFSFeatureFiller featureFiller = new WFSFeatureFiller(feature);
112
            try {
113
                featureFiller.fill(describeFeatureTypeFile);
114
            } catch (SchemaCreationException e) {
115
                throw new WFSException(e);
116
            } catch (FileNotFoundException e) {
117
                throw new WFSException(e);
118
            }
119
        }
120

    
121
        return         feature;
122
    }
123

    
124

    
125

    
126
    /**
127
     * Returns an array of WFSLayerNode's with the descriptors of
128
     * all features (retrieved using the getCapabilities operation)
129
     * @return WFSLayerNode[]
130
     */
131
    public Hashtable getFeatures(){
132
        return wfsClient.getFeatures();
133
    }
134

    
135
    /* (non-Javadoc)
136
     * @see org.gvsig.fmap.dal.DataServerExplorer#add(org.gvsig.fmap.dal.NewDataStoreParameters, boolean)
137
     */
138
    public boolean add(String providerName, NewDataStoreParameters parameters, boolean overwrite)
139
    throws DataException {
140
        // TODO Auto-generated method stub
141
        return false;
142
    }
143

    
144
    /* (non-Javadoc)
145
     * @see org.gvsig.fmap.dal.DataServerExplorer#canAdd()
146
     */
147
    public boolean canAdd() {
148
        // TODO Auto-generated method stub
149
        return false;
150
    }
151

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

    
160
    @Override
161
    protected void doDispose() throws BaseException {
162
        // Nothing to do
163
    }
164

    
165
    /* (non-Javadoc)
166
     * @see org.gvsig.fmap.dal.DataServerExplorer#getAddParameters(java.lang.String)
167
     */
168
    public NewDataStoreParameters getAddParameters(String storeName)
169
    throws DataException {
170
        // TODO Auto-generated method stub
171
        return null;
172
    }
173

    
174
    /* (non-Javadoc)
175
     * @see org.gvsig.fmap.dal.DataServerExplorer#getName()
176
     */
177
    public String getProviderName() {
178
        return NAME;
179
    }
180

    
181
    /* (non-Javadoc)
182
     * @see org.gvsig.fmap.dal.DataServerExplorer#getParameters()
183
     */
184
    public DataServerExplorerParameters getParameters() {
185
        return parameters;
186
    }
187

    
188
    /* (non-Javadoc)
189
     * @see org.gvsig.fmap.dal.DataServerExplorer#list()
190
     */
191
    public List list() throws DataException {
192
        ArrayList list = new ArrayList();
193
        Hashtable features = wfsClient.getFeatures();
194
        Iterator it = features.keySet().iterator();
195
        DataStoreParameters dsp = null;
196
        while (it.hasNext()){
197
            String key = (String)it.next();
198
            WFSFeature feature = (WFSFeature)features.get(key);
199
            list.add(getParametersFor(feature));
200
        }
201
        return list;
202
    }
203

    
204
    public DataStoreParameters getParametersFor(WFSFeature feature)
205
    throws DataException {
206
        WFSStoreParameters params = (WFSStoreParameters)dataManager
207
        .createStoreParameters(WFSStoreProvider.NAME);
208
        params.setUrl(url);
209
        params.setFeatureType(feature.getNamespace().getPrefix(), 
210
            feature.getNamespace().getLocation(),
211
            feature.getName());
212
        return params;
213
    }
214

    
215
    /* (non-Javadoc)
216
     * @see org.gvsig.fmap.dal.DataServerExplorer#list(int)
217
     */
218
    public List list(int mode) throws DataException {
219
        return list();
220
    }
221

    
222
    /* (non-Javadoc)
223
     * @see org.gvsig.fmap.dal.DataServerExplorer#remove(org.gvsig.fmap.dal.DataStoreParameters)
224
     */
225
    public void remove(DataStoreParameters parameters) throws DataException {
226
        // TODO Auto-generated method stub
227

    
228
    }
229

    
230
    /* (non-Javadoc)
231
     * @see org.gvsig.fmap.dal.spi.DataServerExplorerProvider#getServerExplorerProviderServices()
232
     */
233
    public DataServerExplorerProviderServices getServerExplorerProviderServices() {
234
        // TODO Auto-generated method stub
235
        return null;
236
    }
237

    
238
    /* (non-Javadoc)
239
     * @see org.gvsig.fmap.dal.spi.DataServerExplorerProvider#initialize(org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices)
240
     */
241
    public void initialize(
242
        DataServerExplorerProviderServices dataServerExplorerProviderServices) {
243
        // TODO Auto-generated method stub
244

    
245
    }
246

    
247
    /**
248
     * @return
249
     */
250
    public String getTitle() {
251
        String title = wfsClient.getServiceInformation().title;
252
        if (title == null){
253
            return "None";
254
        }
255
        return title;                
256
    }
257

    
258
    /**
259
     * @return
260
     */
261
    public String getAbstract() {
262
        String _abstract = wfsClient.getServiceInformation().abstr;
263
        if (_abstract == null){
264
            return "None";
265
        }
266
        return _abstract;
267
    }
268

    
269
    /**
270
     * @return
271
     */
272
    public String getServerType() {
273
        String serverVersion = wfsClient.getVersion();
274
        if (serverVersion == null) {
275
            return "WFS";
276
        }
277
        return "WFS "+ serverVersion;
278
    }
279

    
280
    /**
281
     * @return
282
     */
283
    public String getUrl() {
284
        return wfsClient.getHost();
285
    }
286

    
287
    /**
288
     * @return
289
     */
290
    public int getMaxFeatures() {
291
        return status.getMaxFeatures();
292
    }
293

    
294
    /**
295
     * @return
296
     */
297
    public int getTimeOut() {
298
        return status.getTimeout();
299
    }
300

    
301
    /**
302
     * @param userName
303
     */
304
    public void setUserName(String userName) {
305
        status.setUserName(userName);                
306
    }
307

    
308
    /**
309
     * @param buffer
310
     */
311
    public void setMaxFeatures(int buffer) {
312
        status.setMaxFeatures(buffer);
313
    }
314

    
315
    /**
316
     * @param timeout
317
     */
318
    public void setTimeOut(int timeout) {
319
        status.setTimeout(timeout);                
320
    }
321

    
322
    /**
323
     * @return
324
     */
325
    public String getVersion() {
326
        return wfsClient.getVersion();
327
    }
328

    
329
    public List getDataStoreProviderNames() {
330
        List x = new ArrayList();
331
        x.add(WFSStoreProvider.NAME);
332
        return x;
333
    }        
334
}