Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wfs / WFSStatus.java @ 40559

History | View | Annotate | Download (15.9 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.wfs;
25

    
26
import java.awt.geom.Rectangle2D;
27
import java.util.ArrayList;
28

    
29
import org.gvsig.compat.CompatLocator;
30
import org.gvsig.compat.lang.StringUtils;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.GeometryLocator;
34
import org.gvsig.fmap.geom.GeometryManager;
35
import org.gvsig.fmap.geom.exception.CreateGeometryException;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.fmap.geom.primitive.GeneralPathX;
38
import org.gvsig.remoteclient.RemoteClientStatus;
39
import org.gvsig.remoteclient.wfs.edition.WFSTTransaction;
40
import org.gvsig.remoteclient.wfs.filters.AbstractFilter;
41
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding;
42
import org.gvsig.remoteclient.wfs.filters.operations.WFSEnvelopeFilterOperation;
43
import org.gvsig.remoteclient.wfs.filters.operations.WFSGeometryFilterOperation;
44
import org.gvsig.remoteclient.wfs.filters.operations.WFSSpatialFilterOperation;
45

    
46
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
47
 *
48
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
49
 *
50
 * This program is free software; you can redistribute it and/or
51
 * modify it under the terms of the GNU General Public License
52
 * as published by the Free Software Foundation; either version 2
53
 * of the License, or (at your option) any later version.
54
 *
55
 * This program is distributed in the hope that it will be useful,
56
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58
 * GNU General Public License for more details.
59
 *
60
 * You should have received a copy of the GNU General Public License
61
 * along with this program; if not, write to the Free Software
62
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
63
 *
64
 * For more information, contact:
65
 *
66
 *  Generalitat Valenciana
67
 *   Conselleria d'Infraestructures i Transport
68
 *   Av. Blasco Ib??ez, 50
69
 *   46010 VALENCIA
70
 *   SPAIN
71
 *
72
 *      +34 963862235
73
 *   gvsig@gva.es
74
 *      www.gvsig.gva.es
75
 *
76
 *    or
77
 *
78
 *   IVER T.I. S.A
79
 *   Salamanca 50
80
 *   46005 Valencia
81
 *   Spain
82
 *
83
 *   +34 963163400
84
 *   dac@iver.es
85
 */
86
/* CVS MESSAGES:
87
 *
88
 * $Id: WFSStatus.java 34132 2010-11-15 09:27:20Z jpiera $
89
 * $Log$
90
 * Revision 1.7  2007-09-20 09:30:12  jaume
91
 * removed unnecessary imports
92
 *
93
 * Revision 1.6  2007/02/09 14:11:01  jorpiell
94
 * Primer piloto del soporte para WFS 1.1 y para WFS-T
95
 *
96
 * Revision 1.5  2006/12/11 11:02:24  ppiqueras
97
 * Corregido bug -> que se mantenga la frase de filtrado
98
 *
99
 * Revision 1.4  2006/10/10 12:52:28  jorpiell
100
 * Soporte para features complejas.
101
 *
102
 * Revision 1.3  2006/06/14 07:54:18  jorpiell
103
 * Se parsea el online resource que antes se ignoraba
104
 *
105
 * Revision 1.2  2006/05/23 13:23:13  jorpiell
106
 * Se ha cambiado el final del bucle de parseado y se tiene en cuenta el online resource
107
 *
108
 * Revision 1.1  2006/04/19 12:51:35  jorpiell
109
 * A?adidas algunas de las clases del servicio WFS
110
 *
111
 *
112
 */
113
/**
114
 * The status of the current WFS connection
115
 * 
116
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
117
 * @see <a href="http://www.opengeospatial.org/standards/wfs">OpenGIS Web Feature Service (WFS) Implementation Specification</a>
118
 */
119
public class WFSStatus extends RemoteClientStatus{
120
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
121
    
122
    /**
123
         *  The optional resultType attribute is used to control how 
124
         *  a web feature service responds to a GetFeature request.
125
         *  The possible values for the attribute are defined in 
126
         *  some constants in this class.
127
         */
128
        private int resultType = RESULTYPE_RESULTS;
129
        
130
        /**
131
         * The default value results indicates that a web feature 
132
         * service should generate a complete response that 
133
         * contains all the features that satisfy the request.
134
         */
135
        public static final int RESULTYPE_RESULTS = 0;
136
        
137
        /**
138
         * The value hits indicates that a web feature service should process the
139
         * GetFeature request and rather than return the entire result set, 
140
         * it should simply indicate the number of feature instance of 
141
         * the requested feature type(s) that satisfy the request.
142
         */
143
        public static final int RESULTYPE_HITS = 1;
144
                        
145
        static final String LOCKACTION_ALL = "ALL"; 
146
        static final String LOCKACTION_SOME = "SOME"; 
147
        //WFS attributes
148
        private String featureName = null;
149
        private String namespacePrefix = null;
150
        private String namespaceLocation = null;
151
        private String[] fields = null;
152
        private String onlineResource = null;
153
        private Integer timeout = new Integer(10000);
154
        private Integer maxFeatures = new Integer(100);        
155
        private String filterByAttribute = null;
156
        private WFSSpatialFilterOperation filterByArea = null;
157
        
158

    
159
        //Geometry manager
160
        private static GeometryManager geometryManager = GeometryLocator.getGeometryManager();
161
        
162
        //WFS-T LockFeature attributes
163
        private String userName = null;
164
        private String password = null;
165
        private ArrayList featuresToLock = new ArrayList();
166
        private ArrayList featuresToLockPropertieName = new ArrayList();
167
        private ArrayList featuresToLockPropertieValue = new ArrayList();
168
        private ArrayList featuresLocked = new ArrayList();
169
        private int expiry = -1;
170
        private String lockAction = null;
171
        private Rectangle2D lockedArea = null;
172
        private String lockedAreaProperty = null;
173
        
174
        //WFS-T Transaction
175
        private WFSTTransaction transaction = null;
176

    
177
        public WFSStatus(String featureName){
178
                this(featureName, null);
179
        }
180

    
181
        public WFSStatus(String featureName, String namespace){
182
                this.featureName = featureName;
183
                this.namespaceLocation = namespace;
184
                setFeatureName(featureName);
185
                lockAction = LOCKACTION_ALL;
186
                featuresLocked = new ArrayList();
187
                featuresLocked = new ArrayList();
188
                featuresToLockPropertieName = new ArrayList();
189
                featuresToLockPropertieValue = new ArrayList();                
190
        }
191

    
192
        /**
193
         * @return Returns the buffer.
194
         */
195
        public Integer getMaxFeatures() {
196
                return maxFeatures;
197
        }
198

    
199

    
200
        /**
201
         * @param buffer The buffer to set.
202
         */
203
        public void setMaxFeatures(Integer buffer) {
204
                if (buffer != null){
205
                        this.maxFeatures = buffer;
206
                }
207
        }
208

    
209

    
210
        /**
211
         * @return Returns the featureName.
212
         */
213
        public String getFeatureName() {
214
                return featureName;
215
        }
216
        
217
        public String getFeatureFullName(){
218
            if (namespacePrefix == null){
219
                return featureName;
220
            }else{
221
                return namespacePrefix + ":" + featureName;
222
            }
223
        }
224

    
225

    
226
        /**
227
         * @param featureName The featureName to set.
228
         */
229
        public void setFeatureName(String featureName) {
230
            if (featureName != null){
231
            int index = featureName.indexOf(":");
232
            if (index>0){
233
                this.featureName = featureName.substring(index+1, featureName.length());
234
                namespacePrefix = featureName.substring(0, index);
235
            }else{
236
                this.featureName = featureName;
237
            }
238
        }           
239
        }
240

    
241
        /**
242
         * @return Returns the fields.
243
         */
244
        public String[] getFields() {
245
                if (fields == null){
246
                        fields = new String[0];
247
                }
248
                return fields;
249
        }
250

    
251

    
252
        /**
253
         * @param fields The fields to set.
254
         */
255
        public void setFields(String[] fields) {
256
                this.fields = fields;
257
        }
258

    
259
        public void setFields(String fields) {
260
                if (fields == null){
261
                        return;
262
                }
263
                this.fields = stringUtils.split(fields, ",");                
264
        }
265

    
266

    
267
        /**
268
         * @return Returns the password.
269
         */
270
        public String getPassword() {
271
                return password;
272
        }
273

    
274

    
275
        /**
276
         * @param password The password to set.
277
         */
278
        public void setPassword(String password) {
279
                this.password = password;
280
        }
281

    
282

    
283
        /**
284
         * @return Returns the timeout.
285
         */
286
        public Integer getTimeout() {
287
                return timeout;
288
        }
289

    
290

    
291
        /**
292
         * @param timeout The timeout to set.
293
         */
294
        public void setTimeout(Integer timeout) {
295
                if (timeout != null){
296
                        this.timeout = timeout;
297
                }
298
        }
299

    
300

    
301
        /**
302
         * @return Returns the userName.
303
         */
304
        public String getUserName() {
305
                return userName;
306
        }
307

    
308

    
309
        /**
310
         * @param userName The userName to set.
311
         */
312
        public void setUserName(String userName) {
313
                this.userName = userName;
314
        }
315

    
316
        public String getOnlineResource() {
317
                return onlineResource;
318
        }
319

    
320

    
321
        public void setOnlineResource(String url) {
322
                onlineResource = url;
323
        }
324

    
325
        /**
326
         * @return Returns the filterQuery.
327
         */
328
        public String getFilterByAttribute() {
329
                return filterByAttribute;
330
        }
331

    
332
        /**
333
         * @param filterQuery The filterQuery to set.
334
         */
335
        public void setFilterByAttribute(String filterQuery) {
336
                this.filterByAttribute = filterQuery;
337
        }        
338

    
339
        /**
340
         * @param filterByArea 
341
         * the filterByArea to set
342
         * @param operation
343
         * The geometric operation to apply. It has to be a value from 
344
         * {@link AbstractFilter}
345
         */
346
        public void setFilterByArea(Geometry geometry, String attributeName, String srs, Integer operation) {
347
                if (geometry == null){
348
                        return;
349
                }
350
                if (attributeName == null){
351
                        attributeName = "the_geom";
352
                }
353
                if (operation == null){
354
                        operation = new Integer(AbstractFilter.GEOMETRIC_OPERATOR_INTERSECT);
355
                }
356
                //TODO add a manager to register this
357
                this.filterByArea = new WFSGeometryFilterOperation(geometry,
358
                                operation.intValue(),
359
                                attributeName, 
360
                                getNamespacePrefix(),
361
                                getNamespaceLocation(),
362
                                srs);                                
363
        }        
364
        
365
        public void removeFilterByArea(){
366
            this.filterByArea = null;
367
        }
368
        
369
        public void removeFilterByAttribute(){
370
            this.filterByAttribute = null;
371
        }
372
        
373
        public void removeAllFilters(){
374
            removeFilterByArea();
375
            removeFilterByAttribute();
376
        }
377
        
378
        /**
379
         * @param filterByArea 
380
         * the filterByArea to set
381
         * @param operation
382
         * The geometric operation to apply. It has to be a value from 
383
         * {@link AbstractFilter}
384
         */
385
        public void setFilterByArea(Envelope envelope, String attributeName, String srs, Integer operation) {
386
                if (envelope == null){
387
                        return;
388
                }
389
                if (attributeName == null){
390
                        attributeName = "the_geom";
391
                }
392
                if (operation == null){
393
                        operation = new Integer(AbstractFilter.GEOMETRIC_OPERATOR_INTERSECT);
394
                }
395
                this.filterByArea = new WFSEnvelopeFilterOperation(envelope,
396
                                operation.intValue(),
397
                                attributeName, 
398
                                getNamespacePrefix(),
399
                                getNamespaceLocation(),
400
                                srs);                                
401
        }        
402
        
403
        /**
404
         * @return the filterByArea
405
         */
406
        public WFSSpatialFilterOperation getFilterByArea() {
407
                return filterByArea;
408
        }
409

    
410
        /**
411
         * @return the filterQueryLocked
412
         */
413
        public String getFilterQueryLocked() {
414
                FilterEncoding filter = new FilterEncoding(this);
415
                filter.setQualified(true);
416
                filter.setNamepacePrefix(null);
417
                filter.setHasBlankSpaces(false);
418
                return getFilterQueryLocked(filter);        
419
        }
420

    
421
        /**
422
         * @return the filterQueryLocked
423
         */
424
        public String getFilterQueryLockedPost() {
425
                FilterEncoding filter = new FilterEncoding(this);
426
                filter.setQualified(true);
427
                return getFilterQueryLocked(filter);
428
        }
429

    
430
        /**
431
         * Create a filter encoding request
432
         * @param filter
433
         * @return
434
         */
435
        private String getFilterQueryLocked(FilterEncoding filter){
436
                if ((featuresToLock.size() == 0) && 
437
                                (getLockedArea() == null) &&
438
                                (featuresToLockPropertieName.size() == 0)){
439
                        return null;
440
                }
441
                for (int i=0 ; i<featuresToLock.size() ; i++){
442
                        filter.addFeatureById(featuresToLock.get(i));
443
                }
444
                if (featuresToLockPropertieName.size() > 0){
445
                        for (int i=0 ; i<featuresToLockPropertieName.size() ; i++){
446
                                filter.addAndClause((String)featuresToLockPropertieName.get(i),
447
                                                (String)featuresToLockPropertieValue.get(i));                                                
448
                        }                                
449
                }
450
                if (lockedArea != null){
451
                        GeneralPathX generalPath = new GeneralPathX();
452
                        generalPath.moveTo(lockedArea.getMinX(), lockedArea.getMinY());
453
                        generalPath.lineTo(lockedArea.getMaxX(), lockedArea.getMinY());
454
                        generalPath.lineTo(lockedArea.getMaxX(), lockedArea.getMaxY());
455
                        generalPath.lineTo(lockedArea.getMinX(), lockedArea.getMaxY());
456
                        generalPath.lineTo(lockedArea.getMinX(), lockedArea.getMinY());
457
                        try {
458
                                filter.clearSpatialFilters();
459
                                filter.addSpatialFilter(geometryManager.createSurface(generalPath, SUBTYPES.GEOM2D),
460
                                                lockedAreaProperty, 
461
                                                getNamespacePrefix(),
462
                                                getNamespaceLocation(),
463
                                                getSrs(), 
464
                                                AbstractFilter.BBOX_ENCLOSES);
465
                        } catch (CreateGeometryException e) {
466
                                return null;
467
                        }
468
                        
469
                }
470
                return filter.toString();        
471
        }
472

    
473
        /**
474
         * @return the expiry
475
         */
476
        public int getExpiry() {
477
                return expiry;
478
        }
479

    
480
        /**
481
         * @param expiry the expiry to set
482
         */
483
        public void setExpiry(int expiry) {
484
                this.expiry = expiry;
485
        }
486

    
487
        /**
488
         * @return the lockAction
489
         */
490
        public String getLockAction() {
491
                return lockAction;
492
        }
493

    
494
        /**
495
         * Set the lock action to all
496
         */
497
        public void setLockActionToAll() {
498
                lockAction = LOCKACTION_ALL;
499
        }
500

    
501
        /**
502
         * Set teh lock action to some
503
         */
504
        public void setLockActionToSome() {
505
                lockAction = LOCKACTION_SOME;
506
        }
507
        
508
        public WFSTTransaction createNewTransaction(){
509
            transaction = new WFSTTransaction(this);
510
            return transaction;
511
        }
512
        
513
        public WFSTTransaction getTransaction(){
514
            return transaction;
515
        }
516

    
517
        /**
518
         * @return the neumber of features blocked
519
         */
520
        public int getFeaturesToLockSize() {
521
                return featuresToLock.size();
522
        }
523

    
524
        /**
525
         * Gets an identifier of a feature that is blocked
526
         * @param i
527
         * The id position
528
         * @return
529
         * The Id
530
         */
531
        public String getFeatureToLockAt(int i){
532
                if (i>featuresToLock.size()){
533
                        return null;
534
                }
535
                return (String)featuresToLock.get(i);
536
        }
537

    
538
        /**
539
         * Remove all the features to lock
540
         */
541
        public void removeFeaturesToLock() {
542
                featuresToLock.clear();
543
                featuresLocked.clear();
544
                featuresToLockPropertieName.clear();
545
                featuresToLockPropertieValue.clear();
546
        }
547

    
548
        /**
549
         * Adds a new feature locked
550
         * @param idFeature
551
         * the feature id
552
         */
553
        public void addFeatureToLock(String idFeature) {
554
                featuresToLock.add(idFeature);
555
        }
556

    
557
        /**
558
         * Adds a new feature locked
559
         * @param idFeature
560
         * the feature id
561
         */
562
        public void addFeatureToLock(String propertyName, String propertyValue){
563
                featuresToLockPropertieName.add(propertyName);
564
                featuresToLockPropertieValue.add(propertyValue);
565
        }
566

    
567
        /**
568
         * @return the idsLocked size
569
         */
570
        public int getFeaturesLocked() {
571
                return featuresLocked.size();
572
        }
573

    
574
        /**
575
         * Gets an identifier tha is blocked
576
         * @param i
577
         * The id position
578
         * @return
579
         * The Id
580
         */
581
        public String getFeatureLockedAt(int i){
582
                if (i>featuresLocked.size()){
583
                        return null;
584
                }
585
                return (String)featuresLocked.get(i);
586
        }
587

    
588
        /**
589
         * Adds a new Id
590
         * @param idLocked
591
         * the idLocked to add
592
         */
593
        public void addFeatureLocked(String lockId) {
594
                featuresLocked.add(lockId);
595
        }
596

    
597
        /**
598
         * @return the lockedArea
599
         */
600
        public Rectangle2D getLockedArea() {
601
                return lockedArea;
602
        }
603

    
604
        /**
605
         * @param lockedArea the lockedArea to set
606
         */
607
        public void setLockedArea(Rectangle2D lockedArea, String lockedAreaProperty) {
608
                this.lockedArea = lockedArea;
609
                this.lockedAreaProperty = lockedAreaProperty;
610
        }
611

    
612
        /**
613
         * @return the namespace prefix
614
         */
615
        public String getNamespacePrefix(){
616
                return namespacePrefix;
617
        }
618

    
619
        /**
620
         * @return the namespace URL
621
         */
622
        public String getNamespaceLocation(){
623
                return namespaceLocation;
624
        }
625

    
626
        /**
627
         * @param namespaceprefix the namespaceprefix to set
628
         */
629
        public void setNamespacePrefix(String namespacePrefix) {
630
                this.namespacePrefix = namespacePrefix;
631
        }
632

    
633
        /**
634
         * @param namespace the namespace to set
635
         */
636
        public void setNamespaceLocation(String namespaceLocation) {
637
                this.namespaceLocation = namespaceLocation;                
638
        }
639

    
640
        /**
641
         * @return the resultType
642
         */
643
        public int getResultType() {
644
                return resultType;
645
        }
646

    
647
        /**
648
         * @param resultType the resultType to set
649
         */
650
        public void setResultType(int resultType) {
651
                this.resultType = resultType;
652
        }
653
}