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

History | View | Annotate | Download (9.93 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, parameters.getIgnoreChace());
83
                if (status == null){
84
                    status = new WFSStatus(null);                                        
85
                }
86
                
87
                wfsClient.getCapabilities(status, parameters.getIgnoreChace(), null);
88
            } catch (ConnectException e) {
89
                throw new InitializeException("Not possible to connect with " + url, e);
90
            } catch (IOException e) {
91
                throw new InitializeException("Not possible to connect with " + url, e);
92
            } catch (WFSException e) {
93
                throw new InitializeException("Not possible to connect with " + url, e);
94
            }
95
        }
96
    }
97

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

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

    
122
        return         feature;
123
    }
124

    
125

    
126

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

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

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

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

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

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

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

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

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

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

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

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

    
229
    }
230

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

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

    
246
    }
247

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

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

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

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

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

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

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

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

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

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

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