Revision 284

View differences:

org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.40/org.gvsig.wfs.app.mainplugin/buildNumber.properties
1
#Mon Jun 06 04:05:16 CEST 2016
2
buildNumber=2122
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.40/org.gvsig.wfs.app.mainplugin/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.store.wfs.WFSLibrary
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.40/org.gvsig.wfs.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25
<!--
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
      <useTransitiveDependencies>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes>
32
        <include>org.gvsig:org.gvsig.wfs.app.mainplugin</include>
33
      </includes>
34
    </dependencySet>
35
  </dependencySets>
36
-->
37

  
38
</assembly>
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.40/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.AbstractDataServerExplorer;
47
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
48
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
49
import org.gvsig.fmap.dal.store.wfs.WFSFeatureFiller;
50
import org.gvsig.fmap.dal.store.wfs.WFSStoreParameters;
51
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider;
52
import org.gvsig.remoteclient.wfs.WFSClient;
53
import org.gvsig.remoteclient.wfs.WFSFeature;
54
import org.gvsig.remoteclient.wfs.WFSStatus;
55
import org.gvsig.remoteclient.wfs.exceptions.WFSException;
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 AbstractDataServerExplorer 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(parameters, services);
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, getParameters().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
    @Override
186
    public WFSServerExplorerParameters getParameters() {
187
        return (WFSServerExplorerParameters) super.getParameters();
188
    }
189

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

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

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

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

  
230
    }
231

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

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

  
247
    }
248

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

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

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

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

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

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

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

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

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

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

  
331
    public List getDataStoreProviderNames() {
332
        List x = new ArrayList();
333
        x.add(WFSStoreProvider.NAME);
334
        return x;
335
    }	
336
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.40/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.40/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.cresques.cts.IProjection;
32
import org.gvsig.fmap.dal.DataParameters;
33
import org.gvsig.fmap.dal.DataStoreParameters;
34
import org.gvsig.fmap.dal.DataTypes;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
37
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.primitive.Envelope;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DelegatedDynObject;
42
import org.gvsig.tools.dynobject.DynClass;
43
import org.gvsig.tools.dynobject.DynStruct;
44
import org.gvsig.tools.persistence.PersistenceManager;
45

  
46
/**
47
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
48
 */
49
public class WFSStoreParameters extends AbstractDataParameters implements
50
 DataStoreParameters{
51
	protected static DynClass DYNCLASS = null;
52
	public static final String DYNCLASS_NAME = "WFSStoreParameters";
53

  
54
	public static final String DYNFIELDNAME_URL = "url";
55
	public static final String DYNFIELDNAME_VERSION = "version";
56
	public static final String DYNFIELDNAME_TYPENAME = "typeName";
57
	public static final String DYNFIELDNAME_NAMESPACE = "namespace";
58
	public static final String DYNFIELDNAME_NAMESPACEPREFIX = "namespacePrefix";
59
	public static final String DYNFIELDNAME_FIELDS = "fields";
60
	public static final String DYNFIELDNAME_FILTER_ENCODING_BY_ATTRIBUTE = "filterEncodingByAttribute";
61
	public static final String DYNFIELDNAME_MAXFEATURES = "maxFeatures";
62
	public static final String DYNFIELDNAME_TIMEOUT = "timeOut";
63
	public static final String DYNFIELDNAME_USER = "user";
64
	public static final String DYNFIELDNAME_PASSWORD = "password";
65
	public static final String DYNFIELDNAME_FILTER_BY_AREA_GEOMETRY = "filterByAreaGeometry";
66
	public static final String DYNFIELDNAME_FILTER_BY_AREA_ENVELOPE = "filterByAreaEnvelope";
67
	public static final String DYNFIELDNAME_FILTER_BY_AREA_OPERATION = "filterByAreaOperation";
68
	public static final String DYNFIELDNAME_FILTER_BY_AREA_ATTRIBUTE = "filterByAreaAttribute";
69
	public static final String DYNFIELDNAME_FILTER_BY_AREA_CRS = "filterByAreaCrs";
70
	public static final String DYNFIELDNAME_CRS = "Crs";
71

  
72
	private DelegatedDynObject delegatedDynObject;
73

  
74
	public WFSStoreParameters() {
75
		super();
76
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
77
		.getDynObjectManager().createDynObject(
78
			WFSStoreParameters.DYNCLASS);
79
	}
80

  
81
	@Override
82
	protected DelegatedDynObject getDelegatedDynObject() {
83
		return delegatedDynObject;
84
	}
85

  
86
	public WFSStoreParameters(DataParameters dataParameters) throws InitializeException, ProviderNotRegisteredException{
87
		this();
88
		setUrl((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_URL));
89
		String namespace = null;
90
		String namespacePrefix = null;
91
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_NAMESPACE)){
92
			namespace = (String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_NAMESPACE);
93
		}
