Revision 105

View differences:

org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/buildNumber.properties
1
#Mon Aug 04 21:08:53 EDT 2014
2
buildNumber=2088
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/serverexplorer/wfs/WFSServerExplorer.java
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
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/serverexplorer/wfs/WFSServerExplorerParameters.java
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
package org.gvsig.fmap.dal.serverexplorer.wfs;
28

  
29
import org.apache.commons.lang3.BooleanUtils;
30
import org.gvsig.fmap.dal.DataServerExplorerParameters;
31
import org.gvsig.fmap.dal.DataTypes;
32
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DelegatedDynObject;
35
import org.gvsig.tools.dynobject.DynClass;
36
import org.gvsig.tools.dynobject.DynField;
37
import org.gvsig.tools.dynobject.DynObjectManager;
38

  
39
/**
40
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41
 */
42
public class WFSServerExplorerParameters extends AbstractDataParameters
43
        implements DataServerExplorerParameters {
44

  
45
    public static final String DYNCLASS_NAME = "WFSServerExplorerParameters";
46
    public static final String DYNFIELDNAME_URL = "url";
47
    public static final String DYNFIELDNAME_VERSION = "version";
48
    public static final String DYNFIELDNAME_IGNORE_CACHE = "ignoreCache";
49
    private DelegatedDynObject delegatedDynObject;
50

  
51
    public WFSServerExplorerParameters() {
52
        super();
53
        this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
54
                .getDynObjectManager()
55
                .createDynObject(this.registerDynClass());
56
    }
57

  
58
    @Override
59
    protected DelegatedDynObject getDelegatedDynObject() {
60
        return delegatedDynObject;
61
    }
62

  
63
    private DynClass registerDynClass() {
64
        DynObjectManager dynman = ToolsLocator.getDynObjectManager();
65
        DynClass dynClass = dynman.get(DYNCLASS_NAME);
66
        DynField field;
67
        if (dynClass == null) {
68
            dynClass = dynman.add(DYNCLASS_NAME);
69

  
70
            field = dynClass.addDynFieldString(DYNFIELDNAME_URL);
71
            field.setDescription("Path of the remote service");
72
            field.setMandatory(true);
73

  
74
            field = dynClass.addDynFieldString(DYNFIELDNAME_VERSION);
75
            field.setDescription("Version of the remote service");
76
            field.setMandatory(false);
77

  
78
            field = dynClass.addDynFieldBoolean(DYNFIELDNAME_IGNORE_CACHE);
79
            field.setDescription("If this is true download al files in the next access.");
80
            field.setMandatory(false);
81
            field.setDefaultFieldValue(Boolean.FALSE);
82
        }
83
        return dynClass;
84
    }
85

  
86
    /* (non-Javadoc)
87
     * @see org.gvsig.fmap.dal.DataServerExplorerParameters#getExplorerName()
88
     */
89
    public String getExplorerName() {
90
        return WFSServerExplorer.NAME;
91
    }
92

  
93
    public String getUrl() {
94
        return (String) this.getDynValue(DYNFIELDNAME_URL);
95
    }
96

  
97
    public void setUrl(String url) {
98
        this.setDynValue(DYNFIELDNAME_URL, url);
99
    }
100

  
101
    public String getVersion() {
102
        return (String) this.getDynValue(DYNFIELDNAME_VERSION);
103
    }
104

  
105
    public void setVersion(String version) {
106
        this.setDynValue(DYNFIELDNAME_VERSION, version);
107
    }
108

  
109
    public boolean getIgnoreChace() {
110
        return BooleanUtils.isTrue((Boolean) this.getDynValue(DYNFIELDNAME_IGNORE_CACHE));
111
    }
112

  
113
    public void setIgnoreCache(Boolean ignoreCache) {
114
        this.setDynValue(DYNFIELDNAME_IGNORE_CACHE, new Boolean(ignoreCache));
115
    }
116

  
117
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/wfs/WFSLibrary.java
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.store.wfs;
29

  
30
import org.gvsig.fmap.dal.DALLibrary;
31
import org.gvsig.fmap.dal.DALLocator;
32
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer;
33
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorerParameters;
34
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
35
import org.gvsig.fmap.mapcontext.MapContextLibrary;
36
import org.gvsig.metadata.exceptions.MetadataException;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.extensionpoint.ExtensionPoint;
39
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
40
import org.gvsig.tools.library.AbstractLibrary;
41
import org.gvsig.tools.library.LibraryException;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class WFSLibrary extends AbstractLibrary {
47

  
48
    @Override
49
    public void doRegistration() {
50
        registerAsServiceOf(DALLibrary.class);
51
        require(MapContextLibrary.class);
52
    }
53

  
54
	@Override
55
	protected void doInitialize() throws LibraryException {
56
	}
57

  
58
	@Override
59
	protected void doPostInitialize() throws LibraryException {
60
		WFSStoreParameters.registerDynClass();
61
		try {
62
			WFSStoreProvider.registerMetadataDefinition();
63
		} catch (MetadataException e) {
64
			throw new LibraryException(this.getClass(), e);
65
		}
66

  
67
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator
68
		.getDataManager();
69

  
70
		if (!dataman.getStoreProviders().contains(WFSStoreProvider.NAME)) {
71
			dataman.registerStoreProvider(WFSStoreProvider.NAME,
72
					WFSStoreProvider.class, WFSStoreParameters.class);
73
		}	
74
		
75
		if (!dataman.getExplorerProviders().contains(WFSServerExplorer.NAME)){
76
			dataman.registerExplorerProvider(WFSServerExplorer.NAME,
77
					WFSServerExplorer.class, WFSServerExplorerParameters.class);
78
		}	
79
		
80
		//Register the WFSStroreParams to be loaded from the catalog extension
81
		ExtensionPointManager extensionPointManager = ToolsLocator
82
		.getExtensionPointManager();
83
		ExtensionPoint extensionPoint = extensionPointManager.add("CatalogDataStoreParameters");
84
		extensionPoint.append("OGC:WFS", "Data store parameters to load a WFS layer", WFSStoreParameters.class);
85
	}
86
}
87

  
88

  
89

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/wfs/WFSStoreProvider.java
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.store.wfs;
29

  
30
import java.io.File;
31
import java.io.IOException;
32
import java.util.ArrayList;
33
import java.util.Iterator;
34
import java.util.List;
35

  
36
import org.cresques.cts.ICoordTrans;
37
import org.cresques.cts.IProjection;
38
import org.gvsig.fmap.crs.CRSFactory;
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.DataStoreParameters;
43
import org.gvsig.fmap.dal.DataTypes;
44
import org.gvsig.fmap.dal.exception.ConnectionServerException;
45
import org.gvsig.fmap.dal.exception.DataException;
46
import org.gvsig.fmap.dal.exception.InitializeException;
47
import org.gvsig.fmap.dal.exception.OpenException;
48
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
49
import org.gvsig.fmap.dal.exception.ReadException;
50
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
51
import org.gvsig.fmap.dal.feature.EditableFeatureType;
52
import org.gvsig.fmap.dal.feature.FeatureQuery;
53
import org.gvsig.fmap.dal.feature.FeatureStore;
54
import org.gvsig.fmap.dal.feature.FeatureType;
55
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
56
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
57
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
58
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
59
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
60
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer;
61
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorerParameters;
62
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
63
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider;
64
import org.gvsig.fmap.geom.Geometry;
65
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
66
import org.gvsig.fmap.geom.GeometryLocator;
67
import org.gvsig.fmap.geom.GeometryManager;
68
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
69
import org.gvsig.fmap.geom.operation.GeometryOperationException;
70
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
71
import org.gvsig.fmap.geom.primitive.Envelope;
72
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerCreationException;
73
import org.gvsig.metadata.MetadataLocator;
74
import org.gvsig.metadata.MetadataManager;
75
import org.gvsig.metadata.exceptions.MetadataException;
76
import org.gvsig.remoteclient.ogc.OGCClientOperation;
77
import org.gvsig.remoteclient.utils.BoundaryBox;
78
import org.gvsig.remoteclient.wfs.WFSClient;
79
import org.gvsig.remoteclient.wfs.WFSFeature;
80
import org.gvsig.remoteclient.wfs.WFSFeatureField;
81
import org.gvsig.remoteclient.wfs.WFSStatus;
82
import org.gvsig.remoteclient.wfs.exceptions.WFSException;
83
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding;
84
import org.gvsig.remoteclient.wfs.request.WFSGetFeatureRequestInformation;
85
import org.gvsig.remoteclient.wfs.request.WFSTransactionRequestInformation;
86
import org.gvsig.tools.ToolsLocator;
87
import org.gvsig.tools.dynobject.DynStruct;
88
import org.gvsig.tools.evaluator.EvaluatorFieldValue;
89
import org.gvsig.tools.evaluator.EvaluatorFieldValueMatch;
90
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo;
91
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator;
92
import org.gvsig.xmlschema.lib.api.XMLSchemaManager;
93
import org.gvsig.xmlschema.lib.api.som.IXSGeometryTypeDefinition;
94
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition;
95
import org.slf4j.Logger;
96
import org.slf4j.LoggerFactory;
97

  
98

  
99
/**
100
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
101
 */
102
public class WFSStoreProvider extends AbstractFeatureStoreProvider {
103
    private static final Logger logger = LoggerFactory.getLogger(WFSStoreProvider.class);
104
    public static String NAME = "WFSStore";
105
    public static String DESCRIPTION = "WFS store to load WFS resources";
106

  
107
    private static final MetadataManager metadataManager = MetadataLocator.getMetadataManager();
108
    private static final String METADATA_DEFINITION_NAME = "WFSStore";    
109
    private static final String METADATA_DEFINITION_DESCRIPTION = "WFSStore metadata definition";
110

  
111
    // private IProjection projection;	
112
    private long featureCount = -1;
113
    private boolean isKnownEnvelope = false;
114

  
115
    /**
116
     * If the user has selected the filter by area option
117
     */
118
    private boolean hasFilterByArea = false;
119

  
120
    /**
121
     * GML provider used by delegation to read the GML files
122
     */
123
    private GPEStoreProvider storeProviderDelegate = null;
124

  
125
    private static final DataManager dataManager = DALLocator.getDataManager();   
126
    private static final XMLSchemaManager xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager();  	
127

  
128
    boolean isFilterByAreaSupported = true;
129

  
130
    //WFS Parameters
131
    private WFSClient wfsClient;
132
    private WFSStatus wfsStatus;
133

  
134
    public WFSStoreProvider(DataStoreParameters params,
135
        DataStoreProviderServices storeServices)
136
    throws InitializeException {
137
        super(params, storeServices, 
138
            ToolsLocator.getDynObjectManager().createDynObject(metadataManager.getDefinition(METADATA_DEFINITION_NAME)));		
139
        initParams();
140
        try {
141
            initFeatureType();
142
        } catch (WFSException e) {
143
            throw new InitializeException(e);
144
        } catch (ReadException e) {
145
            throw new InitializeException(e);
146
        }
147
    }
148

  
149
    private void initParams() throws InitializeException{
150
        try {
151
            WFSStoreParameters wfsParameters = getWFSParameters();
152
            try {
153
                if (wfsParameters.getVersion() == null){
154
                    wfsClient = new WFSClient(wfsParameters.getUrl(), wfsParameters.getIgnoreCache());
155
                    wfsParameters.setVersion(wfsClient.getVersion());
156
                }else{
157
                    wfsClient = new WFSClient(wfsParameters.getUrl(), wfsParameters.getVersion(), wfsParameters.getIgnoreCache());
158
                }
159
            } catch (IOException e) {
160
                throw new InitializeException(e);
161
            }
162
            wfsStatus = new WFSStatus( wfsParameters.getFeatureType(),
163
                wfsParameters.getFeatureNamespace());
164
            wfsStatus.setNamespacePrefix(wfsParameters.getFeaturePrefix());
165
            wfsStatus.setFields(wfsParameters.getFields());
166

  
167
            //Select the filter by area
168
            wfsStatus.setFilterByArea(wfsParameters.getFilterByAreaGeometry(), wfsParameters.getFilterByAreaAttribute(), 
169
                wfsParameters.getFilterByAreaCrs(), wfsParameters.getFilterByAreaOperation());
170
            this.hasFilterByArea = (wfsStatus.getFilterByArea() != null);
171

  
172
            //Select the filter by attribute
173
            wfsStatus.setFilterByAttribute(wfsParameters.getFilterEncodingByAttribute());
174
            
175
            String _srs = wfsParameters.getFilterByAreaCrs();
176
            wfsStatus.setSrs(_srs);
177

  
178
            wfsStatus.setTimeout(wfsParameters.getTimeOut());
179
            wfsStatus.setMaxFeatures(wfsParameters.getMaxFeatures());
180
            wfsStatus.setUserName(wfsParameters.getUser());
181
            wfsStatus.setPassword(wfsParameters.getPassword());
182

  
183
            //Setting the envelope for the layer
184
            wfsClient.getCapabilities(wfsStatus, false, null);
185

  
186
            Envelope envelope = calculateFullEnvelope();
187
            if (envelope != null){
188
                this.setDynValue("Envelope", envelope);
189
                isKnownEnvelope = true;
190
            }			
191
        } catch (WFSException e) {
192
            throw new InitializeException("Impossible to retrieve the file", e);
193
        }
194
    }
195

  
196
    private WFSFeature getSelectedWFSFeature() throws ReadException, WFSException{
197
        WFSStoreParameters wfsParameters = getWFSParameters();
198

  
199
        return  ((WFSServerExplorer)getExplorer()).getFeatureInfo(wfsParameters.getFeatureNamespace(),
200
            wfsParameters.getFeatureType());
201
    }
202

  
203
    private void initFeatureType() throws WFSException, ReadException{	   
204
        WFSFeature feature  = getSelectedWFSFeature();
205

  
206
        if (feature == null){
207
            //TODO read from GML
208
            throw new WFSException("It is not possible to parse the schema");
209
        }
210

  
211
        IProjection ipro = null;
212
        try {
213
            ipro = CRSFactory.getCRS(wfsStatus.getSrs());
214
            this.setDynValue("CRS", ipro);
215
        } catch (Exception ex) {
216
            logger.info("Error: did not set CRS in store provider.", ex);
217
        }
218

  
219
        EditableFeatureType featureType = getStoreServices().createFeatureType();
220

  
221
        for (int i=0 ; i<feature.getFieldSize() ; i++){       
222
            WFSFeatureField featureField = feature.getFieldAt(i);           
223
            int dataType = DataTypes.STRING;               
224
            String typeName = featureField.getType();
225
            EditableFeatureAttributeDescriptor attributeDescriptor = null;
226

  
227
            IXSTypeDefinition typeDefinition = null;
228
            
229
            if (typeName != null){
230
                typeDefinition = xmlSchemaManager.getTypeDefinition(typeName);
231
            }
232
            
233
            if (typeDefinition != null){             
234
                if (typeDefinition.getDataType() != null){
235
                    if (typeDefinition.getDataType().getType() == DataTypes.GEOMETRY){
236
                        dataType = typeDefinition.getDataType().getType();
237
                    }
238
                }
239
                attributeDescriptor = featureType.add(featureField.getName(), dataType);   
240
                if (typeDefinition instanceof IXSGeometryTypeDefinition){
241
                    
242
                    if (ipro != null) {
243
                        attributeDescriptor.setSRS(ipro);
244
                    } else {
245
                        if (feature.getSrs().size() > 0){
246
                            attributeDescriptor.setSRS(CRSFactory.getCRS((String)feature.getSrs().get(0)));
247
                        } else {
248
                            logger.info("Unable to set CRS in feature type.");
249
                        }
250
                    }
251
                    
252
                    
253
                    attributeDescriptor.setGeometryType(((IXSGeometryTypeDefinition)typeDefinition).getGeometryType());
254
                    attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM3D);
255
                    featureType.setDefaultGeometryAttributeName(featureField.getName());
256
                }                               
257
            }else{
258
                attributeDescriptor = featureType.add(typeName, dataType);    
259
            }    
260
            // length, relevant for all (strings) except geometry
261
            attributeDescriptor.setSize(128);
262
        }       
263
        featureType.setHasOID(true);
264

  
265
        FeatureType defaultType = featureType.getNotEditableCopy();
266
        List types = new ArrayList(1);
267
        types.add(defaultType);
268
        this.getStoreServices().setFeatureTypes(types, defaultType);
269
    }
270

  
271
    private Envelope calculateFullEnvelope() {
272
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
273

  
274
        try{
275
            WFSFeature feature  = getSelectedWFSFeature();
276
            if (feature != null){ 
277
                String _srs = wfsStatus.getSrs();
278
                if (_srs != null) {
279

  
280
                    BoundaryBox boundaryBox = feature.getBbox(_srs);
281
                    //The projection is found
282
                    if (boundaryBox != null){
283
                        return geometryManager.createEnvelope(boundaryBox.getXmin(),
284
                            boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D);
285
                    }
286
                    //Check if there is a latlon envelope
287
                    boundaryBox = feature.getLatLonBbox();
288
                    if (boundaryBox != null){
289
                        Envelope envelope = geometryManager.createEnvelope(boundaryBox.getXmin(),
290
                            boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D);
291
                        if (!"EPSG:4326".equals(_srs)){
292
                            IProjection sourceProjection = CRSFactory.getCRS("EPSG:4326");
293
                            IProjection destinationProjection = CRSFactory.getCRS(_srs);
294
                            if (destinationProjection != null){
295
                                ICoordTrans coordTrans = sourceProjection.getCT(destinationProjection);
296
                                return envelope.convert(coordTrans);
297
                            }	
298
                        }
299
                    }
300
                }else{
301
                    //If there is not a SRS is thrown a request for the first 500 features
302
                    int odlMaxFeatures = wfsStatus.getMaxFeatures();
303
                    wfsStatus.setMaxFeatures(500);
304
                    createSet(null, null);
305
                    return storeProviderDelegate.getEnvelope();
306
                }
307
            }
308
        }catch(CreateEnvelopeException e){
309
            logger.error("Impossible to create an envelope", e);
310
        } catch (ReadException e) {
311
            logger.error("Impossible to create an envelope", e);
312
        } catch (WFSException e) {
313
            logger.error("Impossible to create an envelope", e);
314
        } catch (DataException e) {
315
            logger.error("Impossible to create an envelope", e);
316
        }
317
        return null;
318
    }
319

  
320
    private WFSStoreParameters getWFSParameters() {
321
        return (WFSStoreParameters) getParameters();
322
    }
323

  
324
    /* (non-Javadoc)
325
     * @see org.gvsig.fmap.dal.store.gpe.GPEStoreProvider#open()
326
     */
327
    public void open() throws OpenException {
328
        try {
329
            List featureTypes = this.getFeatureStore().getFeatureTypes();
330
            for (int i=0 ; i<featureTypes.size() ; i++){
331
                FeatureType featureType = (FeatureType)featureTypes.get(i);
332
            }
333
        } catch (DataException e) {
334
            throw new OpenException("Reading the geometry type", e);
335
        }
336
    }
337

  
338
    protected static void registerMetadataDefinition() throws MetadataException {       
339
        if (metadataManager.getDefinition(METADATA_DEFINITION_NAME) == null) {
340
            DynStruct metadataDefinition = metadataManager.addDefinition(
341
                METADATA_DEFINITION_NAME, METADATA_DEFINITION_DESCRIPTION);
342

  
343
            metadataDefinition.addDynFieldObject("Envelope").setClassOfValue(Envelope.class).setMandatory(false);
344
            metadataDefinition.addDynFieldObject("CRS").setClassOfValue(IProjection.class).setMandatory(true);
345

  
346
            metadataDefinition.extend(metadataManager
347
                .getDefinition(FeatureStore.METADATA_DEFINITION_NAME));
348
        }
349
    }
350

  
351
    /* (non-Javadoc)
352
     * @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#getExplorer()
353
     */
354
    public DataServerExplorer getExplorer() throws ReadException {
355
        DataManager manager = DALLocator.getDataManager();
356
        WFSServerExplorerParameters params;
357
        try {
358
            params = (WFSServerExplorerParameters) manager
359
            .createServerExplorerParameters(WFSServerExplorer.NAME);
360
            params.setUrl(wfsClient.getHost());
361
            return manager.openServerExplorer(WFSServerExplorer.NAME,params);
362
        } catch (Exception e) {
363
            throw new ReadException(this.getName(), e);
364
        }
365
    }
366

  
367
    public String getProviderName() {
368
        return NAME;
369
    }
370

  
371
    public FeatureSetProvider createSet(FeatureQuery query)
372
    throws DataException {
373
        return createSet(query, null);
374
    }
375

  
376
    public FeatureSetProvider createSet(FeatureQuery query,
377
        FeatureType featureType) throws DataException {
378
        if ((featureCount == -1) ||
379
            (storeProviderDelegate == null) ||
380
            (featureCount >= wfsStatus.getMaxFeatures())){ 
381

  
382
            File file = null;
383

  
384
            if (query == null){
385
                file = executeQuery();   
386
            }else{
387
                //If it is possible to execute a spatial query...
388
                if ((query.getFilter() != null) && (!hasFilterByArea)){
389
                    file = executeSpatialQuery(query);
390
                }else{
391
                    file = executeQuery();   
392
                }	
393

  
394
            }
395
            storeProviderDelegate = createProvider(file);
396
        }
397
        
398
        return storeProviderDelegate.createSet(query, featureType);
399
    }
400

  
401
    /**
402
     * It creates the provider that is used to retrieve features from a file.
403
     * @param file
404
     * the file that contains the downloaded file
405
     * @return
406
     * @throws InitializeException
407
     * @throws ProviderNotRegisteredException
408
     */
409
    private GPEStoreProvider createProvider(File file) throws InitializeException, ProviderNotRegisteredException{
410
        return new GPEStoreProvider(createStoreParameters(file), getStoreServices());
411
    }	
412

  
413
    private DataStoreParameters createStoreParameters(File file) throws InitializeException, ProviderNotRegisteredException{
414
        DataStoreParameters parameters = dataManager.createStoreParameters(GPEStoreProvider.NAME);
415

  
416
        parameters.setDynValue("File", file.getAbsolutePath());
417
        parameters.setDynValue("Envelope", this.getDynValue("Envelope"));
418
        parameters.setDynValue("useAxisOrderYX", this.getWFSParameters().getUseAxisOrderYX());
419
        return parameters;
420
    }
421

  
422
    /**
423
     * It executes a wfs Query without spatial filter
424
     * @throws DataException
425
     */
426
    private File executeQuery() throws DataException{
427
        try{
428
            wfsStatus.setResultType(WFSStatus.RESULTYPE_RESULTS);
429
            if (!hasFilterByArea){
430
                wfsStatus.removeFilterByArea();
431
            }
432
            return wfsClient.getFeature(wfsStatus, getWFSParameters().getIgnoreCache(), null);
433
        } catch (WFSException e) {
434
            throw new InitializeException("Impossible to retrieve the file", e);
435
        }
436
    }
437

  
438
    /**
439
     * Executes a new query sending the FilterEncoding request to the server
440
     * @param query
441
     * The Query to send
442
     * @throws InitializeException
443
     * If there is a problem with the request or the parsing process
444
     */
445
    private File executeSpatialQuery(FeatureQuery query) throws DataException{
446
        EvaluatorFieldsInfo fieldsInfo = query.getFilter().getFieldsInfo();
447
        String[] fields = fieldsInfo.getFieldNames();
448
        for (int i=0 ; i<fields.length ; i++){
449
            EvaluatorFieldValue[] evaluatorFieldValues = fieldsInfo.getFieldValues(fields[i]);
450
            for (int j=0 ; j<evaluatorFieldValues.length ; j++){				
451
                if (EvaluatorFieldValue.MATCH == evaluatorFieldValues[j].getType()){
452
                    EvaluatorFieldValueMatch evaluatorFieldValueMatch = (EvaluatorFieldValueMatch)evaluatorFieldValues[j];
453
                    Object area = evaluatorFieldValueMatch.getValue();
454
                    if (area instanceof Envelope){
455
                        return executeSpatialQueryFromEnvelope(evaluatorFieldValueMatch.getFieldName(),
456
                            (Envelope)area);					
457
                    }else if (area instanceof Geometry){
458
                        return executeSpatialQueryFromGeometry(evaluatorFieldValueMatch.getFieldName(),
459
                            (Geometry)area);						
460
                    }
461
                }
462
            }			
463
        }
464
        return null;
465
    }
466

  
467
    private File executeSpatialQueryFromGeometry(String the_geom, Geometry geometry) throws DataException{
468
        wfsStatus.setFilterByArea(geometry, the_geom, wfsStatus.getSrs(), 
469
            FilterEncoding.GEOMETRIC_OPERATOR_CONTAINS);
470
        return executeSpatialQuery();
471
    }
472

  
473
    private File executeSpatialQueryFromEnvelope(String the_geom, Envelope envelope) throws DataException{
474
        wfsStatus.setFilterByArea(envelope, the_geom, wfsStatus.getSrs(), 
475
            FilterEncoding.GEOMETRIC_OPERATOR_CONTAINS);		
476
        return executeSpatialQuery();
477
    }
478

  
479
    private File executeSpatialQuery() throws DataException{
480
        try {
481
            wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST);
482
            //If it is not possible to calculate the 
483
            wfsStatus.setResultType(WFSStatus.RESULTYPE_RESULTS);
484
            return wfsClient.getFeature(wfsStatus, getWFSParameters().getIgnoreCache(), null);
485
        } catch (WFSException e) {
486
            throw new InitializeException("Impossible to retrieve the file", e);
487
        }
488
    }		
