Statistics
| Revision:

svn-gvsig-desktop / import / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 18320

History | View | Annotate | Download (22.3 KB)

1
package com.iver.cit.gvsig.fmap.layers;
2

    
3
import java.awt.geom.Rectangle2D;
4
import java.io.IOException;
5
import java.net.ConnectException;
6
import java.net.MalformedURLException;
7
import java.net.URL;
8
import java.util.HashMap;
9
import java.util.Map;
10
import java.util.Vector;
11

    
12
import javax.swing.ImageIcon;
13

    
14
import org.gvsig.remoteClient.gml.schemas.XMLElement;
15
import org.gvsig.remoteClient.gml.types.IXMLType;
16
import org.gvsig.remoteClient.gml.types.XMLComplexType;
17
import org.gvsig.remoteClient.wfs.WFSStatus;
18
import org.gvsig.remoteClient.wfs.filters.FilterEncoding;
19

    
20
import com.iver.andami.PluginServices;
21
import com.iver.cit.gvsig.fmap.DriverException;
22
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
23
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
24
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
25
import com.iver.cit.gvsig.fmap.drivers.WFSDriverException;
26
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
27
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory;
28
import com.iver.cit.gvsig.fmap.drivers.wfs.filters.SQLExpressionFormat;
29
import com.iver.cit.gvsig.fmap.edition.wfs.WFSTLockFeaturesException;
30
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
31
import com.iver.utiles.StringUtilities;
32
import com.iver.utiles.XMLEntity;
33
import com.iver.utiles.extensionPoints.ExtensionPoint;
34
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
35

    
36
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
37
 *
38
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
39
 *
40
 * This program is free software; you can redistribute it and/or
41
 * modify it under the terms of the GNU General Public License
42
 * as published by the Free Software Foundation; either version 2
43
 * of the License, or (at your option) any later version.
44
 *
45
 * This program is distributed in the hope that it will be useful,
46
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
48
 * GNU General Public License for more details.
49
 *
50
 * You should have received a copy of the GNU General Public License
51
 * along with this program; if not, write to the Free Software
52
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
53
 *
54
 * For more information, contact:
55
 *
56
 *  Generalitat Valenciana
57
 *   Conselleria d'Infraestructures i Transport
58
 *   Av. Blasco Ib??ez, 50
59
 *   46010 VALENCIA
60
 *   SPAIN
61
 *
62
 *      +34 963862235
63
 *   gvsig@gva.es
64
 *      www.gvsig.gva.es
65
 *
66
 *    or
67
 *
68
 *   IVER T.I. S.A
69
 *   Salamanca 50
70
 *   46005 Valencia
71
 *   Spain
72
 *
73
 *   +34 963163400
74
 *   dac@iver.es
75
 */
