svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / WFSStatus.java @ 34026
History | View | Annotate | Download (15.3 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.Geometry.SUBTYPES; |
10 |
import org.gvsig.fmap.geom.GeometryLocator; |
11 |
import org.gvsig.fmap.geom.GeometryManager; |
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 34026 2010-11-08 13:06:02Z jpiera $
|
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 namespaceLocation = null; |
129 |
private String[] fields = null; |
130 |
private String onlineResource = null; |
131 |
private Integer timeout = new Integer(10000); |
132 |
private Integer maxFeatures = 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.namespaceLocation = namespace;
|
161 |
setFeatureName(featureName); |
162 |
lockAction = LOCKACTION_ALL; |
163 |
transactions = new ArrayList(); |
164 |
featuresLocked = new ArrayList(); |
165 |
featuresLocked = new ArrayList(); |
166 |
featuresToLockPropertieName = new ArrayList(); |
167 |
featuresToLockPropertieValue = new ArrayList(); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* @return Returns the buffer.
|
172 |
*/
|
173 |
public Integer getMaxFeatures() { |
174 |
return maxFeatures;
|
175 |
} |
176 |
|
177 |
|
178 |
/**
|
179 |
* @param buffer The buffer to set.
|
180 |
*/
|
181 |
public void setMaxFeatures(Integer buffer) { |
182 |
if (buffer != null){ |
183 |
this.maxFeatures = buffer;
|
184 |
} |
185 |
} |
186 |
|
187 |
|
188 |
/**
|
189 |
* @return Returns the featureName.
|
190 |
*/
|
191 |
public String getFeatureName() { |
192 |
return featureName;
|
193 |
} |
194 |
|
195 |
public String getFeatureFullName(){ |
196 |
if (namespacePrefix == null){ |
197 |
return featureName;
|
198 |
}else{
|
199 |
return namespacePrefix + ":" + featureName; |
200 |
} |
201 |
} |
202 |
|
203 |
|
204 |
/**
|
205 |
* @param featureName The featureName to set.
|
206 |
*/
|
207 |
public void setFeatureName(String featureName) { |
208 |
if (featureName != null){ |
209 |
int index = featureName.indexOf(":"); |
210 |
if (index>0){ |
211 |
this.featureName = featureName.substring(index+1, featureName.length()); |
212 |
namespacePrefix = featureName.substring(0, index);
|
213 |
}else{
|
214 |
this.featureName = featureName;
|
215 |
} |
216 |
} |
217 |
} |
218 |
|
219 |
/**
|
220 |
* @return Returns the fields.
|
221 |
*/
|
222 |
public String[] getFields() { |
223 |
if (fields == null){ |
224 |
fields = new String[0]; |
225 |
} |
226 |
return fields;
|
227 |
} |
228 |
|
229 |
|
230 |
/**
|
231 |
* @param fields The fields to set.
|
232 |
*/
|
233 |
public void setFields(String[] fields) { |
234 |
this.fields = fields;
|
235 |
} |
236 |
|
237 |
public void setFields(String fields) { |
238 |
if (fields == null){ |
239 |
return;
|
240 |
} |
241 |
this.fields = stringUtils.split(fields, ","); |
242 |
} |
243 |
|
244 |
|
245 |
/**
|
246 |
* @return Returns the password.
|
247 |
*/
|
248 |
public String getPassword() { |
249 |
return password;
|
250 |
} |
251 |
|
252 |
|
253 |
/**
|
254 |
* @param password The password to set.
|
255 |
*/
|
256 |
public void setPassword(String password) { |
257 |
this.password = password;
|
258 |
} |
259 |
|
260 |
|
261 |
/**
|
262 |
* @return Returns the timeout.
|
263 |
*/
|
264 |
public Integer getTimeout() { |
265 |
return timeout;
|
266 |
} |
267 |
|
268 |
|
269 |
/**
|
270 |
* @param timeout The timeout to set.
|
271 |
*/
|
272 |
public void setTimeout(Integer timeout) { |
273 |
if (timeout != null){ |
274 |
this.timeout = timeout;
|
275 |
} |
276 |
} |
277 |
|
278 |
|
279 |
/**
|
280 |
* @return Returns the userName.
|
281 |
*/
|
282 |
public String getUserName() { |
283 |
return userName;
|
284 |
} |
285 |
|
286 |
|
287 |
/**
|
288 |
* @param userName The userName to set.
|
289 |
*/
|
290 |
public void setUserName(String userName) { |
291 |
this.userName = userName;
|
292 |
} |
293 |
|
294 |
public String getOnlineResource() { |
295 |
return onlineResource;
|
296 |
} |
297 |
|
298 |
|
299 |
public void setOnlineResource(String url) { |
300 |
onlineResource = url; |
301 |
} |
302 |
|
303 |
/**
|
304 |
* @return Returns the filterQuery.
|
305 |
*/
|
306 |
public String getFilterByAttribute() { |
307 |
return filterByAttribute;
|
308 |
} |
309 |
|
310 |
/**
|
311 |
* @param filterQuery The filterQuery to set.
|
312 |
*/
|
313 |
public void setFilterByAttribute(String filterQuery) { |
314 |
this.filterByAttribute = filterQuery;
|
315 |
} |
316 |
|
317 |
/**
|
318 |
* @param filterByArea
|
319 |
* the filterByArea to set
|
320 |
* @param operation
|
321 |
* The geometric operation to apply. It has to be a value from
|
322 |
* {@link AbstractFilter}
|
323 |
*/
|
324 |
public void setFilterByArea(Geometry geometry, String attributeName, String srs, Integer operation) { |
325 |
if (geometry == null){ |
326 |
return;
|
327 |
} |
328 |
if (attributeName == null){ |
329 |
attributeName = "the_geom";
|
330 |
} |
331 |
if (operation == null){ |
332 |
operation = new Integer(AbstractFilter.GEOMETRIC_OPERATOR_INTERSECT); |
333 |
} |
334 |
//TODO add a manager to register this
|
335 |
this.filterByArea = new WFSGeometryFilterOperation(geometry, |
336 |
operation.intValue(), |
337 |
attributeName, |
338 |
getNamespacePrefix(), |
339 |
getNamespaceLocation(), |
340 |
srs); |
341 |
} |
342 |
|
343 |
/**
|
344 |
* @param filterByArea
|
345 |
* the filterByArea to set
|
346 |
* @param operation
|
347 |
* The geometric operation to apply. It has to be a value from
|
348 |
* {@link AbstractFilter}
|
349 |
*/
|
350 |
public void setFilterByArea(Envelope envelope, String attributeName, String srs, Integer operation) { |
351 |
if (envelope == null){ |
352 |
return;
|
353 |
} |
354 |
if (attributeName == null){ |
355 |
attributeName = "the_geom";
|
356 |
} |
357 |
if (operation == null){ |
358 |
operation = new Integer(AbstractFilter.GEOMETRIC_OPERATOR_INTERSECT); |
359 |
} |
360 |
this.filterByArea = new WFSEnvelopeFilterOperation(envelope, |
361 |
operation.intValue(), |
362 |
attributeName, |
363 |
getNamespacePrefix(), |
364 |
getNamespaceLocation(), |
365 |
srs); |
366 |
} |
367 |
|
368 |
/**
|
369 |
* @return the filterByArea
|
370 |
*/
|
371 |
public WFSSpatialFilterOperation getFilterByArea() {
|
372 |
return filterByArea;
|
373 |
} |
374 |
|
375 |
/**
|
376 |
* @return the filterQueryLocked
|
377 |
*/
|
378 |
public String getFilterQueryLocked() { |
379 |
FilterEncoding filter = new FilterEncoding();
|
380 |
filter.setQualified(true);
|
381 |
filter.setNamepacePrefix(null);
|
382 |
filter.setHasBlankSpaces(false);
|
383 |
return getFilterQueryLocked(filter);
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* @return the filterQueryLocked
|
388 |
*/
|
389 |
public String getFilterQueryLockedPost() { |
390 |
FilterEncoding filter = new FilterEncoding();
|
391 |
filter.setQualified(true);
|
392 |
return getFilterQueryLocked(filter);
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Create a filter encoding request
|
397 |
* @param filter
|
398 |
* @return
|
399 |
*/
|
400 |
private String getFilterQueryLocked(FilterEncoding filter){ |
401 |
if ((featuresToLock.size() == 0) && |
402 |
(getLockedArea() == null) &&
|
403 |
(featuresToLockPropertieName.size() == 0)){
|
404 |
return null; |
405 |
} |
406 |
for (int i=0 ; i<featuresToLock.size() ; i++){ |
407 |
filter.addFeatureById(featuresToLock.get(i)); |
408 |
} |
409 |
if (featuresToLockPropertieName.size() > 0){ |
410 |
for (int i=0 ; i<featuresToLockPropertieName.size() ; i++){ |
411 |
filter.addAndClause((String)featuresToLockPropertieName.get(i),
|
412 |
(String)featuresToLockPropertieValue.get(i));
|
413 |
} |
414 |
} |
415 |
if (lockedArea != null){ |
416 |
GeneralPathX generalPath = new GeneralPathX();
|
417 |
generalPath.moveTo(lockedArea.getMinX(), lockedArea.getMinY()); |
418 |
generalPath.lineTo(lockedArea.getMaxX(), lockedArea.getMinY()); |
419 |
generalPath.lineTo(lockedArea.getMaxX(), lockedArea.getMaxY()); |
420 |
generalPath.lineTo(lockedArea.getMinX(), lockedArea.getMaxY()); |
421 |
generalPath.lineTo(lockedArea.getMinX(), lockedArea.getMinY()); |
422 |
try {
|
423 |
filter.clearSpatialFilters(); |
424 |
filter.addSpatialFilter(geometryManager.createSurface(generalPath, SUBTYPES.GEOM2D), |
425 |
lockedAreaProperty, |
426 |
getNamespacePrefix(), |
427 |
getNamespaceLocation(), |
428 |
getSrs(), |
429 |
AbstractFilter.BBOX_ENCLOSES); |
430 |
} catch (CreateGeometryException e) {
|
431 |
return null; |
432 |
} |
433 |
|
434 |
} |
435 |
return filter.toString();
|
436 |
} |
437 |
|
438 |
/**
|
439 |
* @return the expiry
|
440 |
*/
|
441 |
public int getExpiry() { |
442 |
return expiry;
|
443 |
} |
444 |
|
445 |
/**
|
446 |
* @param expiry the expiry to set
|
447 |
*/
|
448 |
public void setExpiry(int expiry) { |
449 |
this.expiry = expiry;
|
450 |
} |
451 |
|
452 |
/**
|
453 |
* @return the lockAction
|
454 |
*/
|
455 |
public String getLockAction() { |
456 |
return lockAction;
|
457 |
} |
458 |
|
459 |
/**
|
460 |
* Set the lock action to all
|
461 |
*/
|
462 |
public void setLockActionToAll() { |
463 |
lockAction = LOCKACTION_ALL; |
464 |
} |
465 |
|
466 |
/**
|
467 |
* Set teh lock action to some
|
468 |
*/
|
469 |
public void setLockActionToSome() { |
470 |
lockAction = LOCKACTION_SOME; |
471 |
} |
472 |
|
473 |
/**
|
474 |
* @return the transaction size
|
475 |
*/
|
476 |
public int getTransactionsSize() { |
477 |
return transactions.size();
|
478 |
} |
479 |
|
480 |
/**
|
481 |
* Gets an transaction
|
482 |
* @param i
|
483 |
* Transaction position
|
484 |
* @return
|
485 |
* A transaction
|
486 |
*/
|
487 |
public WFSTTransaction getTransactionAt(int i){ |
488 |
if (i>getTransactionsSize()){
|
489 |
return null; |
490 |
} |
491 |
return (WFSTTransaction)transactions.get(i);
|
492 |
} |
493 |
|
494 |
/**
|
495 |
* Adds a new transaction
|
496 |
* @param transactions the transactions to add
|
497 |
*/
|
498 |
public WFSTTransaction createTransaction(String version) { |
499 |
WFSTTransaction transaction = WFSTransactionFactory.createTransaction(version, |
500 |
getFeatureName(), |
501 |
getNamespacePrefix(), |
502 |
getNamespaceLocation(), |
503 |
featuresLocked); |
504 |
transactions.add(transaction); |
505 |
return transaction;
|
506 |
} |
507 |
|
508 |
/**
|
509 |
* @return the neumber of features blocked
|
510 |
*/
|
511 |
public int getFeaturesToLockSize() { |
512 |
return featuresToLock.size();
|
513 |
} |
514 |
|
515 |
/**
|
516 |
* Gets an identifier of a feature that is blocked
|
517 |
* @param i
|
518 |
* The id position
|
519 |
* @return
|
520 |
* The Id
|
521 |
*/
|
522 |
public String getFeatureToLockAt(int i){ |
523 |
if (i>featuresToLock.size()){
|
524 |
return null; |
525 |
} |
526 |
return (String)featuresToLock.get(i); |
527 |
} |
528 |
|
529 |
/**
|
530 |
* Remove all the features to lock
|
531 |
*/
|
532 |
public void removeFeaturesToLock() { |
533 |
featuresToLock.clear(); |
534 |
featuresLocked.clear(); |
535 |
featuresToLockPropertieName.clear(); |
536 |
featuresToLockPropertieValue.clear(); |
537 |
} |
538 |
|
539 |
/**
|
540 |
* Adds a new feature locked
|
541 |
* @param idFeature
|
542 |
* the feature id
|
543 |
*/
|
544 |
public void addFeatureToLock(String idFeature) { |
545 |
featuresToLock.add(idFeature); |
546 |
} |
547 |
|
548 |
/**
|
549 |
* Adds a new feature locked
|
550 |
* @param idFeature
|
551 |
* the feature id
|
552 |
*/
|
553 |
public void addFeatureToLock(String propertyName, String propertyValue){ |
554 |
featuresToLockPropertieName.add(propertyName); |
555 |
featuresToLockPropertieValue.add(propertyValue); |
556 |
} |
557 |
|
558 |
/**
|
559 |
* @return the idsLocked size
|
560 |
*/
|
561 |
public int getFeaturesLocked() { |
562 |
return featuresLocked.size();
|
563 |
} |
564 |
|
565 |
/**
|
566 |
* Gets an identifier tha is blocked
|
567 |
* @param i
|
568 |
* The id position
|
569 |
* @return
|
570 |
* The Id
|
571 |
*/
|
572 |
public String getFeatureLockedAt(int i){ |
573 |
if (i>featuresLocked.size()){
|
574 |
return null; |
575 |
} |
576 |
return (String)featuresLocked.get(i); |
577 |
} |
578 |
|
579 |
/**
|
580 |
* Adds a new Id
|
581 |
* @param idLocked
|
582 |
* the idLocked to add
|
583 |
*/
|
584 |
public void addFeatureLocked(String lockId) { |
585 |
featuresLocked.add(lockId); |
586 |
} |
587 |
|
588 |
/**
|
589 |
* @return the lockedArea
|
590 |
*/
|
591 |
public Rectangle2D getLockedArea() { |
592 |
return lockedArea;
|
593 |
} |
594 |
|
595 |
/**
|
596 |
* @param lockedArea the lockedArea to set
|
597 |
*/
|
598 |
public void setLockedArea(Rectangle2D lockedArea, String lockedAreaProperty) { |
599 |
this.lockedArea = lockedArea;
|
600 |
this.lockedAreaProperty = lockedAreaProperty;
|
601 |
} |
602 |
|
603 |
/**
|
604 |
* @return the namespace prefix
|
605 |
*/
|
606 |
public String getNamespacePrefix(){ |
607 |
return namespacePrefix;
|
608 |
} |
609 |
|
610 |
/**
|
611 |
* @return the namespace URL
|
612 |
*/
|
613 |
public String getNamespaceLocation(){ |
614 |
return namespaceLocation;
|
615 |
} |
616 |
|
617 |
/**
|
618 |
* @param namespaceprefix the namespaceprefix to set
|
619 |
*/
|
620 |
public void setNamespacePrefix(String namespacePrefix) { |
621 |
this.namespacePrefix = namespacePrefix;
|
622 |
} |
623 |
|
624 |
/**
|
625 |
* @param namespace the namespace to set
|
626 |
*/
|
627 |
public void setNamespaceLocation(String namespaceLocation) { |
628 |
this.namespaceLocation = namespaceLocation;
|
629 |
} |
630 |
|
631 |
/**
|
632 |
* @return the resultType
|
633 |
*/
|
634 |
public int getResultType() { |
635 |
return resultType;
|
636 |
} |
637 |
|
638 |
/**
|
639 |
* @param resultType the resultType to set
|
640 |
*/
|
641 |
public void setResultType(int resultType) { |
642 |
this.resultType = resultType;
|
643 |
} |
644 |
} |