489

  
490
    public Object getSourceId() {
491
        StringBuffer sourceID = new StringBuffer(getWFSParameters().getUrl());
492
        sourceID.append("_" + getWFSParameters().getFeatureType());
493
        int hash = sourceID.hashCode();
494
        if (sourceID.length() > 60){
495
            return sourceID.substring(0, 60) + "_" + hash;
496
        }else{
497
            return sourceID.toString() + "_" + hash;
498
        }
499
    }
500
   
501
    public Object createNewOID() {        
502
        try {
503
            return String.valueOf(getFeatureCount()+1);
504
        } catch (DataException e) {
505
            return String.valueOf(Math.random());
506
        }
507
    }
508

  
509
    public long getFeatureCount() throws DataException {
510
        if (featureCount == -1){
511
            wfsStatus.setResultType(WFSStatus.RESULTYPE_HITS);
512
            try {
513
                //The filter encoding is better supported using POST
514
                if (hasFilterByArea){
515
                    wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST);
516
                }else{
517
                    wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_GET);
518
                }
519
                File file = wfsClient.getFeature(wfsStatus, getWFSParameters().getIgnoreCache(), null);
520
                featureCount = ((WFSGetFeatureRequestInformation)wfsClient.getLastWfsRequestInformation()).getNumberOfFeatures();
521
                //If the service doesn't support RESULTTYPE_HITS, parse the file and get the FeatureCount
522
                if (featureCount == -1){
523
                    storeProviderDelegate = createProvider(file);
524
                    featureCount = storeProviderDelegate.getFeatureCount();
525
                }
526
            } catch (WFSException e) {
527
                throw new ConnectionServerException("Error calculating the feature count", e);
528
            }