76
/* CVS MESSAGES:
77
 *
78
 * $Id: FLyrWFS.java 18320 2008-01-25 13:16:03Z jpiera $
79
 * $Log$
80
 * Revision 1.10.2.14  2007-06-29 10:55:12  jorpiell
81
 * Encoding problem fixed
82
 *
83
 * Revision 1.10.2.12  2007/01/25 16:11:15  jorpiell
84
 * Se han cambiado los imports que hac?an referencia a remoteServices. Esto es as?, porque se han renombrado las clases del driver de GML
85
 *
86
 * Revision 1.10.2.11  2007/01/08 09:51:39  ppiqueras
87
 * Corregidos bugs + nueva funcionalidad, como que almacene informaci?n de los campos y valores que posee.
88
 *
89
 * Revision 1.27  2006/12/26 10:25:37  ppiqueras
90
 * Corregidas las dependencias con las nuevas ubicaciones de clases: IXMLType, XMLElement, IXMLComplexType, etc. (en libRemoteServices)
91
 *
92
 * Revision 1.26  2006/12/26 09:28:01  ppiqueras
93
 * Cambiado "atttibutes" en todas las aparaciones en atributos, m?todos, clases, paquetes o comentarios por "fields". (S?lo a aquellas que afectan a clases dentro del proyecto extWFS2).
94
 *
95
 * Revision 1.24  2006/12/15 13:55:17  ppiqueras
96
 * Almacena todos los campos y valores conocidos de la capa.
97
 *
98
 * Revision 1.23  2006/12/11 11:02:24  ppiqueras
99
 * Corregido bug -> que se mantenga la frase de filtrado
100
 *
101
 * Revision 1.22  2006/11/28 08:04:51  jorpiell
102
 * Se guarda la query para que pueda ser recuperada desde la ventana de propiedades
103
 *
104
 * Revision 1.21  2006/11/16 17:17:48  jorpiell
105
 * Se guarda el filtro en el gvp
106
 *
107
 * Revision 1.20  2006/11/16 13:29:47  jorpiell
108
 * Se ha reescrito losl m?todo para  guardar y recuperar gvps
109
 *
110
 * Revision 1.19  2006/11/15 17:38:08  jorpiell
111
 * Ya se puede guardar una capa en WFS.
112
 *
113
 * Revision 1.18  2006/10/31 12:24:04  jorpiell
114
 * Comprobado el caso en el que los atributos no tienen tipo
115
 *
116
 * Revision 1.17  2006/10/31 09:55:28  jorpiell
117
 * Se ha modificado el constructor del WFS desde cat?logo
118
 *
119
 * Revision 1.16  2006/10/31 09:38:15  jorpiell
120
 * Se ha creado una factoria para crear la capa. De ese modo no se repite c?digo desde le panel de propiedades y desde el panel de la capa
121
 *
122
 * Revision 1.15  2006/10/23 07:37:04  jorpiell
123
 * Ya funciona el filterEncoding
124
 *
125
 * Revision 1.14  2006/10/10 12:55:06  jorpiell
126
 * Se ha a?adido el soporte de features complejas
127
 *
128
 * Revision 1.13  2006/10/02 12:54:35  jorpiell
129
 * No se pod?a crear un mapa que tubiera la opci?n enlace vivo habilitada
130
 *
131
 * Revision 1.12  2006/10/02 09:09:45  jorpiell
132
 * Cambios del 10 copiados al head
133
 *
134
 * Revision 1.10.2.3  2006/09/29 14:12:53  luisw2
135
 * CRSFactory.getCRS substitutes ProjectionPool.get
136
 *
137
 * Revision 1.10.2.2  2006/09/28 08:54:01  jorpiell
138
 * Ya se puede reproyectar
139
 *
140
 * Revision 1.10.2.1  2006/09/26 07:36:24  jorpiell
141
 * El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
142
 *
143
 * Revision 1.10  2006/09/05 15:41:52  jorpiell
144
 * A?adida la funcionalidad de cargar WFS desde el cat?logo
145
 *
146
 * Revision 1.9  2006/07/05 12:05:41  jorpiell
147
 * Se ha modificado para que avise si se han recuperado las mismas features que marca el campo buffer
148
 *
149
 * Revision 1.8  2006/06/21 12:52:10  jorpiell
150
 * A?adido un icono para la capa WFS
151
 *
152
 * Revision 1.7  2006/06/21 12:35:45  jorpiell
153
 * Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
154
 *
155
 * Revision 1.6  2006/06/15 11:17:06  jorpiell
156
 * Se ha encontrado la forma de comprobar cuando se prodicia un error de parseo al hacer un hasnext (en la feature). Se atrapa y se lanza la excepci?n hacia arriba
157
 *
158
 * Revision 1.5  2006/06/14 07:57:19  jorpiell
159
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
160
 *
161
 * Revision 1.4  2006/06/05 16:49:31  caballero
162
 * poder editar y exportar
163
 *
164
 * Revision 1.3  2006/05/25 10:31:55  jorpiell
165
 * Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
166
 *
167
 * Revision 1.2  2006/05/23 13:21:59  jorpiell
168
 * Si hay alg?n problema en la carga se muestra un mensaje de error
169
 *
170
 * Revision 1.1  2006/05/19 12:54:11  jorpiell
171
 * Creada la capa WFS
172
 *
173
 *
174
 */
175
/**
176
 *  FMap's WFS Layer class.
177
 *
178
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
179
 */
