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