529
        }
530
        return featureCount;
531
    }
532

  
533
    public int getOIDType() {
534
        return DataTypes.STRING;
535
    }
536

  
537
    public ResourceProvider getResource() {
538
        return storeProviderDelegate.getResource();
539
    }
540

  
541
    protected FeatureProvider internalGetFeatureProviderByReference(
542
        FeatureReferenceProviderServices reference, FeatureType featureType)
543
    throws DataException {
544
        return storeProviderDelegate.internalGetFeatureProviderByReference(reference, featureType);
545
    }
546

  
547
    public String getFullName() {       
548
        return getWFSParameters().getUrl() + "_" + getWFSParameters().getFeatureType();
549
    }
550

  
551
    public String getName() {        
552
        return getWFSParameters().getFeatureType();
553
    }
554

  
555
    public boolean isKnownEnvelope(){  
556
        return isKnownEnvelope;
557
    }
558

  
559
    public boolean hasRetrievedFeaturesLimit(){
560
        return true;
561
    }
562

  
563
    public int getRetrievedFeaturesLimit(){
564
        //WFS 1.0.0 can not know where is the limit
565
        if (getWFSParameters().getVersion().equals("1.0.0")){
566
            return 0;
567
        }else{
568
            return wfsClient.getServiceInformation().getMaxFeatures();
569
        }
570
    }