180
public class FLyrWFS extends FLyrVect{
181
        private URL host = null;
182
        private String onlineResource = null;
183
        private String name = null;
184
        private String layerName = null;
185
        private String userName = null;
186
        private String password = null;
187
        private String FieldsQuery = null;
188
        private String CoordinatesQuery = null;
189
        private String visualFilterQuery = null;
190
        private XMLElement[] fields = null;
191
        private int numfeatures = 100;
192
        private int timeout = 10000;
193
        private int wfstExpiryTime = 0;
194
        private String srs = null;
195
        private FMapWFSDriver wfsDriver = null;
196
        private WFSLayerNode wfsLayerNode = null;
197
        private Map allFieldsAndValuesKnown = null;
198
        private WFSStatus status = null;
199
        
200
        /**
201
         * Constructor
202
         */
203
        public FLyrWFS(){
204
                super();
205
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("WFSExtension");
206
                if (extensionPoint != null){
207
                        try {
208
                                WFSLayerListener listener = (WFSLayerListener)extensionPoint.create("WFSLayerListener");
209
                                listener.setWfsLayer(this);
210
                                addLayerListener(listener);
211
                        } catch (Exception e) {
212
                                //Impossible to Use the WFST lockoperation
213
                        }
214
                }
215
        }
216

    
217
        /**
218
         * Constructor to load a new layer from a catalog
219
         * search
220
         * @param args
221
         * Params to load a new layer
222
         * @throws WFSDriverException 
223
         * @throws IOException 
224
         * @throws MalformedURLException 
225
         * @throws ConnectException 
226
         * @throws DriverIOException 
227
         */
228
        public FLyrWFS(Map args) throws WFSDriverException, ConnectException, MalformedURLException, IOException, DriverIOException{
229
                this();
230
                String[] sLayer = (String[])args.get("layer");
231
                String user = (String)args.get("user");
232
                String pwd = (String)args.get("pwd");
233
                String host = (String)args.get("host");        
234
                String projection = (String)args.get("projection");
235

    
236
                FMapWFSDriver driver = FMapWFSDriverFactory.getFMapDriverForURL(new URL(host));
237
                WFSLayerNode[] layers = driver.getLayerList();
238
                WFSLayerNode layer = driver.getLayerInfo(sLayer[0]);
239

    
240
                layer.setSelectedFields(layer.getFields());
241

    
242
                Vector vAtts = new Vector();
243
                if (layer.getFields().size() == 1){
244
                        XMLElement element = (XMLElement)layer.getFields().get(0);
245
                        if (element.getEntityType().getType() != IXMLType.COMPLEX){
246
                                vAtts.add(element);
247
                        }else{
248
                                vAtts = ((XMLComplexType)element.getEntityType()).getAttributes();
249
                        }
250
                }
251
                for (int i=0 ; i<layer.getFields().size() ; i++){
252
                        XMLElement element = (XMLElement)layer.getFields().get(i);
253
                        if (element.getEntityType().getType() != IXMLType.COMPLEX){
254
                                vAtts.add((XMLElement)layer.getFields().get(i));
255
                        }else{
256

    
257
                        }
258
                }
259

    
260
                XMLElement[] atts = new XMLElement[vAtts.size()];
261
                for (int i=0 ; i<vAtts.size() ; i++){
262
                        atts[i] = (XMLElement)vAtts.get(i);
263
                }
264

    
265
                setHost(host);
266
                setName(sLayer[0]);
267
                setLayerName(sLayer[0]);
268
                setWfsLayerNode(layer);
269
                setFields(atts);
270
                setUserName(user);
271
                setPassword(pwd);
272
                setNumfeatures(10000);
273
                setTimeout(10000);
274
                setWfsDriver(driver);                        
275
                setProjection(CRSFactory.getCRS(projection));
276

    
277
                load();            
278
        }
279

    
280

    
281
        /**
282
         * Loads the features from the server
283
         */
284
        public void load() throws DriverIOException{
285
                WFSAdapter adapter = new WFSAdapter();
286
                try {
287
                        wfsDriver.getFeature(getWFSStatus());
288

    
289
                        adapter.setDriver((VectorialDriver) wfsDriver);
290
                        setSource(adapter);
291

    
292
                        if (getLegend() == null){
293
                                setLegend(LegendFactory.createSingleSymbolLegend(
294
                                                getShapeType()));
295
                        }
296
                } catch (Exception e){
297
                        e.printStackTrace();
298
                        throw new DriverIOException(e.getMessage());
299
                }
300
        }
301

    
302
        /**
303
         * Gets the WFS Status
304
         * @return
305
         */
306
        private WFSStatus getWFSStatus(){
307
                if (status == null){
308
                        status = wfsDriver.getStatus();
309
                }else{
310
                        status.setFeatureName(getLayerName());
311
                }
312
                status.setUserName(getUserName());
313
                status.setPassword(getPassword());
314
                status.setBuffer(getNumfeatures());
315
                status.setTimeout(getTimeout());
316
                status.setFields(getFieldNames());
317
                status.setOnlineResource(getOnlineResource());
318
                status.setSrs(getSrs());
319
                //Filter Encoding transformation
320
                FilterEncoding fe = SQLExpressionFormat.createFilter();                                
321
                fe.setQuery(getFieldsQuery());
322
                status.setFilterQuery(fe.toString());
323
                status.setFilterVisualText(getVisualFilterQuery());
324
                return status;
325
        }
326

    
327
        /**
328
         * @return Returns the layerName.
329
         */
330
        public String getLayerName() {
331
                return layerName;
332
        }
333
        /**
334
         * @param layerName The layerName to set.
335
         */
336
        public void setLayerName(String layerName) {
337
                this.layerName = layerName;
338
        }
339
        /**
340
         * @return Returns the numfeatures.
341
         */
342
        public int getNumfeatures() {
343
                return numfeatures;
344
        }
345
        /**
346
         * @param numfeatures The numfeatures to set.
347
         */
348
        public void setNumfeatures(int numfeatures) {
349
                this.numfeatures = numfeatures;
350
        }
351

    
352
        /**
353
         * @return Returns the pwd.
354
         */
355
        public String getPassword() {
356
                return password;
357
        }
358
        /**
359
         * @param pwd The pwd to set.
360
         */
361
        public void setPassword(String password) {
362
                this.password = password;
363
        }
364
        /**
365
         * @return Returns the timeout.
366
         */
367
        public int getTimeout() {
368
                return timeout;
369
        }
370
        /**
371
         * @param timeout The timeout to set.
372
         */
373
        public void setTimeout(int timeout) {
374
                this.timeout = timeout;
375
        }
376
        /**
377
         * @return Returns the user.
378
         */
379
        public String getUserName() {
380
                return userName;
381
        }
382
        /**
383
         * @param user The user to set.
384
         */
385
        public void setUserName(String userName) {
386
                this.userName = userName;
387
        }
388
        /**
389
         * @return The visual filtering text from "Where"
390
         */
391
        public String getVisualFilterQuery() {
392
                return visualFilterQuery;
393
        }
394
        /**
395
         * @param visualFilterQuery The visual filtering text from "Where"
396
         */
397
        public void setVisualFilterQueyr(String visualFilterQuery) {
398
                this.visualFilterQuery = visualFilterQuery;
399
        }
400
        /**
401
         * @return Returns the fields.
402
         */
403
        public XMLElement[] getFields() {
404
                if (fields == null){
405
                        return new XMLElement[0];
406
                }
407
                return fields;
408
        }
409

    
410
        /**
411
         * Return the fields name
412
         * @return
413
         */
414
        public String[] getFieldNames(){
415
                Vector vFields = new Vector();
416
                for (int i=0 ; i<getFields().length ; i++){
417
                        if ((getFields()[i].getEntityType() == null) || 
418
                                        (getFields()[i].getEntityType().getType() != IXMLType.COMPLEX)){
419
                                vFields.add(getFields()[i].getName());
420
                        }
421
                }
422
                String[] fields = new String[vFields.size()];
423
                for (int i=0 ; i<vFields.size() ; i++){
424
                        fields[i] = (String)vFields.get(i);
425
                }
426
                return fields;
427
        }
428

    
429
        /**
430
         * @param fields The fields to set.
431
         */
432
        public void setFields(XMLElement[] fields) {
433
                this.fields = fields;
434
        }
435
        /**
436
         * @return Returns the name.
437
         */
438
        public String getName() {
439
                return name;
440
        }
441
        /**
442
         * @param name The name to set.
443
         */
444
        public void setName(String name) {
445
                this.name = name;
446
        }
447
        /**
448
         * @return Returns the host.
449
         */
450
        public URL getHost() {
451
                return host;
452
        }
453
        /**
454
         * @param host The host to set.
455
         */
456
        public void setHost(URL host) {
457
                this.host = host;
458
        }
459

    
460
        /**
461
         * @return Returns the wfs.
462
         */
463
        public FMapWFSDriver getWfsDriver() {
464
                return wfsDriver;
465
        }
466

    
467
        /**
468
         * @param wfs The wfs to set.
469
         */
470
        public void setWfsDriver(FMapWFSDriver wfs) {
471
                this.wfsDriver = wfs;
472
        }
473

    
474

    
475
        /*
476
         *  (non-Javadoc)
477
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getStrategy()
478
         */
479
//        public Strategy getStrategy() {
480
//        if (wfsStrategy == null){
481
//        wfsStrategy = new WFSStrategy(this);
482
//        }
483
//        return wfsStrategy;
484
//        }
485

    
486
        /*
487
         *  (non-Javadoc)
488
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
489
         */
490
        public Rectangle2D getFullExtent() throws DriverException {
491
                try {
492
                        Rectangle2D extent = wfsDriver.getFullExtent();
493
                        if (extent == null){
494
                                return null;
495
                        }
496
                        if (getCoordTrans() != null){
497
                                return getCoordTrans().convert(extent);
498
                        }
499
                        return extent;
500
                } catch (IOException e) {
501
                        throw new DriverException(e.toString());
502
                }
503
        }
504

    
505
        /**
506
         * @return Returns the onlineResource.
507
         */
508
        public String getOnlineResource() {
509
                return onlineResource;
510
        }
511

    
512
        /**
513
         * @param onlineResource The onlineResource to set.
514
         */
515
        public void setOnlineResource(String onlineResource) {
516
                this.onlineResource = onlineResource;
517
        }
518

    
519
        public HashMap getProperties() {
520
                HashMap info = new HashMap();
521
                info.put("name", getName());
522
                info.put("layerName", getLayerName());
523
                info.put("layerText", getLayerText());
524
                info.put("attributes", getFields());
525
                info.put("host", getHost());        
526
                info.put("wfsLayerNode", getWfsLayerNode());        
527
                info.put("status",getWFSStatus());                        
528
                return info;
529

    
530
        }
531

    
532
        /**
533
         * @return Returns the wfsLayerNode.
534
         */
535
        public WFSLayerNode getWfsLayerNode() {
536
                return wfsLayerNode;
537
        }
538

    
539
        /**
540
         * @param wfsLayerNode The wfsLayerNode to set.
541
         */
542
        public void setWfsLayerNode(WFSLayerNode wfsLayerNode) {
543
                this.wfsLayerNode = wfsLayerNode;
544
        }
545

    
546
        public void setHost(String host2) {
547
                try {
548
                        setHost(new URL(host2));
549
                } catch (MalformedURLException e) {
550
                        // TODO Auto-generated catch block
551
                        e.printStackTrace();
552
                }                
553
        }
554

    
555
        public ImageIcon getTocImageIcon() {                        
556
                return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wfs2").getClassLoader().getResource("images/icoLayer.png"));
557
        }
558

    
559
        /*
560
         *  (non-Javadoc)
561
         * @see com.iver.cit.gvsig.fmap.layers.FLyrVect#isPropertiesMenuVisible()
562
         */
563
        public boolean isPropertiesMenuVisible(){
564
                return false;
565
        }
566

    
567
        public String getSrs() {
568
                return srs;
569
        }
570

    
571
        public void setSrs(String srs) {
572
                this.srs = srs;
573
        }
574

    
575
        /**
576
         * @return XMLEntity.
577
         * @throws XMLException
578
         */
579
        public XMLEntity getXMLEntity() throws XMLException {        
580
                XMLEntity xml = super.getXMLEntity();                
581

    
582
                // Full extent
583
                try {
584
                        xml.putProperty("fullExtent", StringUtilities.rect2String(getFullExtent()));
585
                } catch (DriverException e) {
586
                        // TODO Auto-generated catch block
587
                        e.printStackTrace();
588
                }
589

    
590
                // Host
591
                xml.putProperty("host", host.toExternalForm());
592

    
593
                // Layer name
594
                xml.putProperty("layerName", getLayerName());                
595
                xml.putProperty("name", getName());
596

    
597
                //Layer fields
598
                XMLElement[] fields = getFields();
599
                String strFields = "";
600
                for (int i=0 ; i<fields.length ; i++){
601
                        //If is not the root node
602
                        if (fields[i].getParentElement() != null){
603
                                strFields = strFields + fields[i].getFullName();
604
                                if (i < fields.length - 1){
605
                                        strFields = strFields + "~##SEP1##~";
606
                                }
607
                        }else{
608
                                xml.putProperty("rootNode", true);
609
                        }
610
                }
611
                xml.putProperty("fields", strFields);
612

    
613
                // User name
614
                xml.putProperty("user", getUserName());
615

    
616
                // SRS
617
                xml.putProperty("srs", getSrs());                
618

    
619
                // OnlineResources
620
                xml.putProperty("onlineResource", getOnlineResource());
621

    
622
                // TimeOut
623
                xml.putProperty("timeout", getTimeout());                
624

    
625
                // Buffer
626
                xml.putProperty("buffer", getNumfeatures());
627

    
628
                //Projection
629
                xml.putProperty("projection",getProjection().getAbrev());
630

    
631
                //Filter
632
                xml.putProperty("filterEncoding",getFieldsQuery());
633

    
634
                return xml;
635
        }
636

    
637
        /**
638
         * @param xml XMLEntity
639
         *
640
         * @throws XMLException
641
         * @throws DriverException
642
         * @throws DriverI OException
643
         */
644
        public void setXMLEntity(XMLEntity xml)throws XMLException {
645

    
646
                // Host
647
                try {
648
                        host = new URL(xml.getStringProperty("host"));
649
                } catch (MalformedURLException e) {
650
                        throw new XMLException(e);
651
                }
652

    
653
                // Layer name
654
                setLayerName(xml.getStringProperty("layerName"));                        
655
                setName(xml.getStringProperty("name"));                
656

    
657
                // User name
658
                if (xml.contains("user")){
659
                        setUserName(xml.getStringProperty("user"));
660
                }
661

    
662
                // SRS
663
                if (xml.contains("srs")){
664
                        setSrs(xml.getStringProperty("srs"));
665
                }
666

    
667
                // OnlineResources
668
                if (xml.contains("onlineResource")){
669
                        setOnlineResource(xml.getStringProperty("onlineResource"));
670
                }
671

    
672
                // TimeOut
673
                if (xml.contains("timeout")){
674
                        setTimeout(xml.getIntProperty("timeout"));
675
                }
676

    
677
                // Buffer
678
                if (xml.contains("buffer")){
679
                        setNumfeatures(xml.getIntProperty("buffer"));
680
                }
681

    
682
                //Projection
683
                if (xml.contains("projection")){
684
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("projection")));
685
                }       