94
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_NAMESPACEPREFIX)){
95
			namespacePrefix = (String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_NAMESPACEPREFIX);
96
		}
97
		setFeatureType(namespacePrefix, namespace,
98
				(String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_TYPENAME));
99
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_MAXFEATURES)){
100
			setMaxFeatures((Integer)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_MAXFEATURES));
101
		}else{
102
			setMaxFeatures(1000);
103
		}
104
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_TIMEOUT)){
105
			setTimeOut((Integer)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_TIMEOUT));
106
		}else{
107
			setTimeOut(10000);
108
		}
109
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_GEOMETRY)){
110
			setFilterByAreaGeometry((Geometry)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_GEOMETRY));
111
			setFilterByAreaAttribute((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_ATTRIBUTE));
112
			setFilterByAreaCrs((IProjection)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_CRS));
113
			setFilterByAreaOperation((Integer)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_OPERATION));
114
		}
115
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_ENVELOPE)){
116
			setFilterByAreaEnvelope((Envelope)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_ENVELOPE));
117
			setFilterByAreaAttribute((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_ATTRIBUTE));
118
			setFilterByAreaCrs((IProjection)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_CRS));
119
			setFilterByAreaOperation((Integer)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_BY_AREA_OPERATION));
120
		}
121
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_VERSION)){
122
			setVersion((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_VERSION));
123
		}
124
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_ENCODING_BY_ATTRIBUTE)){
125
			setFilterEncodingByAttribute((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_FILTER_ENCODING_BY_ATTRIBUTE));
126
		}
127
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_USER)){
128
			setUser((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_USER));
129
		}
130
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_PASSWORD)){
131
			setPassword((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_PASSWORD));
132
		}
133
		if (dataParameters.hasDynValue(WFSStoreParameters.DYNFIELDNAME_CRS)){
134
			setCrs((String)dataParameters.getDynValue(WFSStoreParameters.DYNFIELDNAME_CRS));
135
		}
136
	}
