svn-gvsig-desktop / tags / v2_0_0_Build_2020 / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / WFSStatus.java @ 33910
History | View | Annotate | Download (14.7 KB)
1 |
package org.gvsig.remoteclient.wfs; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.gvsig.compat.CompatLocator; |
7 |
import org.gvsig.compat.lang.StringUtils; |
8 |
import org.gvsig.fmap.geom.Geometry; |
9 |
import org.gvsig.fmap.geom.GeometryLocator; |
10 |
import org.gvsig.fmap.geom.GeometryManager; |
11 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
12 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
13 |
import org.gvsig.fmap.geom.primitive.Envelope; |
14 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
15 |
import org.gvsig.remoteclient.RemoteClientStatus; |
16 |
import org.gvsig.remoteclient.wfs.edition.WFSTTransaction; |
17 |
import org.gvsig.remoteclient.wfs.edition.WFSTransactionFactory; |
18 |
import org.gvsig.remoteclient.wfs.filters.AbstractFilter; |
19 |
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding; |
20 |
import org.gvsig.remoteclient.wfs.filters.operations.WFSEnvelopeFilterOperation; |
21 |
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation; |
22 |
import org.gvsig.remoteclient.wfs.filters.operations.WFSSpatialFilterOperation; |
23 |
|
24 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
25 |
*
|
26 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
27 |
*
|
28 |
* This program is free software; you can redistribute it and/or
|
29 |
* modify it under the terms of the GNU General Public License
|
30 |
* as published by the Free Software Foundation; either version 2
|
31 |
* of the License, or (at your option) any later version.
|
32 |
*
|
33 |
* This program is distributed in the hope that it will be useful,
|
34 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
35 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
36 |
* GNU General Public License for more details.
|
37 |
*
|
38 |
* You should have received a copy of the GNU General Public License
|
39 |
* along with this program; if not, write to the Free Software
|
40 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
41 |
*
|
42 |
* For more information, contact:
|
43 |
*
|
44 |
* Generalitat Valenciana
|
45 |
* Conselleria d'Infraestructures i Transport
|
46 |
* Av. Blasco Ib??ez, 50
|
47 |
* 46010 VALENCIA
|
48 |
* SPAIN
|
49 |
*
|
50 |
* +34 963862235
|
51 |
* gvsig@gva.es
|
52 |
* www.gvsig.gva.es
|
53 |
*
|
54 |
* or
|
55 |
*
|
56 |
* IVER T.I. S.A
|
57 |
* Salamanca 50
|
58 |
* 46005 Valencia
|
59 |
* Spain
|
60 |
*
|
61 |
* +34 963163400
|
62 |
* dac@iver.es
|
63 |
*/
|
64 |
/* CVS MESSAGES:
|
65 |
*
|
66 |
* $Id: WFSStatus.java 33910 2010-10-26 11:53:58Z cordinyana $
|
67 |
* $Log$
|
68 |
* Revision 1.7 2007-09-20 09:30:12 jaume
|
69 |
* removed unnecessary imports
|
70 |
*
|
71 |
* Revision 1.6 2007/02/09 14:11:01 jorpiell
|
72 |
* Primer piloto del soporte para WFS 1.1 y para WFS-T
|
73 |
*
|
74 |
* Revision 1.5 2006/12/11 11:02:24 ppiqueras
|
75 |
* Corregido bug -> que se mantenga la frase de filtrado
|
76 |
*
|
77 |
* Revision 1.4 2006/10/10 12:52:28 jorpiell
|
78 |
* Soporte para features complejas.
|
79 |
*
|
80 |
* Revision 1.3 2006/06/14 07:54:18 jorpiell
|
81 |
* Se parsea el online resource que antes se ignoraba
|
82 |
*
|
83 |
* Revision 1.2 2006/05/23 13:23:13 jorpiell
|
84 |
* Se ha cambiado el final del bucle de parseado y se tiene en cuenta el online resource
|
85 |
*
|
86 |
* Revision 1.1 2006/04/19 12:51:35 jorpiell
|
87 |
* A?adidas algunas de las clases del servicio WFS
|
88 |
*
|
89 |
*
|
90 |
*/
|
91 |
/**
|
92 |
* The status of the current WFS connection
|
93 |
*
|
94 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
95 |
* @see <a href="http://www.opengeospatial.org/standards/wfs">OpenGIS Web Feature Service (WFS) Implementation Specification</a>
|
96 |
*/
|
97 |
public class WFSStatus extends RemoteClientStatus{ |
98 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
99 |
|
100 |
/**
|
101 |
* The optional resultType attribute is used to control how
|
102 |
* a web feature service responds to a GetFeature request.
|
103 |
* The possible values for the attribute are defined in
|
104 |
* some constants in this class.
|
105 |
*/
|
106 |
private int resultType = RESULTYPE_RESULTS; |
107 |
|
108 |
/**
|
109 |
* The default value results indicates that a web feature
|
110 |
* service should generate a complete response that
|
111 |
* contains all the features that satisfy the request.
|
112 |
*/
|
113 |
public static final int RESULTYPE_RESULTS = 0; |
114 |
|
115 |
/**
|
116 |
* The value hits indicates that a web feature service should process the
|
117 |
* GetFeature request and rather than return the entire result set,
|
118 |
* it should simply indicate the number of feature instance of
|
119 |
* the requested feature type(s) that satisfy the request.
|
120 |
*/
|
121 |
public static final int RESULTYPE_HITS = 1; |
122 |
|
123 |
static final String LOCKACTION_ALL = "ALL"; |
124 |
static final String LOCKACTION_SOME = "SOME"; |
125 |
//WFS attributes
|
126 |
private String featureName = null; |
127 |
private String namespacePrefix = null; |
128 |
private String namespace = null; |
129 |
private String[] fields = null; |
130 |
private String onlineResource = null; |
131 |
private Integer timeout = new Integer(10000); |
132 |
private Integer buffer = new Integer(100); |
133 |
private String filterByAttribute = null; |
134 |
private WFSSpatialFilterOperation filterByArea = null; |
135 |
|
136 |
|
137 |
//Geometry manager
|
138 |
private static GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
139 |
|
140 |
//WFS-T LockFeature attributes
|
141 |
private String userName = null; |
142 |
private String password = null; |
143 |
private ArrayList featuresToLock = new ArrayList(); |
144 |
private ArrayList featuresToLockPropertieName = new ArrayList(); |
145 |
private ArrayList featuresToLockPropertieValue = new ArrayList(); |
146 |
private ArrayList featuresLocked = new ArrayList(); |
147 |
private int expiry = -1; |
148 |
private String lockAction = null; |
149 |
private Rectangle2D lockedArea = null; |
150 |
private String lockedAreaProperty = null; |
151 |
//WFS-T Transaction
|
152 |
private ArrayList transactions = null; |
153 |
|
154 |
public WFSStatus(String featureName){ |
155 |
this(featureName, null); |
156 |
} |
157 |
|
158 |
public WFSStatus(String featureName, String namespace){ |
159 |
this.featureName = featureName;
|
160 |
this.namespace = namespace;
|
161 |
if (featureName != null){ |
162 |
int index = featureName.indexOf(":"); |
163 |
if (index>0){ |
164 |
namespacePrefix = featureName.substring(0, index);
|
165 |
} |
166 |
} |
167 |
lockAction = LOCKACTION_ALL; |
168 |
transactions = new ArrayList(); |
169 |
featuresLocked = new ArrayList(); |
170 |
featuresLocked = new ArrayList(); |
171 |
featuresToLockPropertieName = new ArrayList(); |
172 |
featuresToLockPropertieValue = new ArrayList(); |
173 |
} |
174 |
|
175 |
/**
|
176 |
* @return Returns the buffer.
|
177 |
*/
|
178 |
public Integer getBuffer() { |
179 |
return buffer;
|
180 |
} |
181 |
|
182 |
|
183 |
/**
|
184 |
* @param buffer The buffer to set.
|
185 |
*/
|
186 |
public void setBuffer(Integer buffer) { |
187 |
if (buffer != null){ |
188 |
this.buffer = buffer;
|
189 |
} |
190 |
} |
191 |
|
192 |
|
193 |
/**
|
194 |
* @return Returns the featureName.
|
195 |
*/
|
196 |
public String getFeatureName() { |
197 |
return featureName;
|
198 |
} |
199 |
|
200 |
|
201 |
/**
|
202 |
* @param featureName The featureName to set.
|
203 |
*/
|
204 |
public void setFeatureName(String featureName) { |
205 |
this.featureName = featureName;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* @return Returns the fields.
|
210 |
*/
|
211 |
public String[] getFields() { |
212 |
if (fields == null){ |
213 |
fields = new String[0]; |
214 |
} |
215 |
return fields;
|
216 |
} |
217 |
|
218 |
|
219 |
/**
|
220 |
* @param fields The fields to set.
|
221 |
*/
|
222 |
public void setFields(String[] fields) { |
223 |
this.fields = fields;
|
224 |
} |
225 |
|
226 |
public void setFields(String fields) { |
227 |
if (fields == null){ |
228 |
return;
|
229 |
} |
230 |
this.fields = stringUtils.split(fields, ","); |
231 |
} |
232 |
|
233 |
|
234 |
/**
|
235 |
* @return Returns the password.
|
236 |
*/
|
237 |
public String getPassword() { |
238 |
return password;
|
239 |
} |
240 |
|
241 |
|
242 |
/**
|
243 |
* @param password The password to set.
|
244 |
*/
|
245 |
public void setPassword(String password) { |
246 |
this.password = password;
|
247 |
} |
248 |
|
249 |
|
250 |
/**
|
251 |
* @return Returns the timeout.
|
252 |
*/
|
253 |
public Integer getTimeout() { |
254 |
return timeout;
|
255 |
} |
256 |
|
257 |
|
258 |
/**
|
259 |
* @param timeout The timeout to set.
|
260 |
*/
|
261 |
public void setTimeout(Integer timeout) { |
262 |
if (timeout != null){ |
263 |
this.timeout = timeout;
|
264 |
} |
265 |
} |
266 |
|
267 |
|
268 |
/**
|
269 |
* @return Returns the userName.
|
270 |
*/
|
271 |
public String getUserName() { |
272 |
return userName;
|
273 |
} |
274 |
|
275 |
|
276 |
/**
|
277 |
* @param userName The userName to set.
|
278 |
*/
|
279 |
public void setUserName(String userName) { |
280 |
this.userName = userName;
|
281 |
} |
282 |
|
283 |
public String getOnlineResource() { |
284 |
return onlineResource;
|
285 |
} |
286 |
|
287 |
|
288 |
public void setOnlineResource(String url) { |
289 |
onlineResource = url; |
290 |
} |
291 |
|
292 |
/**
|
293 |
* @return Returns the filterQuery.
|
294 |
*/
|
295 |
public String getFilterByAttribute() { |
296 |
return filterByAttribute;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* @param filterQuery The filterQuery to set.
|
301 |
*/
|
302 |
public void setFilterByAttribute(String filterQuery) { |
303 |
this.filterByAttribute = filterQuery;
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* @param filterByArea
|
308 |
* the filterByArea to set
|
309 |
* @param operation
|
310 |
* The geometric operation to apply. It has to be a value from
|
311 |
* {@link AbstractFilter}
|
312 |
*/
|
313 |
public void setFilterByArea(Geometry geometry, String attributeName, String srs, Integer operation) { |
314 |
if (geometry == null){ |
315 |
return;
|
316 |
} |
317 |
if (attributeName == null){ |
318 |
attributeName = "the_geom";
|
319 |
} |
320 |
if (operation == null){ |
321 |
operation = new Integer(AbstractFilter.GEOMETRIC_OPERATOR_INTERSECT); |
322 |
} |
323 |
this.filterByArea = new WFSGeometryFilterOperation(geometry, |
324 |
operation.intValue(), |
325 |
attributeName, |
326 |
srs); |
327 |
} |
328 |
|
329 |
/**
|
330 |
* @param filterByArea
|
331 |
* the filterByArea to set
|
332 |
* @param operation
|
333 |
* The geometric operation to apply. It has to be a value from
|
334 |
* {@link AbstractFilter}
|
335 |
*/
|
336 |
public void setFilterByArea(Envelope envelope, String attributeName, String srs, Integer operation) { |
337 |
if (envelope == null){ |
338 |
return;
|
339 |
} |
340 |
if (attributeName == null){ |
341 |
attributeName = "the_geom";
|
342 |
} |
343 |
if (operation == null){ |
344 |
operation = new Integer(AbstractFilter.GEOMETRIC_OPERATOR_INTERSECT); |
345 |
} |
346 |
this.filterByArea = new WFSEnvelopeFilterOperation(envelope, |
347 |
operation.intValue(), |
348 |
attributeName, |
349 |
srs); |
350 |
} |
351 |
|
352 |
/**
|
353 |
* @return the filterByArea
|
354 |
*/
|
355 |
public WFSSpatialFilterOperation getFilterByArea() {
|
356 |
return filterByArea;
|
357 |
} |
358 |
|
359 |
/**
|
360 |
* @return the filterQueryLocked
|
361 |
*/
|
362 |
public String getFilterQueryLocked() { |
363 |
FilterEncoding filter = new FilterEncoding();
|
364 |
filter.setQualified(true);
|
365 |
filter.setNamepacePrefix(null);
|
366 |
filter.setHasBlankSpaces(false);
|
367 |
return getFilterQueryLocked(filter);
|
368 |
} |
369 |
|
370 |
/**
|
371 |
* @return the filterQueryLocked
|
372 |
*/
|
373 |
public String getFilterQueryLockedPost() { |
374 |
FilterEncoding filter = new FilterEncoding();
|
375 |
filter.setQualified(true);
|
376 |
return getFilterQueryLocked(filter);
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* Create a filter encoding request
|
381 |
* @param filter
|
382 |
* @return
|
383 |
*/
|
384 |
private String getFilterQueryLocked(FilterEncoding filter){ |
385 |
if ((featuresToLock.size() == 0) && |
386 |
(getLockedArea() == null) &&
|
387 |
(featuresToLockPropertieName.size() == 0)){
|
388 |
return null; |
389 |
} |
390 |
for (int i=0 ; i<featuresToLock.size() ; i++){ |
391 |
filter.addFeatureById(featuresToLock.get(i)); |
392 |
} |
393 |
if (featuresToLockPropertieName.size() > 0){ |
394 |
for (int i=0 ; i<featuresToLockPropertieName.size() ; i++){ |
395 |
filter.addAndClause((String)featuresToLockPropertieName.get(i),
|
396 |
(String)featuresToLockPropertieValue.get(i));
|
397 |
} |
398 |
} |
399 |
if (lockedArea != null){ |
400 |
GeneralPathX generalPath = new GeneralPathX();
|
401 |
generalPath.moveTo(lockedArea.getMinX(), lockedArea.getMinY()); |
402 |
generalPath.lineTo(lockedArea.getMaxX(), lockedArea.getMinY()); |
403 |
generalPath.lineTo(lockedArea.getMaxX(), lockedArea.getMaxY()); |
404 |
generalPath.lineTo(lockedArea.getMinX(), lockedArea.getMaxY()); |
405 |
generalPath.lineTo(lockedArea.getMinX(), lockedArea.getMinY()); |
406 |
try {
|
407 |
filter.clearSpatialFilters(); |
408 |
filter.addSpatialFilter(geometryManager.createSurface(generalPath, SUBTYPES.GEOM2D), |
409 |
lockedAreaProperty, |
410 |
getSrs(), |
411 |
AbstractFilter.BBOX_ENCLOSES); |
412 |
} catch (CreateGeometryException e) {
|
413 |
return null; |
414 |
} |
415 |
|
416 |
} |
417 |
return filter.toString();
|
418 |
} |
419 |
|
420 |
/**
|
421 |
* @return the expiry
|
422 |
*/
|
423 |
public int getExpiry() { |
424 |
return expiry;
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* @param expiry the expiry to set
|
429 |
*/
|
430 |
public void setExpiry(int expiry) { |
431 |
this.expiry = expiry;
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* @return the lockAction
|
436 |
*/
|
437 |
public String getLockAction() { |
438 |
return lockAction;
|
439 |
} |
440 |
|
441 |
/**
|
442 |
* Set the lock action to all
|
443 |
*/
|
444 |
public void setLockActionToAll() { |
445 |
lockAction = LOCKACTION_ALL; |
446 |
} |
447 |
|
448 |
/**
|
449 |
* Set teh lock action to some
|
450 |
*/
|
451 |
public void setLockActionToSome() { |
452 |
lockAction = LOCKACTION_SOME; |
453 |
} |
454 |
|
455 |
/**
|
456 |
* @return the transaction size
|
457 |
*/
|
458 |
public int getTransactionsSize() { |
459 |
return transactions.size();
|
460 |
} |
461 |
|
462 |
/**
|
463 |
* Gets an transaction
|
464 |
* @param i
|
465 |
* Transaction position
|
466 |
* @return
|
467 |
* A transaction
|
468 |
*/
|
469 |
public WFSTTransaction getTransactionAt(int i){ |
470 |
if (i>getTransactionsSize()){
|
471 |
return null; |
472 |
} |
473 |
return (WFSTTransaction)transactions.get(i);
|
474 |
} |
475 |
|
476 |
/**
|
477 |
* Adds a new transaction
|
478 |
* @param transactions the transactions to add
|
479 |
*/
|
480 |
public WFSTTransaction createTransaction(String version) { |
481 |
WFSTTransaction transaction = WFSTransactionFactory.createTransaction(version, |
482 |
getFeatureName(), |
483 |
getNamespacePrefix(), |
484 |
getNamespace(), |
485 |
featuresLocked); |
486 |
transactions.add(transaction); |
487 |
return transaction;
|
488 |
} |
489 |
|
490 |
/**
|
491 |
* @return the neumber of features blocked
|
492 |
*/
|
493 |
public int getFeaturesToLockSize() { |
494 |
return featuresToLock.size();
|
495 |
} |
496 |
|
497 |
/**
|
498 |
* Gets an identifier of a feature that is blocked
|
499 |
* @param i
|
500 |
* The id position
|
501 |
* @return
|
502 |
* The Id
|
503 |
*/
|
504 |
public String getFeatureToLockAt(int i){ |
505 |
if (i>featuresToLock.size()){
|
506 |
return null; |
507 |
} |
508 |
return (String)featuresToLock.get(i); |
509 |
} |
510 |
|
511 |
/**
|
512 |
* Remove all the features to lock
|
513 |
*/
|
514 |
public void removeFeaturesToLock() { |
515 |
featuresToLock.clear(); |
516 |
featuresLocked.clear(); |
517 |
featuresToLockPropertieName.clear(); |
518 |
featuresToLockPropertieValue.clear(); |
519 |
} |
520 |
|
521 |
/**
|
522 |
* Adds a new feature locked
|
523 |
* @param idFeature
|
524 |
* the feature id
|
525 |
*/
|
526 |
public void addFeatureToLock(String idFeature) { |
527 |
featuresToLock.add(idFeature); |
528 |
} |
529 |
|
530 |
/**
|
531 |
* Adds a new feature locked
|
532 |
* @param idFeature
|
533 |
* the feature id
|
534 |
*/
|
535 |
public void addFeatureToLock(String propertyName, String propertyValue){ |
536 |
featuresToLockPropertieName.add(propertyName); |
537 |
featuresToLockPropertieValue.add(propertyValue); |
538 |
} |
539 |
|
540 |
/**
|
541 |
* @return the idsLocked size
|
542 |
*/
|
543 |
public int getFeaturesLocked() { |
544 |
return featuresLocked.size();
|
545 |
} |
546 |
|
547 |
/**
|
548 |
* Gets an identifier tha is blocked
|
549 |
* @param i
|
550 |
* The id position
|
551 |
* @return
|
552 |
* The Id
|
553 |
*/
|
554 |
public String getFeatureLockedAt(int i){ |
555 |
if (i>featuresLocked.size()){
|
556 |
return null; |
557 |
} |
558 |
return (String)featuresLocked.get(i); |
559 |
} |
560 |
|
561 |
/**
|
562 |
* Adds a new Id
|
563 |
* @param idLocked
|
564 |
* the idLocked to add
|
565 |
*/
|
566 |
public void addFeatureLocked(String lockId) { |
567 |
featuresLocked.add(lockId); |
568 |
} |
569 |
|
570 |
/**
|
571 |
* @return the lockedArea
|
572 |
*/
|
573 |
public Rectangle2D getLockedArea() { |
574 |
return lockedArea;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* @param lockedArea the lockedArea to set
|
579 |
*/
|
580 |
public void setLockedArea(Rectangle2D lockedArea, String lockedAreaProperty) { |
581 |
this.lockedArea = lockedArea;
|
582 |
this.lockedAreaProperty = lockedAreaProperty;
|
583 |
} |
584 |
|
585 |
/**
|
586 |
* @return the namespace prefix
|
587 |
*/
|
588 |
public String getNamespacePrefix(){ |
589 |
return namespacePrefix;
|
590 |
} |
591 |
|
592 |
/**
|
593 |
* @return the namespace URL
|
594 |
*/
|
595 |
public String getNamespace(){ |
596 |
return namespace;
|
597 |
} |
598 |
|
599 |
/**
|
600 |
* @param namespaceprefix the namespaceprefix to set
|
601 |
*/
|
602 |
public void setNamespacePrefix(String namespacePrefix) { |
603 |
this.namespacePrefix = namespacePrefix;
|
604 |
} |
605 |
|
606 |
/**
|
607 |
* @param namespace the namespace to set
|
608 |
*/
|
609 |
public void setNamespace(String namespace) { |
610 |
this.namespace = namespace;
|
611 |
} |
612 |
|
613 |
/**
|
614 |
* @return the resultType
|
615 |
*/
|
616 |
public int getResultType() { |
617 |
return resultType;
|
618 |
} |
619 |
|
620 |
/**
|
621 |
* @param resultType the resultType to set
|
622 |
*/
|
623 |
public void setResultType(int resultType) { |
624 |
this.resultType = resultType;
|
625 |
} |
626 |
} |