686

    
687
                //Filter
688
                if (xml.contains("filterEncoding")){
689
                        setFieldsQuery(xml.getStringProperty("filterEncoding"));
690
                }   
691

    
692
                // Layer fields
693
                FMapWFSDriver driver;
694
                try {
695
                        driver = FMapWFSDriverFactory.getFMapDriverForURL(host);
696
                        setWfsDriver(driver);        
697
                        WFSAdapter adapter = new WFSAdapter();
698
                        adapter.setDriver((VectorialDriver) wfsDriver);
699
                        setSource(adapter);
700
                        super.setXMLEntity(xml);
701
                        setLegend(LegendFactory.createFromXML(xml.getChild(0)));
702
                } catch (Exception e) {
703
                        throw new XMLException(e);        
704
                }
705
                driver.getLayerList();
706
                WFSLayerNode layer = driver.getLayerInfo(getLayerName());                        
707
                XMLElement[] atts = null;                
708

    
709
//                The root element always exists
710
                XMLElement rootElement = (XMLElement)layer.getFields().get(0);
711

    
712
                if (xml.contains("fields")) {
713
                        String[] fields = xml.getStringProperty("fields").split("~##SEP1##~");        
714
                        if ((fields.length == 1) && (fields[0].equals(""))){
715
                                fields = new String[0];
716
                        }
717
                        //The root element always is a complex type
718
                        Vector allFields = ((XMLComplexType)rootElement.getEntityType()).getAttributes();
719
                        //If the root node has been selected
720
                        if (xml.contains("rootNode")){
721
                                if (xml.getBooleanProperty("rootNode")==true){
722
                                        atts = new XMLElement[fields.length + 1];
723
                                        atts[fields.length] = rootElement;
724
                                }else{
725
                                        atts = new XMLElement[fields.length];
726
                                }
727
                        }else{
728
                                atts = new XMLElement[fields.length];
729
                        }
730
                        //Adding the other fields
731
                        for (int i=0 ; i<fields.length ; i++){
732
                                for (int j=0 ; j<allFields.size() ; j++){
733
                                        XMLElement field = (XMLElement)allFields.get(j);
734
                                        if (field != null){
735
                                                XMLElement found = field.searchAttribute(fields[i]);
736
                                                if (found != null){
737
                                                        atts[i] = found;
738
                                                        break;
739
                                                }
740
                                        }
741
                                }                                        
742
                        }                        
743
                }else{
744
                        if (xml.contains("rootNode")){
745
                                if (xml.getBooleanProperty("rootNode")==true){
746
                                        atts = new XMLElement[1];
747
                                        atts[0] = rootElement;
748
                                }
749
                        }
750
                }