137

  
138
	protected static void registerDynClass() {
139
		if (DYNCLASS == null) {
140
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
141
			DynStruct definition = manager.addDefinition(
142
					WFSStoreParameters.class,
143
					DYNCLASS_NAME,
144
					"WFSStoreParameters Persistence definition",
145
					null,
146
					null
147
			);
148
			definition.addDynFieldString(DYNFIELDNAME_URL)
149
				.setDescription("URL of the WFS server")
150
				.setMandatory(true);
151

  
152
			definition.addDynFieldString(DYNFIELDNAME_VERSION)
153
				.setDescription("Version of the WFS server")
154
				.setMandatory(false);
155

  
156
			definition.addDynFieldString(DYNFIELDNAME_TYPENAME)
157
				.setDescription("Feature type to retrieve")
158
				.setMandatory(true);
159

  
160
			definition.addDynFieldString(DYNFIELDNAME_NAMESPACE)
161
				.setDescription("Namespace of the feature type to retrieve")
162
				.setMandatory(false);
163

  
164
			definition.addDynFieldString(DYNFIELDNAME_NAMESPACEPREFIX)
165
				.setDescription("Prefix of the namespace of the feature type to retrieve")
166
				.setMandatory(false);
167

  
168
			definition.addDynFieldString(DYNFIELDNAME_FIELDS)
169
				.setDescription("Fields to retrieve separated by ','")
170
				.setMandatory(false);
171

  
172
			definition.addDynFieldString(DYNFIELDNAME_FILTER_ENCODING_BY_ATTRIBUTE)
173
				.setDescription("Filter encoding request")
174
				.setMandatory(false);
175

  
176
			definition.addDynFieldInt(DYNFIELDNAME_MAXFEATURES)
177
				.setDescription("Number of features to retrieve")
178
				.setMandatory(false);
179

  
180
			definition.addDynFieldInt(DYNFIELDNAME_TIMEOUT)
181
				.setDescription("Timeout")
182
				.setMandatory(false);
183

  
184
			definition.addDynFieldString(DYNFIELDNAME_USER)
185
				.setDescription("User name (not used at this moment)")
186
				.setMandatory(false);
187

  
188
			definition.addDynFieldString(DYNFIELDNAME_PASSWORD)
189
				.setDescription("Password (not used at this moment")
190
				.setMandatory(false);
191

  
192
			definition.addDynFieldObject(DYNFIELDNAME_FILTER_BY_AREA_GEOMETRY)
193
				.setType(DataTypes.GEOMETRY)
194
				.setDescription("Geometry used to do the filter")
195
				.setMandatory(false);
196

  
197
			definition.addDynFieldObject(DYNFIELDNAME_FILTER_BY_AREA_ENVELOPE)
198
			.setType(DataTypes.ENVELOPE)
199
			.setDescription("Envelope used to do the filter")
200
			.setMandatory(false);
201

  
202
			definition.addDynFieldInt(DYNFIELDNAME_FILTER_BY_AREA_OPERATION)
203
				.setDescription("Geometry operation used to do the filter")
204
				.setMandatory(false);
205

  
206
			definition.addDynFieldString(DYNFIELDNAME_FILTER_BY_AREA_ATTRIBUTE)
207
				.setDescription("Attribute that contains the geometry")
208
				.setMandatory(false);
209

  
210
			definition.addDynFieldObject(DYNFIELDNAME_FILTER_BY_AREA_CRS)
211
			.setType(DataTypes.CRS)
212
			.setDescription("CRS to do the spatial filter of the query")
213
			.setMandatory(false);
214

  
215
			definition.addDynFieldString(DYNFIELDNAME_CRS)
216
			.setDescription("CRS")
217
			.setMandatory(false);
218

  
219
			definition.addDynFieldBoolean("useAxisOrderYX")
220
                                .setDefaultFieldValue("false")
221
				.setMandatory(false);
222

  
223
			definition.addDynFieldBoolean("ignoreCache")
224
                                .setDefaultFieldValue("false")
225
				.setMandatory(false);
226

  
227
			DYNCLASS = (DynClass) definition;
228
		}
229
	}
230

  
231
	/* (non-Javadoc)
232
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName()
233
	 */
234
	public String getDataStoreName() {
235
		return WFSStoreProvider.NAME;
236
	}
237

  
238
	/* (non-Javadoc)
239
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDescription()
240
	 */
241
	public String getDescription() {
242
		return WFSStoreProvider.DESCRIPTION;
243
	}
244

  
245
	/* (non-Javadoc)
246
	 * @see org.gvsig.fmap.dal.DataStoreParameters#isValid()
247
	 */
248
	public boolean isValid() {
249
		// TODO Auto-generated method stub
250
		return false;
251
	}
252

  
253
	public String getUrl(){
254
		return (String) this.getDynValue(DYNFIELDNAME_URL);
255
	}
256

  
257
	public void setUrl(String url){
258
		this.setDynValue(DYNFIELDNAME_URL, url);
259
	}
260

  
261
	public String getVersion(){
262
		return (String) this.getDynValue(DYNFIELDNAME_VERSION);
263
	}
264

  
265
	public void setVersion(String version){
266
		this.setDynValue(DYNFIELDNAME_VERSION, version);
267
	}
268

  
269
	public String getFeatureType(){
270
		return (String) this.getDynValue(DYNFIELDNAME_TYPENAME);
271
	}
272

  
273
	public void setFeatureType(String featureType){
274
		this.setDynValue(DYNFIELDNAME_TYPENAME, featureType);
275
	}
276

  
277
	public void setFeatureType(String namespace, String featureType){
278
		this.setDynValue(DYNFIELDNAME_NAMESPACE, namespace);
279
		this.setDynValue(DYNFIELDNAME_TYPENAME, featureType);
280
	}
281

  
282
	public void setFeatureType(String prefix, String namespace, String featureType){
283
		this.setDynValue(DYNFIELDNAME_NAMESPACEPREFIX, prefix);
284
		this.setDynValue(DYNFIELDNAME_NAMESPACE, namespace);
285
		this.setDynValue(DYNFIELDNAME_TYPENAME, featureType);
286
	}
287

  
288
	public String getFeatureNamespace(){
289
		return (String) this.getDynValue(DYNFIELDNAME_NAMESPACE);
290
	}
291

  
292
	public String getFeaturePrefix(){
293
		return (String) this.getDynValue(DYNFIELDNAME_NAMESPACEPREFIX);
294
	}
295

  
296
	public String getFields(){
297
		return (String) this.getDynValue(DYNFIELDNAME_FIELDS);
298
	}
299

  
300
	public void setFields(String fields){
301
		this.setDynValue(DYNFIELDNAME_FIELDS, fields);
302
	}
303

  
304
	public String getFilterEncodingByAttribute(){
305
		return (String) this.getDynValue(DYNFIELDNAME_FILTER_ENCODING_BY_ATTRIBUTE);
306
	}
307

  
308
	public void setFilterEncodingByAttribute(String filter){
309
		this.setDynValue(DYNFIELDNAME_FILTER_ENCODING_BY_ATTRIBUTE, filter);
310
	}
311

  
312
	public Integer getMaxFeatures(){
313
		return (Integer) this.getDynValue(DYNFIELDNAME_MAXFEATURES);
314
	}
315

  
316
	public void setMaxFeatures(Integer maxFeatures){
317
		this.setDynValue(DYNFIELDNAME_MAXFEATURES, maxFeatures);
318
	}
319

  
320
	public Integer getTimeOut(){
321
		return (Integer) this.getDynValue(DYNFIELDNAME_TIMEOUT);
322
	}
323

  
324
	public void setTimeOut(Integer timeOut){
325
		this.setDynValue(DYNFIELDNAME_TIMEOUT, timeOut);
326
	}
327

  
328
	public String getUser(){
329
		return (String) this.getDynValue(DYNFIELDNAME_USER);
330
	}
331

  
332
	public void setUser(String user){
333
		this.setDynValue(DYNFIELDNAME_USER, user);
334
	}
335

  
336
	public String getPassword(){
337
		return (String) this.getDynValue(DYNFIELDNAME_PASSWORD);
338
	}
339

  
340
	public void setPassword(String password){
341
		this.setDynValue(DYNFIELDNAME_PASSWORD, password);
342
	}
343

  
344
	public Geometry getFilterByAreaGeometry(){
345
		return (Geometry) this.getDynValue(DYNFIELDNAME_FILTER_BY_AREA_GEOMETRY);
346
	}
347

  
348
	public void setFilterByAreaGeometry(Geometry area){
349
		this.setDynValue(DYNFIELDNAME_FILTER_BY_AREA_GEOMETRY, area);
350
	}
351

  
352
	public Envelope getFilterByAreaEnvelope(){
353
		return (Envelope) this.getDynValue(DYNFIELDNAME_FILTER_BY_AREA_ENVELOPE);
354
	}
355

  
356
	public void setFilterByAreaEnvelope(Envelope area){
357
		this.setDynValue(DYNFIELDNAME_FILTER_BY_AREA_ENVELOPE, area);
358
	}
359

  
360
	public Integer getFilterByAreaOperation(){
361
		return (Integer) this.getDynValue(DYNFIELDNAME_FILTER_BY_AREA_OPERATION);
362
	}
363

  
364
	public void setFilterByAreaOperation(Integer operation){
365
		this.setDynValue(DYNFIELDNAME_FILTER_BY_AREA_OPERATION, operation);
366
	}
367

  
368
	public IProjection getFilterByAreaCrs(){
369
		return (IProjection) this.getDynValue(DYNFIELDNAME_FILTER_BY_AREA_CRS);
370
	}
371

  
372
	public void setFilterByAreaCrs(IProjection crs){
373
		this.setDynValue(DYNFIELDNAME_FILTER_BY_AREA_CRS, crs);
374
	}
375

  
376
	public String getCrs(){
377
		return (String) this.getDynValue(DYNFIELDNAME_CRS);
378
	}
379

  
380
	public void setCrs(String crs){
381
		this.setDynValue(DYNFIELDNAME_CRS, crs);
382
	}
383

  
384
	public String getFilterByAreaAttribute(){
385
		return (String) this.getDynValue(DYNFIELDNAME_FILTER_BY_AREA_ATTRIBUTE);
386
	}
387

  
388
	public void setFilterByAreaAttribute(String attribute){
389
		this.setDynValue(DYNFIELDNAME_FILTER_BY_AREA_ATTRIBUTE, attribute);
390
	}
391

  
392
	public boolean getUseAxisOrderYX() {
393
            Boolean x = (Boolean) this.getDynValue("useAxisOrderYX");
394
            return BooleanUtils.isTrue(x);
395
	}
396

  
397
	public void setUseAxisOrderYX(boolean useAxisOrderYX){
398
            this.setDynValue("useAxisOrderYX", new Boolean(useAxisOrderYX));
399
	}
400

  
401
        public boolean getIgnoreCache() {
402
            Boolean x = (Boolean) this.getDynValue("ignoreCache");
403
            return BooleanUtils.isTrue(x);
404
	}
405

  
406
	public void setIgnoreCache(boolean ignoreCache){
407
            this.setDynValue("ignoreCache", new Boolean(ignoreCache));
408
	}
409
}
410

  
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.40/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/wfs/WFSTTransactionBuilder.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.ByteArrayOutputStream;
25
import java.io.OutputStream;
26

  
27
import org.gvsig.fmap.dal.DataTypes;
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
30
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
35
import org.gvsig.gpe.lib.api.GPELocator;
36
import org.gvsig.gpe.lib.api.GPEManager;
37
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerCreationException;
38
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandler;
39
import org.gvsig.remoteclient.wfs.WFSClient;
40
import org.gvsig.remoteclient.wfs.WFSStatus;
41
import org.gvsig.remoteclient.wfs.edition.WFSTAttributesOperation;
42
import org.gvsig.remoteclient.wfs.edition.WFSTInsertOperation;
43
import org.gvsig.remoteclient.wfs.edition.WFSTTransaction;
44
import org.gvsig.remoteclient.wfs.edition.WFSTUpdateOperation;
45

  
46

  
47
/**
48
 * @author gvSIG Team
49
 * @version $Id$
50
 *
51
 */
52
public class WFSTTransactionBuilder {
53
    private WFSStatus wfsStatus;
54
    private WFSClient wfsClient;
55
    private static final GPEManager gpeManager = GPELocator.getGPEManager();
56
    private WFSTTransaction transaction = null;
57
    
58
    public WFSTTransactionBuilder(WFSStatus wfsStatus, WFSClient wfsClient) {
59
        super();
60
        this.wfsStatus = wfsStatus;
61
        this.wfsClient = wfsClient;
62
        transaction = wfsStatus.createNewTransaction();
63
    }  
64
    
65
    private void addFeatureAttributes(WFSTAttributesOperation attributesOperation, FeatureProvider featureProvider) throws WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException{
66
        for (int i=0 ; i<featureProvider.getType().size() ; i++){
67
            FeatureAttributeDescriptor featureAttributeDescriptor = featureProvider.getType().getAttributeDescriptor(i);
68
            String attributeValue = "";
69
            if (featureAttributeDescriptor.getType() != DataTypes.GEOMETRY){
70
                if (featureProvider.get(i) != null){
71
                    attributeValue = featureProvider.get(i).toString();
72
                }
73
            }else{
74
                Geometry geometry = (Geometry)featureProvider.get(i);
75
                attributeValue = toGML(geometry, featureAttributeDescriptor.getSRS().getAbrev());               
76
            }  
77
            attributesOperation.addAttribute(featureAttributeDescriptor.getName(), attributeValue);
78
        }
79
    }
80
    
81
    private String toGML(Geometry geometry, String srs) throws GeometryOperationNotSupportedException, GeometryOperationException, WriterHandlerCreationException{
82
        OutputStream os = new ByteArrayOutputStream();
83
        IGPEWriterHandler writerHandler = gpeManager.createWriterByMimeType("text/xml; subtype=gml/3.1.2");  
84
        writerHandler.setOutputStream(os);
85
        writerHandler.initialize();       
86
        GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
87
        geometryOperationContext.setAttribute("writerHandler", writerHandler);
88
        geometryOperationContext.setAttribute("srs", srs);
89
        geometryOperationContext.setAttribute("id", null);
90
        geometry.invokeOperation("writeGml2", geometryOperationContext);
91
        writerHandler.close(); 
92
        //Remove the xml header
93
        String gml = os.toString();
94
        return gml.substring(38, gml.length());
95
    }
96
    
97
    public void addInsertFeature(FeatureProvider featureProvider) throws WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException{
98
        WFSTInsertOperation insertOperation = transaction.createInsertOperation();
99
        addFeatureAttributes(insertOperation, featureProvider);
100
    } 
101

  
102
    public void addUpdateFeature(FeatureProvider featureProvider) throws WriterHandlerCreationException, GeometryOperationNotSupportedException, GeometryOperationException{
103
        WFSTUpdateOperation updateOperation = transaction.createUpdateOperation(featureProvider.getOID().toString());
104
        addFeatureAttributes(updateOperation, featureProvider);
105
    }
106
    
107
    public void addDeleteFeature(String id) throws DataException{
108
        transaction.createDeleteOperation(id);      
109
    }
110
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.40/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.40/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.awt.geom.AffineTransform;
31
import java.io.File;
32
import java.io.IOException;
33
import java.util.ArrayList;
34
import java.util.Iterator;
35
import java.util.List;
36

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

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

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

  
109
	// private IProjection projection;
110
	private long featureCount = -1;
111
	private boolean isKnownEnvelope = false;
112

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

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

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

  
127
	boolean isFilterByAreaSupported = true;
128

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

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

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

  
174
			// Select the filter by area
175

  
176
			Geometry filterByAreaGeometry = wfsParameters
177
					.getFilterByAreaGeometry();
178
			Envelope filterByAreaEnvelope = wfsParameters
179
					.getFilterByAreaEnvelope();
180
			if (filterByAreaGeometry != null) {
181
				wfsStatus.setFilterByArea(filterByAreaGeometry,
182
						wfsParameters.getFilterByAreaAttribute(),
183
						wfsParameters.getFilterByAreaCrs().getFullCode(),
184
						wfsParameters.getFilterByAreaOperation());
185
			} else if (filterByAreaEnvelope != null) {
186
				wfsStatus.setFilterByArea(filterByAreaEnvelope,
187
						wfsParameters.getFilterByAreaAttribute(),
188
						wfsParameters.getFilterByAreaCrs().getFullCode(),
189
						wfsParameters.getFilterByAreaOperation());
190
			}
191
			this.hasFilterByArea = (wfsStatus.getFilterByArea() != null);
192

  
193
			// Select the filter by attribute
194
			wfsStatus.setFilterByAttribute(wfsParameters
195
					.getFilterEncodingByAttribute());
196

  
197
			String _srs = wfsParameters.getCrs();
198
			wfsStatus.setSrs(_srs);
199

  
200
			wfsStatus.setTimeout(wfsParameters.getTimeOut());
201
			wfsStatus.setMaxFeatures(wfsParameters.getMaxFeatures());
202
			wfsStatus.setUserName(wfsParameters.getUser());
203
			wfsStatus.setPassword(wfsParameters.getPassword());
204

  
205
			// Setting the envelope for the layer
206
			wfsClient.getCapabilities(wfsStatus, false, null);
207

  
208
			Envelope envelope = calculateFullEnvelope();
209
			if (envelope != null) {
210
				this.setDynValue("Envelope", envelope);
211
				isKnownEnvelope = true;
212
			}
213
		} catch (WFSException e) {
214
			throw new InitializeException("Impossible to retrieve the file", e);
215
		}
216
	}
217

  
218
	private WFSFeature getSelectedWFSFeature() throws ReadException,
219
			WFSException {
220
		WFSStoreParameters wfsParameters = getWFSParameters();
221

  
222
		return ((WFSServerExplorer) getExplorer()).getFeatureInfo(
223
				wfsParameters.getFeatureNamespace(),
224
				wfsParameters.getFeatureType());
225
	}
226

  
227
	private void initFeatureType() throws WFSException, ReadException {
228
		WFSFeature feature = getSelectedWFSFeature();
229

  
230
		if (feature == null) {
231
			// TODO read from GML
232
			throw new WFSException("It is not possible to parse the schema");
233
		}
234

  
235
		IProjection ipro = null;
236
		try {
237
			ipro = CRSFactory.getCRS(wfsStatus.getSrs());
238
			this.setDynValue("CRS", ipro);
239
		} catch (Exception ex) {
240
			logger.info("Error: did not set CRS in store provider.", ex);
241
		}
242

  
243
		EditableFeatureType featureType = getStoreServices()
244
				.createFeatureType();
245

  
246
		for (int i = 0; i < feature.getFieldSize(); i++) {
247
			WFSFeatureField featureField = feature.getFieldAt(i);
248
			int dataType = DataTypes.STRING;
249
			String typeName = featureField.getType();
250
			EditableFeatureAttributeDescriptor attributeDescriptor = null;
251

  
252
			IXSTypeDefinition typeDefinition = null;
253

  
254
			if (typeName != null) {
255
				typeDefinition = xmlSchemaManager.getTypeDefinition(typeName);
256
			}
257

  
258
			if (typeDefinition != null) {
259
				if (typeDefinition.getDataType() != null) {
260
					if (typeDefinition.getDataType().getType() == DataTypes.GEOMETRY) {
261
						dataType = typeDefinition.getDataType().getType();
262
					}
263
				}
264
				attributeDescriptor = featureType.add(featureField.getName(),
265
						dataType);
266
				if (typeDefinition instanceof IXSGeometryTypeDefinition) {
267

  
268
					if (ipro != null) {
269
						attributeDescriptor.setSRS(ipro);
270
					} else {
271
						if (feature.getSrs().size() > 0) {
272
							attributeDescriptor.setSRS(CRSFactory
273
									.getCRS((String) feature.getSrs().get(0)));
274
						} else {
275
							logger.info("Unable to set CRS in feature type.");
276
						}
277
					}
278

  
279
					attributeDescriptor
280
							.setGeometryType(((IXSGeometryTypeDefinition) typeDefinition)
281
									.getGeometryType());
282
					attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM3D);
283
					featureType.setDefaultGeometryAttributeName(featureField
284
							.getName());
285
				}
286
			} else {
287
				attributeDescriptor = featureType.add(typeName, dataType);
288
			}
289
			// length, relevant for all (strings) except geometry
290
			attributeDescriptor.setSize(128);
291
		}
292
		featureType.setHasOID(true);
293

  
294
		FeatureType defaultType = featureType.getNotEditableCopy();
295
		List types = new ArrayList(1);
296
		types.add(defaultType);
297
		this.getStoreServices().setFeatureTypes(types, defaultType);
298
	}
299

  
300
	private Envelope calculateFullEnvelope() {
301
		GeometryManager geometryManager = GeometryLocator.getGeometryManager();
302

  
303
		try {
304
			WFSFeature feature = getSelectedWFSFeature();
305
			if (feature != null) {
306
				String _srs = wfsStatus.getSrs();
307
				if (_srs != null) {
308

  
309
					BoundaryBox boundaryBox = feature.getBbox(_srs);
310
					// The projection is found
311
					if (boundaryBox != null) {
312
						return geometryManager.createEnvelope(
313
								boundaryBox.getXmin(), boundaryBox.getYmin(),
314
								boundaryBox.getXmax(), boundaryBox.getYmax(),
315
								SUBTYPES.GEOM2D);
316
					}
317
					// Check if there is a latlon envelope
318
					boundaryBox = feature.getLatLonBbox();
319
					if (boundaryBox != null) {
320
						Envelope envelope = geometryManager.createEnvelope(
321
								boundaryBox.getXmin(), boundaryBox.getYmin(),
322
								boundaryBox.getXmax(), boundaryBox.getYmax(),
323
								SUBTYPES.GEOM2D);
324
						if (!"EPSG:4326".equals(_srs)) {
325
							IProjection sourceProjection = CRSFactory
326
									.getCRS("EPSG:4326");
327
							IProjection destinationProjection = CRSFactory
328
									.getCRS(_srs);
329
							if (destinationProjection != null) {
330
								ICoordTrans coordTrans = sourceProjection
331
										.getCT(destinationProjection);
332
								return envelope.convert(coordTrans);
333
							}
334
						}
335
					}
336
				} else {
337
					// If there is not a SRS is thrown a request for the first
338
					// 500 features
339
					int odlMaxFeatures = wfsStatus.getMaxFeatures();
340
					wfsStatus.setMaxFeatures(500);
341
					createSet(null, null);
342
					return storeProviderDelegate.getEnvelope();
343
				}
344
			}
345
		} catch (CreateEnvelopeException e) {
346
			logger.error("Impossible to create an envelope", e);
347
		} catch (ReadException e) {
348
			logger.error("Impossible to create an envelope", e);
349
		} catch (WFSException e) {
350
			logger.error("Impossible to create an envelope", e);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff