root / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / fmap / dal / store / wfs / WFSStoreProvider.java @ 34132
History | View | Annotate | Download (23.7 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.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.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
import org.gvsig.fmap.crs.CRSFactory; |
42 |
import org.gvsig.fmap.dal.DALLocator; |
43 |
import org.gvsig.fmap.dal.DataManager; |
44 |
import org.gvsig.fmap.dal.DataServerExplorer; |
45 |
import org.gvsig.fmap.dal.DataStoreParameters; |
46 |
import org.gvsig.fmap.dal.DataTypes; |
47 |
import org.gvsig.fmap.dal.exception.ConnectionServerException; |
48 |
import org.gvsig.fmap.dal.exception.DataException; |
49 |
import org.gvsig.fmap.dal.exception.InitializeException; |
50 |
import org.gvsig.fmap.dal.exception.OpenException; |
51 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
52 |
import org.gvsig.fmap.dal.exception.ReadException; |
53 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
54 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
55 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
56 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
57 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
58 |
import org.gvsig.fmap.dal.feature.FeatureType; |
59 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
60 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
61 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
62 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
63 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
64 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
65 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorerParameters; |
66 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
67 |
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider; |
68 |
import org.gvsig.fmap.geom.Geometry; |
69 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
70 |
import org.gvsig.fmap.geom.GeometryLocator; |
71 |
import org.gvsig.fmap.geom.GeometryManager; |
72 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
73 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
74 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
75 |
import org.gvsig.fmap.geom.primitive.Envelope; |
76 |
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerCreationException; |
77 |
import org.gvsig.metadata.MetadataLocator; |
78 |
import org.gvsig.metadata.MetadataManager; |
79 |
import org.gvsig.metadata.exceptions.MetadataException; |
80 |
import org.gvsig.remoteclient.ogc.OGCClientOperation; |
81 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
82 |
import org.gvsig.remoteclient.wfs.WFSClient; |
83 |
import org.gvsig.remoteclient.wfs.WFSFeature; |
84 |
import org.gvsig.remoteclient.wfs.WFSFeatureField; |
85 |
import org.gvsig.remoteclient.wfs.WFSStatus; |
86 |
import org.gvsig.remoteclient.wfs.exceptions.WFSException; |
87 |
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding; |
88 |
import org.gvsig.remoteclient.wfs.request.WFSGetFeatureRequestInformation; |
89 |
import org.gvsig.tools.ToolsLocator; |
90 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
91 |
import org.gvsig.tools.dynobject.DynStruct; |
92 |
import org.gvsig.tools.evaluator.EvaluatorFieldValue; |
93 |
import org.gvsig.tools.evaluator.EvaluatorFieldValueMatch; |
94 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
95 |
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator; |
96 |
import org.gvsig.xmlschema.lib.api.XMLSchemaManager; |
97 |
import org.gvsig.xmlschema.lib.api.som.IXSGeometryTypeDefinition; |
98 |
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition; |
99 |
|
100 |
|
101 |
/**
|
102 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
103 |
*/
|
104 |
public class WFSStoreProvider extends AbstractFeatureStoreProvider { |
105 |
private static final Logger logger = LoggerFactory.getLogger(WFSStoreProvider.class); |
106 |
public static String NAME = "WFSStore"; |
107 |
public static String DESCRIPTION = "WFS store to load WFS resources"; |
108 |
|
109 |
private static final MetadataManager metadataManager = MetadataLocator.getMetadataManager(); |
110 |
private static final String METADATA_DEFINITION_NAME = "WFSStore"; |
111 |
private static final String METADATA_DEFINITION_DESCRIPTION = "WFSStore metadata definition"; |
112 |
|
113 |
private IProjection projection;
|
114 |
private int featureCount = -1; |
115 |
private boolean isKnownEnvelope = false; |
116 |
|
117 |
/**
|
118 |
* If the user has selected the filter by area option
|
119 |
*/
|
120 |
private boolean hasFilterByArea = false; |
121 |
|
122 |
/**
|
123 |
* GML provider used by delegation to read the GML files
|
124 |
*/
|
125 |
private GPEStoreProvider storeProviderDelegate = null; |
126 |
|
127 |
private static final DataManager dataManager = DALLocator.getDataManager(); |
128 |
private static final DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
129 |
private static final XMLSchemaManager xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager(); |
130 |
|
131 |
boolean isFilterByAreaSupported = true; |
132 |
|
133 |
//WFS Parameters
|
134 |
private WFSClient wfsClient;
|
135 |
private WFSStatus wfsStatus;
|
136 |
|
137 |
public WFSStoreProvider(DataStoreParameters params,
|
138 |
DataStoreProviderServices storeServices) |
139 |
throws InitializeException {
|
140 |
super(params, storeServices,
|
141 |
ToolsLocator.getDynObjectManager().createDynObject(metadataManager.getDefinition(METADATA_DEFINITION_NAME))); |
142 |
initParams(); |
143 |
try {
|
144 |
initFeatureType(); |
145 |
} catch (WFSException e) {
|
146 |
throw new InitializeException(e); |
147 |
} catch (ReadException e) {
|
148 |
throw new InitializeException(e); |
149 |
} |
150 |
} |
151 |
|
152 |
private void initParams() throws InitializeException{ |
153 |
try {
|
154 |
WFSStoreParameters wfsParameters = getWFSParameters(); |
155 |
try {
|
156 |
if (wfsParameters.getVersion() == null){ |
157 |
wfsClient = new WFSClient(wfsParameters.getUrl());
|
158 |
wfsParameters.setVersion(wfsClient.getVersion()); |
159 |
}else{
|
160 |
wfsClient = new WFSClient(wfsParameters.getUrl(), wfsParameters.getVersion());
|
161 |
} |
162 |
} catch (IOException e) { |
163 |
throw new InitializeException(e); |
164 |
} |
165 |
wfsStatus = new WFSStatus( wfsParameters.getFeatureType(),
|
166 |
wfsParameters.getFeatureNamespace()); |
167 |
wfsStatus.setNamespacePrefix(wfsParameters.getFeaturePrefix()); |
168 |
wfsStatus.setFields(wfsParameters.getFields()); |
169 |
|
170 |
//Select the filter by area
|
171 |
wfsStatus.setFilterByArea(wfsParameters.getFilterByAreaGeometry(), wfsParameters.getFilterByAreaAttribute(), |
172 |
wfsParameters.getFilterByAreaCrs(), wfsParameters.getFilterByAreaOperation()); |
173 |
this.hasFilterByArea = (wfsStatus.getFilterByArea() != null); |
174 |
|
175 |
//Select the filter by attribute
|
176 |
wfsStatus.setFilterByAttribute(wfsParameters.getFilterEncodingByAttribute()); |
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 |
projection = CRSFactory.getCRS(feature.getDefaultSRS()); |
212 |
this.setDynValue("CRS", projection); |
213 |
|
214 |
EditableFeatureType featureType = getStoreServices().createFeatureType(); |
215 |
|
216 |
for (int i=0 ; i<feature.getFieldSize() ; i++){ |
217 |
WFSFeatureField featureField = feature.getFieldAt(i); |
218 |
int dataType = DataTypes.OBJECT;
|
219 |
String typeName = featureField.getType();
|
220 |
EditableFeatureAttributeDescriptor attributeDescriptor = null;
|
221 |
|
222 |
IXSTypeDefinition typeDefinition = xmlSchemaManager.getTypeDefinition(typeName); |
223 |
if (typeDefinition != null){ |
224 |
if (typeDefinition.getDataType() != null){ |
225 |
dataType = typeDefinition.getDataType().getType(); |
226 |
} |
227 |
attributeDescriptor = featureType.add(featureField.getName(), dataType); |
228 |
if (typeDefinition instanceof IXSGeometryTypeDefinition){ |
229 |
if (feature.getSrs().size() > 0){ |
230 |
attributeDescriptor.setSRS(CRSFactory.getCRS((String)feature.getSrs().get(0))); |
231 |
} |
232 |
attributeDescriptor.setGeometryType(((IXSGeometryTypeDefinition)typeDefinition).getGeometryType()); |
233 |
attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM2D); |
234 |
featureType.setDefaultGeometryAttributeName(featureField.getName()); |
235 |
} |
236 |
}else{
|
237 |
attributeDescriptor = featureType.add(typeName, dataType); |
238 |
} |
239 |
} |
240 |
featureType.setHasOID(true);
|
241 |
|
242 |
FeatureType defaultType = featureType.getNotEditableCopy(); |
243 |
List types = new ArrayList(1); |
244 |
types.add(defaultType); |
245 |
this.getStoreServices().setFeatureTypes(types, defaultType);
|
246 |
} |
247 |
|
248 |
private Envelope calculateFullEnvelope() {
|
249 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
250 |
|
251 |
try{
|
252 |
WFSFeature feature = getSelectedWFSFeature(); |
253 |
if (feature != null){ |
254 |
if (feature.getSrs().size() > 0){ |
255 |
String srs = feature.getDefaultSRS();
|
256 |
BoundaryBox boundaryBox = feature.getBbox(srs); |
257 |
if (boundaryBox == null) |
258 |
{ |
259 |
boundaryBox = feature.getBbox(srs); |
260 |
} |
261 |
//The projection is found
|
262 |
if (boundaryBox != null){ |
263 |
return geometryManager.createEnvelope(boundaryBox.getXmin(),
|
264 |
boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D); |
265 |
} |
266 |
//Check if there is a latlon envelope
|
267 |
boundaryBox = feature.getLatLonBbox(); |
268 |
if (boundaryBox != null){ |
269 |
Envelope envelope = geometryManager.createEnvelope(boundaryBox.getXmin(), |
270 |
boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D); |
271 |
IProjection sourceProjection = CRSFactory.getCRS("EPSG:4326");
|
272 |
IProjection destinationProjection = CRSFactory.getCRS(srs); |
273 |
if (destinationProjection != null){ |
274 |
ICoordTrans coordTrans = sourceProjection.getCT(destinationProjection); |
275 |
return envelope.convert(coordTrans);
|
276 |
} |
277 |
} |
278 |
}else{
|
279 |
//If there is not a SRS is thrown a request for the first 500 features
|
280 |
int odlMaxFeatures = wfsStatus.getMaxFeatures();
|
281 |
wfsStatus.setMaxFeatures(500);
|
282 |
createSet(null, null); |
283 |
return storeProviderDelegate.getEnvelope();
|
284 |
} |
285 |
} |
286 |
}catch(CreateEnvelopeException e){
|
287 |
logger.error("Impossible to create an envelope", e);
|
288 |
} catch (ReadException e) {
|
289 |
logger.error("Impossible to create an envelope", e);
|
290 |
} catch (WFSException e) {
|
291 |
logger.error("Impossible to create an envelope", e);
|
292 |
} catch (DataException e) {
|
293 |
logger.error("Impossible to create an envelope", e);
|
294 |
} |
295 |
return null; |
296 |
} |
297 |
|
298 |
private WFSStoreParameters getWFSParameters() {
|
299 |
return (WFSStoreParameters) getParameters();
|
300 |
} |
301 |
|
302 |
/* (non-Javadoc)
|
303 |
* @see org.gvsig.fmap.dal.store.gpe.GPEStoreProvider#open()
|
304 |
*/
|
305 |
public void open() throws OpenException { |
306 |
try {
|
307 |
List featureTypes = this.getFeatureStore().getFeatureTypes(); |
308 |
for (int i=0 ; i<featureTypes.size() ; i++){ |
309 |
FeatureType featureType = (FeatureType)featureTypes.get(i); |
310 |
} |
311 |
} catch (DataException e) {
|
312 |
throw new OpenException("Reading the geometry type", e); |
313 |
} |
314 |
} |
315 |
|
316 |
protected static void registerMetadataDefinition() throws MetadataException { |
317 |
if (metadataManager.getDefinition(METADATA_DEFINITION_NAME) == null) { |
318 |
DynStruct metadataDefinition = metadataManager.addDefinition( |
319 |
METADATA_DEFINITION_NAME, METADATA_DEFINITION_DESCRIPTION); |
320 |
|
321 |
metadataDefinition.addDynFieldObject("Envelope").setClassOfValue(Envelope.class).setMandatory(false); |
322 |
metadataDefinition.addDynFieldObject("CRS").setClassOfValue(IProjection.class).setMandatory(true); |
323 |
|
324 |
metadataDefinition.extend(metadataManager |
325 |
.getDefinition(FeatureStore.METADATA_DEFINITION_NAME)); |
326 |
} |
327 |
} |
328 |
|
329 |
/* (non-Javadoc)
|
330 |
* @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#getExplorer()
|
331 |
*/
|
332 |
public DataServerExplorer getExplorer() throws ReadException { |
333 |
DataManager manager = DALLocator.getDataManager(); |
334 |
WFSServerExplorerParameters params; |
335 |
try {
|
336 |
params = (WFSServerExplorerParameters) manager |
337 |
.createServerExplorerParameters(WFSServerExplorer.NAME); |
338 |
params.setUrl(wfsClient.getHost()); |
339 |
return manager.openServerExplorer(WFSServerExplorer.NAME,params);
|
340 |
} catch (Exception e) { |
341 |
throw new ReadException(this.getName(), e); |
342 |
} |
343 |
} |
344 |
|
345 |
|
346 |
/* (non-Javadoc)
|
347 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getName()
|
348 |
*/
|
349 |
public String getProviderName() { |
350 |
return NAME;
|
351 |
} |
352 |
|
353 |
public FeatureSetProvider createSet(FeatureQuery query)
|
354 |
throws DataException {
|
355 |
return createSet(query, null); |
356 |
} |
357 |
|
358 |
public FeatureSetProvider createSet(FeatureQuery query,
|
359 |
FeatureType featureType) throws DataException {
|
360 |
File file = null; |
361 |
|
362 |
if (query == null){ |
363 |
file = executeQuery(); |
364 |
}else{
|
365 |
//If it is possible to execute a spatial query...
|
366 |
if (query.getFilter() != null){ |
367 |
file = executeSpatialQuery(query); |
368 |
}else{
|
369 |
file = executeQuery(); |
370 |
} |
371 |
|
372 |
} |
373 |
|
374 |
storeProviderDelegate = createProvider(file); |
375 |
return storeProviderDelegate.createSet(query, featureType);
|
376 |
} |
377 |
|
378 |
|
379 |
|
380 |
/**
|
381 |
* It creates the provider that is used to retrieve features from a file.
|
382 |
* @param file
|
383 |
* the file that contains the downloaded file
|
384 |
* @return
|
385 |
* @throws InitializeException
|
386 |
* @throws ProviderNotRegisteredException
|
387 |
*/
|
388 |
private GPEStoreProvider createProvider(File file) throws InitializeException, ProviderNotRegisteredException{ |
389 |
return new GPEStoreProvider(createStoreParameters(file), getStoreServices()); |
390 |
} |
391 |
|
392 |
private DataStoreParameters createStoreParameters(File file) throws InitializeException, ProviderNotRegisteredException{ |
393 |
DataStoreParameters parameters = dataManager.createStoreParameters(GPEStoreProvider.NAME); |
394 |
|
395 |
parameters.setDynValue("File", file.getAbsolutePath());
|
396 |
parameters.setDynValue("Envelope", this.getDynValue("Envelope")); |
397 |
return parameters;
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* It executes a wfs Query without spatial filter
|
402 |
* @throws DataException
|
403 |
*/
|
404 |
private File executeQuery() throws DataException{ |
405 |
try{
|
406 |
wfsStatus.setResultType(WFSStatus.RESULTYPE_RESULTS); |
407 |
if (!hasFilterByArea){
|
408 |
wfsStatus.removeFilterByArea(); |
409 |
} |
410 |
return wfsClient.getFeature(wfsStatus, true, null); |
411 |
} catch (WFSException e) {
|
412 |
throw new InitializeException("Impossible to retrieve the file", e); |
413 |
} |
414 |
} |
415 |
|
416 |
/**
|
417 |
* Executes a new query sending the FilterEncoding request to the server
|
418 |
* @param query
|
419 |
* The Query to send
|
420 |
* @throws InitializeException
|
421 |
* If there is a problem with the request or the parsing process
|
422 |
*/
|
423 |
private File executeSpatialQuery(FeatureQuery query) throws DataException{ |
424 |
EvaluatorFieldsInfo fieldsInfo = query.getFilter().getFieldsInfo(); |
425 |
String[] fields = fieldsInfo.getFieldNames(); |
426 |
for (int i=0 ; i<fields.length ; i++){ |
427 |
EvaluatorFieldValue[] evaluatorFieldValues = fieldsInfo.getFieldValues(fields[i]);
|
428 |
for (int j=0 ; j<evaluatorFieldValues.length ; j++){ |
429 |
if (EvaluatorFieldValue.MATCH == evaluatorFieldValues[j].getType()){
|
430 |
EvaluatorFieldValueMatch evaluatorFieldValueMatch = (EvaluatorFieldValueMatch)evaluatorFieldValues[j]; |
431 |
Object area = evaluatorFieldValueMatch.getValue();
|
432 |
if (area instanceof Envelope){ |
433 |
return executeSpatialQueryFromEnvelope(evaluatorFieldValueMatch.getFieldName(),
|
434 |
(Envelope)area); |
435 |
}else if (area instanceof Geometry){ |
436 |
return executeSpatialQueryFromGeometry(evaluatorFieldValueMatch.getFieldName(),
|
437 |
(Geometry)area); |
438 |
} |
439 |
} |
440 |
} |
441 |
} |
442 |
return null; |
443 |
} |
444 |
|
445 |
private File executeSpatialQueryFromGeometry(String the_geom, Geometry geometry) throws DataException{ |
446 |
wfsStatus.setFilterByArea(geometry, the_geom, projection.getAbrev(), |
447 |
FilterEncoding.GEOMETRIC_OPERATOR_CONTAINS); |
448 |
return executeSpatialQuery();
|
449 |
} |
450 |
|
451 |
private File executeSpatialQueryFromEnvelope(String the_geom, Envelope envelope) throws DataException{ |
452 |
wfsStatus.setFilterByArea(envelope, the_geom, projection.getAbrev(), |
453 |
FilterEncoding.GEOMETRIC_OPERATOR_CONTAINS); |
454 |
return executeSpatialQuery();
|
455 |
} |
456 |
|
457 |
private File executeSpatialQuery() throws DataException{ |
458 |
try {
|
459 |
wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST); |
460 |
//If it is not possible to calculate the
|
461 |
wfsStatus.setResultType(WFSStatus.RESULTYPE_RESULTS); |
462 |
return wfsClient.getFeature(wfsStatus, true, null); |
463 |
} catch (WFSException e) {
|
464 |
throw new InitializeException("Impossible to retrieve the file", e); |
465 |
} |
466 |
} |
467 |
|
468 |
public Object getSourceId() { |
469 |
StringBuffer sourceID = new StringBuffer(getWFSParameters().getUrl()); |
470 |
sourceID.append("_" + getWFSParameters().getFeatureType());
|
471 |
int hash = sourceID.hashCode();
|
472 |
if (sourceID.length() > 60){ |
473 |
return sourceID.substring(0, 60) + "_" + hash; |
474 |
}else{
|
475 |
return sourceID.toString() + "_" + hash; |
476 |
} |
477 |
} |
478 |
|
479 |
public Object createNewOID() { |
480 |
try {
|
481 |
return String.valueOf(getFeatureCount()+1); |
482 |
} catch (DataException e) {
|
483 |
return String.valueOf(Math.random()); |
484 |
} |
485 |
} |
486 |
|
487 |
public long getFeatureCount() throws DataException { |
488 |
if (featureCount == -1){ |
489 |
wfsStatus.setResultType(WFSStatus.RESULTYPE_HITS); |
490 |
try {
|
491 |
wfsClient.getFeature(wfsStatus, true, null); |
492 |
featureCount = ((WFSGetFeatureRequestInformation)wfsClient.getLastWfsRequestInformation()).getNumberOfFeatures(); |
493 |
} catch (WFSException e) {
|
494 |
throw new ConnectionServerException("Error calculating the feature count", e); |
495 |
} |
496 |
} |
497 |
return featureCount;
|
498 |
} |
499 |
|
500 |
public int getOIDType() { |
501 |
return DataTypes.STRING;
|
502 |
} |
503 |
|
504 |
public ResourceProvider getResource() {
|
505 |
return storeProviderDelegate.getResource();
|
506 |
} |
507 |
|
508 |
protected FeatureProvider internalGetFeatureProviderByReference(
|
509 |
FeatureReferenceProviderServices reference, FeatureType featureType) |
510 |
throws DataException {
|
511 |
return storeProviderDelegate.internalGetFeatureProviderByReference(reference, featureType);
|
512 |
} |
513 |
|
514 |
public String getFullName() { |
515 |
return getWFSParameters().getUrl() + "_" + getWFSParameters().getFeatureType(); |
516 |
} |
517 |
|
518 |
public String getName() { |
519 |
return getFullName();
|
520 |
} |
521 |
|
522 |
public boolean isKnownEnvelope(){ |
523 |
return isKnownEnvelope;
|
524 |
} |
525 |
|
526 |
public boolean hasRetrievedFeaturesLimit(){ |
527 |
return true; |
528 |
} |
529 |
|
530 |
public int getRetrievedFeaturesLimit(){ |
531 |
//WFS 1.0.0 can not know where is the limit
|
532 |
if (getWFSParameters().getVersion().equals("1.0.0")){ |
533 |
return 0; |
534 |
}else{
|
535 |
return wfsClient.getServiceInformation().getMaxFeatures();
|
536 |
} |
537 |
} |
538 |
|
539 |
public void performChanges(Iterator deleteds, Iterator inserteds, |
540 |
Iterator updateds, Iterator featureTypesChanged) |
541 |
throws DataException {
|
542 |
WFSTTransactionBuilder transactionBuilder = new WFSTTransactionBuilder(wfsStatus, wfsClient);
|
543 |
|
544 |
//Create the Query
|
545 |
try {
|
546 |
//Add new features
|
547 |
while (inserteds.hasNext()){
|
548 |
transactionBuilder.addInsertFeature((FeatureProvider)inserteds.next()); |
549 |
} |
550 |
//Add deleted features
|
551 |
while (deleteds.hasNext()){
|
552 |
transactionBuilder.addDeleteFeature((FeatureReference)deleteds.next()); |
553 |
} |
554 |
//Add updated features
|
555 |
while (updateds.hasNext()){
|
556 |
transactionBuilder.addUpdateFeature((FeatureProvider)updateds.next()); |
557 |
} |
558 |
} catch (WriterHandlerCreationException e) {
|
559 |
throw new WFSTTRansactionException(e); |
560 |
} catch (GeometryOperationNotSupportedException e) {
|
561 |
throw new WFSTTRansactionException(e); |
562 |
} catch (GeometryOperationException e) {
|
563 |
throw new WFSTTRansactionException(e); |
564 |
} |
565 |
|
566 |
//Send the query to the server
|
567 |
try {
|
568 |
wfsClient.transaction(wfsStatus, true, null); |
569 |
} catch (WFSException e) {
|
570 |
throw new WFSTTRansactionException(e); |
571 |
} |
572 |
} |
573 |
|
574 |
public boolean allowWrite() { |
575 |
return wfsClient.getServiceInformation().isOperationSupported("Transaction"); |
576 |
} |
577 |
|
578 |
public Envelope getEnvelope() throws DataException { |
579 |
return (Envelope) this.getDynValue("Envelope"); |
580 |
} |
581 |
|
582 |
public FeatureProvider createFeatureProvider(FeatureType type)
|
583 |
throws DataException {
|
584 |
return super.createFeatureProvider(type); |
585 |
} |
586 |
|
587 |
|
588 |
} |
589 |
|