751
                layer.setSelectedFields(atts);
752
                setWfsLayerNode(layer);
753
                setFields(atts);        
754
                setAvailable(true);
755
        }
756

    
757
        /**
758
         * @return Returns the fieldsQuery.
759
         */
760
        public String getFieldsQuery() {
761
                return FieldsQuery;
762
        }
763

    
764
        /**
765
         * @param fieldsQuery The fieldsQuery to set.
766
         */
767
        public void setFieldsQuery(String fieldsQuery) {
768
                FieldsQuery = fieldsQuery;
769
        }
770

    
771
        /**
772
         * @return Returns the coordinatesQuery.
773
         */
774
        public String getCoordinatesQuery() {
775
                return CoordinatesQuery;
776
        }
777

    
778
        /**
779
         * @param coordinatesQuery The coordinatesQuery to set.
780
         */
781
        public void setCoordinatesQuery(String coordinatesQuery) {
782
                CoordinatesQuery = coordinatesQuery;
783
        }
784

    
785
        /**
786
         * Sets all fields and values known about this layer
787
         * 
788
         * @param _allFieldsAndValuesKnown A Map
789
         */
790
        public void setAllFieldsAndValuesKnown(Map _allFieldsAndValuesKnown) {
791
                if (this.allFieldsAndValuesKnown == null)
792
                        allFieldsAndValuesKnown = new HashMap();
793

    
794
                allFieldsAndValuesKnown = _allFieldsAndValuesKnown;
795
        }
796

    
797
        /**
798
         * Gets all fields and values known about this layer
799
         * 
800
         * @return A Map
801
         */
802
        public Map getAllFieldsAndValuesKnown() {
803
                return allFieldsAndValuesKnown;
804
        }
805

    
806
        /**
807
         * @return the isWfstEditing
808
         */
809
        public boolean isWfstEditing() {
810
                return wfsDriver.isWfstEditing();
811
        }
812

    
813
        /**
814
         * @param isWfstEditing the isWfstEditing to set
815
         */
816
        public void setWfstEditing(boolean isWfstEditing) {
817
                wfsDriver.setWfstEditing(isWfstEditing);
818
        }
819
        
820
        /**
821
         * It locks all the features
822
         * @param expiryTime
823
         * The maximum time to edit
824
         * @throws WFSTLockFeaturesException 
825
         */
826
        public void lockCurrentFeatures(int expiryTime) throws WFSTLockFeaturesException{
827
                wfstExpiryTime = expiryTime;
828
                wfsDriver.lockCurrentFeatures(expiryTime);
829
        }
830

    
831
        /**
832
         * @return the wfstExpiryTime
833
         */
834
        public int getWfstExpiryTime() {
835
                return wfstExpiryTime;
836
        }
837
        
838
        /**
839
         * @return true if the layer can be edit using WFST
840
         */
841
        public boolean isTransactional(){
842
                return wfsDriver.isTransactional();
843
        }
844

    
845
        /**
846
         * @param wfstExpiryTime the wfstExpiryTime to set
847
         */
848
        public void setWfstExpiryTime(int wfstExpiryTime) {
849
                this.wfstExpiryTime = wfstExpiryTime;
850
        }
851
        
852
        
853
        /**
854
         * @return the isWfstGeometriesUpdated
855
         */
856
        public boolean isWfstGeometriesUpdated() {
857
                return wfsDriver.isWfstGeometriesUpdated();
858
        }
859

    
860
        /**
861
         * @param isWfstGeometriesUpdated the isWfstGeometriesUpdated to set
862
         */
863
        public void setWfstGeometriesUpdated(boolean isWfstGeometriesUpdated) {
864
                wfsDriver.setWfstGeometriesUpdated(isWfstGeometriesUpdated);
865
        }
866
}