571

  
572
    public void performChanges(Iterator deleteds, Iterator inserteds,
573
        Iterator updateds, Iterator featureTypesChanged)
574
    throws DataException {
575
        wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST);
576
        WFSTTransactionBuilder transactionBuilder = new WFSTTransactionBuilder(wfsStatus, wfsClient);
577

  
578
        //Create the Query
579
        try {
580
            //Add new features
581
            while (inserteds.hasNext()){
582
                transactionBuilder.addInsertFeature((FeatureProvider)inserteds.next());
583
            }
584
            //Add deleted features
585
            while (deleteds.hasNext()){
586
                transactionBuilder.addDeleteFeature(
587
                    internalGetFeatureProviderByReference((FeatureReferenceProviderServices)deleteds.next(), null).getOID().toString());;
588
            }
589
            //Add updated features
590
            while (updateds.hasNext()){
591
                transactionBuilder.addUpdateFeature((FeatureProvider)updateds.next());
592
            }
593
        } catch (WriterHandlerCreationException e) {
594
            throw new WFSTTRansactionException(e);
595
        } catch (GeometryOperationNotSupportedException e) {
596
            throw new WFSTTRansactionException(e);
597
        } catch (GeometryOperationException e) {
598
            throw new WFSTTRansactionException(e);
599
        }
600
        
601
        //Send the query to the server
602
        try {
603
            wfsClient.transaction(wfsStatus, true, null);
604
            WFSTransactionRequestInformation transactionRequestInformation =  (WFSTransactionRequestInformation)wfsClient.getLastWfsRequestInformation();
605
            if (transactionRequestInformation.getStatus() == WFSTransactionRequestInformation.STATUS_FAILED){
606
                throw new WFSTTRansactionException(transactionRequestInformation.getMessage());
607
            }
608
        } catch (WFSException e) {
609
            throw new WFSTTRansactionException(e);
610
        }
611
    }
612

  
613
    public boolean allowWrite() {
614
        return wfsClient.getServiceInformation().isOperationSupported("Transaction");
615
    }
616

  
617
    public Envelope getEnvelope() throws DataException {        
618
        return (Envelope) this.getDynValue("Envelope");
619
    }
620

  
621
    public FeatureProvider createFeatureProvider(FeatureType type)
622
    throws DataException {       
623
        return super.createFeatureProvider(type);
624
    }
625

  
626

  
627
}
628

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/wfs/WFSTTRansactionException.java
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
package org.gvsig.fmap.dal.store.wfs;
23

  
24
import org.gvsig.fmap.dal.exception.DataException;
25

  
26

  
27
/**
28
 * @author gvSIG Team
29
 * @version $Id$
30
 *
31
 */
32
public class WFSTTRansactionException extends DataException {
33
   private static final long serialVersionUID = -5529148262961765052L;
34

  
35
   private final static String MESSAGE_FORMAT = "Can't write the feature.";
36
   private final static String MESSAGE_KEY = "_WFSTTranscationException";
37

  
38
   public WFSTTRansactionException(Throwable cause) {
39
       super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);  
40
   }
41
   
42
   public WFSTTRansactionException(String message) {
43
       super(message, MESSAGE_KEY, serialVersionUID);  
44
   }
45
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/wfs/WFSFeatureFiller.java
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
package org.gvsig.fmap.dal.store.wfs;
23

  
24
import java.io.File;
25
import java.io.FileInputStream;
26
import java.io.FileNotFoundException;
27
import java.util.Iterator;
28

  
29
import org.gvsig.remoteclient.wfs.WFSFeature;
30
import org.gvsig.tools.dataTypes.DataType;
31
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator;
32
import org.gvsig.xmlschema.lib.api.XMLSchemaManager;
33
import org.gvsig.xmlschema.lib.api.exceptions.SchemaCreationException;
34
import org.gvsig.xmlschema.lib.api.som.IXSComplexContent;
35
import org.gvsig.xmlschema.lib.api.som.IXSComplexTypeDefinition;
36
import org.gvsig.xmlschema.lib.api.som.IXSContentType;
37
import org.gvsig.xmlschema.lib.api.som.IXSElementDeclaration;
38
import org.gvsig.xmlschema.lib.api.som.IXSExtension;
39
import org.gvsig.xmlschema.lib.api.som.IXSGroup;
40
import org.gvsig.xmlschema.lib.api.som.IXSRestriction;
41
import org.gvsig.xmlschema.lib.api.som.IXSSchema;
42
import org.gvsig.xmlschema.lib.api.som.IXSSimpleContent;
43
import org.gvsig.xmlschema.lib.api.som.IXSSimpleTypeDefinition;
44
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

  
48

  
49
/**
50
 * @author gvSIG Team
51
 * @version $Id$
52
 *
53
 */
54
public class WFSFeatureFiller {
55
   private static final Logger LOG = LoggerFactory.getLogger(WFSFeatureFiller.class);
56
    private XMLSchemaManager xmlSchemaManager = null;
57
    private static final String XMLSCHEMA_PARSER_PROVIDER_NAME = "xmlschema.providers.kxml";
58
    private WFSFeature feature;
59
    
60
    public WFSFeatureFiller(WFSFeature feature) {
61
        super();
62
        xmlSchemaManager =  XMLSchemaLocator.getXMLSchemaManager();
63
        this.feature = feature;
64
    }
65

  
66
    /**
67
     * @param describeFeatureTypeFile
68
     * @param feature
69
     * @throws FileNotFoundException 
70
     * @throws SchemaCreationException 
71
     */
72
    public void fill(File describeFeatureTypeFile) throws SchemaCreationException, FileNotFoundException {
73
        IXSSchema schema = xmlSchemaManager.parse(XMLSCHEMA_PARSER_PROVIDER_NAME, new FileInputStream(describeFeatureTypeFile));
74
        IXSElementDeclaration elementDeclaration = null;
75
        if (feature.getNamespace() == null){
76
            elementDeclaration = schema.getElementDeclarationByName(null, feature.getName()); 
77
        }else{
78
            elementDeclaration = schema.getElementDeclarationByName(feature.getNamespace().getLocation(), feature.getLocalName());
79
        }
80
        if (elementDeclaration == null){
81
            return;
82
        }
83
        IXSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
84
        if (typeDefinition == null){
85
            return;
86
        }
87
        if (typeDefinition instanceof IXSSimpleTypeDefinition){
88
            
89
        }else if (typeDefinition instanceof IXSComplexTypeDefinition){ 
90
            fill((IXSComplexTypeDefinition)typeDefinition);
91
        }
92
        feature.setCompleted(true);
93
    }
94

  
95
    /**
96
     * @param typeDefinition
97
     */
98
    private void fill(IXSComplexTypeDefinition complexTypeDefinition) {
99
        IXSContentType contentType = complexTypeDefinition.getContentType();
100
        if (contentType != null){
101
            fill((IXSContentType)contentType);
102
        }
103
        IXSGroup group = complexTypeDefinition.getGroup();
104
        if (group != null){
105
            fill((IXSGroup)contentType);
106
        }        
107
    }
108

  
109
    /**
110
     * @param complexTypeDefinition
111
     */
112
    private void fill(IXSGroup group) {
113
        Iterator it = group.getItems().iterator();
114
        while (it.hasNext()){
115
            Object item = it.next();
116
            if (item instanceof IXSElementDeclaration){
117
                IXSElementDeclaration elementDeclaration = (IXSElementDeclaration)item;       
118
                DataType dataType = null;
119
                if (elementDeclaration.getTypeDefinition() != null){
120
                    dataType = elementDeclaration.getTypeDefinition().getDataType();
121
                }
122
                
123
                if (dataType == null || elementDeclaration.getNodeName() == null) {
124
                    LOG.info("Feature attribute type not recognized: "
125
                        + elementDeclaration.toString(),
126
                        new Exception("Feature attribute type not recognized: "
127
                        + elementDeclaration.toString()));
128
                } else {
129
                    feature.addField(elementDeclaration.getNodeName(), elementDeclaration.getTypeName(), dataType);
130
                }
131
                       
132
            }else {
133
                LOG.info("Feature attribute not recognized: "
134
                    + (item == null ? "NULL" : item.getClass().getName()),
135
                        new Exception("Feature attribute not recognized"));
136
            }               
137
        }      
138
    }
139

  
140
    /**
141
     * @param complexTypeDefinition
142
     */
143
    private void fill(IXSContentType contentType) {
144
        if (contentType instanceof IXSSimpleContent){
145
           fill((IXSSimpleContent)contentType);
146
        }else if (contentType instanceof IXSComplexContent){
147
            fill((IXSComplexContent)contentType);
148
        }else if (contentType instanceof IXSGroup){
149
           fill((IXSGroup)contentType);
150
        }        
151
    }
152
    
153
    private void fill(IXSSimpleContent simpleContent) {
154
        IXSRestriction restriction = simpleContent.getRestriction();
155
        if (restriction != null){
156
            fill(restriction);
157
        }
158
        IXSExtension extension = simpleContent.getExtension();
159
        if (extension != null){
160
            fill(extension);
161
        }
162
    }
163
    
164
    private void fill(IXSComplexContent complexContent) {
165
        IXSRestriction restriction = complexContent.getRestriction();
166
        if (restriction != null){
167
            fill(restriction);
168
        }
169
        IXSExtension extension = complexContent.getExtension();
170
        if (extension != null){
171
            fill(extension);
172
        }
173
    }
174

  
175
    /**
176
     * @param extension
177
     */
178
    private void fill(IXSExtension extension) {
179
        IXSGroup group = extension.getGroup();
180
        if (group != null){
181
            fill(group);
182
        }        
183
    }
184

  
185
    /**
186
     * @param restriction
187
     */
188
    private void fill(IXSRestriction restriction) {
189
        IXSGroup group = restriction.getGroup();
190
        if (group != null){
191
            fill(group);
192
        }            
193
    }
194
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.5/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/wfs/WFSStoreParameters.java
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.store.wfs;
29

  
30
import org.apache.commons.lang3.BooleanUtils;
31
import org.gvsig.fmap.dal.DataParameters;
32
import org.gvsig.fmap.dal.DataStoreParameters;
33
import org.gvsig.fmap.dal.DataTypes;
34
import org.gvsig.fmap.dal.exception.InitializeException;
35
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
36
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DelegatedDynObject;
40
import org.gvsig.tools.dynobject.DynClass;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43

  
44
/**
45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
46
 */
47
public class WFSStoreParameters extends AbstractDataParameters implements
48
 DataStoreParameters{
49
	protected static DynClass DYNCLASS = null;
50
	public static final String DYNCLASS_NAME = "WFSStoreParameters";
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff