Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 10392

History | View | Annotate | Download (22.2 KB)

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

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

    
15
import javax.swing.ImageIcon;
16

    
17
import org.gvsig.remoteClient.gml.schemas.XMLElement;
18
import org.gvsig.remoteClient.gml.types.IXMLType;
19
import org.gvsig.remoteClient.gml.types.XMLComplexType;
20
import org.gvsig.remoteClient.wfs.WFSStatus;
21
import org.gvsig.remoteClient.wfs.filters.AFilter;
22
import org.gvsig.remoteClient.wfs.filters.FilterEncoding;
23

    
24
import com.iver.andami.PluginServices;
25
import com.iver.cit.gvsig.fmap.DriverException;
26
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
27
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
28
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
29
import com.iver.cit.gvsig.fmap.drivers.WFSException;
30
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
31
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory;
32
import com.iver.cit.gvsig.fmap.drivers.wfs.filters.SQLExpressionFormat;
33
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
34
import com.iver.utiles.StringUtilities;
35
import com.iver.utiles.XMLEntity;
36

    
37
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
38
 *
39
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
40
 *
41
 * This program is free software; you can redistribute it and/or
42
 * modify it under the terms of the GNU General Public License
43
 * as published by the Free Software Foundation; either version 2
44
 * of the License, or (at your option) any later version.
45
 *
46
 * This program is distributed in the hope that it will be useful,
47
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49
 * GNU General Public License for more details.
50
 *
51
 * You should have received a copy of the GNU General Public License
52
 * along with this program; if not, write to the Free Software
53
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
54
 *
55
 * For more information, contact:
56
 *
57
 *  Generalitat Valenciana
58
 *   Conselleria d'Infraestructures i Transport
59
 *   Av. Blasco Ib??ez, 50
60
 *   46010 VALENCIA
61
 *   SPAIN
62
 *
63
 *      +34 963862235
64
 *   gvsig@gva.es
65
 *      www.gvsig.gva.es
66
 *
67
 *    or
68
 *
69
 *   IVER T.I. S.A
70
 *   Salamanca 50
71
 *   46005 Valencia
72
 *   Spain
73
 *
74
 *   +34 963163400
75
 *   dac@iver.es
76
 */
77
/* CVS MESSAGES:
78
 *
79
 * $Id: FLyrWFS.java 10392 2007-02-19 11:44:42Z jorpiell $
80
 * $Log$
81
 * Revision 1.31  2007-02-19 11:44:42  jorpiell
82
 * A?adidos los filtros por ?rea
83
 *
84
 * Revision 1.30  2007/02/09 14:12:38  jorpiell
85
 * Soporte para WFS 1.1 y WFS-T
86
 *
87
 * Revision 1.29  2007/01/12 13:09:41  jorpiell
88
 * added searches by area
89
 *
90
 * Revision 1.28  2007/01/10 08:23:02  jorpiell
91
 * If the parent element is selected is not necessary to select its children
92
 *
93
 * Revision 1.27  2006/12/26 10:25:37  ppiqueras
94
 * Corregidas las dependencias con las nuevas ubicaciones de clases: IXMLType, XMLElement, IXMLComplexType, etc. (en libRemoteServices)
95
 *
96
 * Revision 1.26  2006/12/26 09:28:01  ppiqueras
97
 * 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).
98
 *
99
 * Revision 1.24  2006/12/15 13:55:17  ppiqueras
100
 * Almacena todos los campos y valores conocidos de la capa.
101
 *
102
 * Revision 1.23  2006/12/11 11:02:24  ppiqueras
103
 * Corregido bug -> que se mantenga la frase de filtrado
104
 *
105
 * Revision 1.22  2006/11/28 08:04:51  jorpiell
106
 * Se guarda la query para que pueda ser recuperada desde la ventana de propiedades
107
 *
108
 * Revision 1.21  2006/11/16 17:17:48  jorpiell
109
 * Se guarda el filtro en el gvp
110
 *
111
 * Revision 1.20  2006/11/16 13:29:47  jorpiell
112
 * Se ha reescrito losl m?todo para  guardar y recuperar gvps
113
 *
114
 * Revision 1.19  2006/11/15 17:38:08  jorpiell
115
 * Ya se puede guardar una capa en WFS.
116
 *
117
 * Revision 1.18  2006/10/31 12:24:04  jorpiell
118
 * Comprobado el caso en el que los atributos no tienen tipo
119
 *
120
 * Revision 1.17  2006/10/31 09:55:28  jorpiell
121
 * Se ha modificado el constructor del WFS desde cat?logo
122
 *
123
 * Revision 1.16  2006/10/31 09:38:15  jorpiell
124
 * 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
125
 *
126
 * Revision 1.15  2006/10/23 07:37:04  jorpiell
127
 * Ya funciona el filterEncoding
128
 *
129
 * Revision 1.14  2006/10/10 12:55:06  jorpiell
130
 * Se ha a?adido el soporte de features complejas
131
 *
132
 * Revision 1.13  2006/10/02 12:54:35  jorpiell
133
 * No se pod?a crear un mapa que tubiera la opci?n enlace vivo habilitada
134
 *
135
 * Revision 1.12  2006/10/02 09:09:45  jorpiell
136
 * Cambios del 10 copiados al head
137
 *
138
 * Revision 1.10.2.3  2006/09/29 14:12:53  luisw2
139
 * CRSFactory.getCRS substitutes ProjectionPool.get
140
 *
141
 * Revision 1.10.2.2  2006/09/28 08:54:01  jorpiell
142
 * Ya se puede reproyectar
143
 *
144
 * Revision 1.10.2.1  2006/09/26 07:36:24  jorpiell
145
 * El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
146
 *
147
 * Revision 1.10  2006/09/05 15:41:52  jorpiell
148
 * A?adida la funcionalidad de cargar WFS desde el cat?logo
149
 *
150
 * Revision 1.9  2006/07/05 12:05:41  jorpiell
151
 * Se ha modificado para que avise si se han recuperado las mismas features que marca el campo buffer
152
 *
153
 * Revision 1.8  2006/06/21 12:52:10  jorpiell
154
 * A?adido un icono para la capa WFS
155
 *
156
 * Revision 1.7  2006/06/21 12:35:45  jorpiell
157
 * 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
158
 *
159
 * Revision 1.6  2006/06/15 11:17:06  jorpiell
160
 * 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
161
 *
162
 * Revision 1.5  2006/06/14 07:57:19  jorpiell
163
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
164
 *
165
 * Revision 1.4  2006/06/05 16:49:31  caballero
166
 * poder editar y exportar
167
 *
168
 * Revision 1.3  2006/05/25 10:31:55  jorpiell
169
 * Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
170
 *
171
 * Revision 1.2  2006/05/23 13:21:59  jorpiell
172
 * Si hay alg?n problema en la carga se muestra un mensaje de error
173
 *
174
 * Revision 1.1  2006/05/19 12:54:11  jorpiell
175
 * Creada la capa WFS
176
 *
177
 *
178
 */
179
/**
180
 *  FMap's WFS Layer class.
181
 *
182
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
183
 */
184
public class FLyrWFS extends FLyrVect{
185
        private URL host = null;
186
        private String onlineResource = null;
187
        private String name = null;
188
        private String layerName = null;
189
        private String nameSapce = null;
190
    private String userName = null;
191
    private String password = null;
192
    private String FieldsQuery = null;
193
    private Rectangle2D bbox = null;
194
    private String bboxPropertyName = null;
195
    private String visualFilterQuery = null;
196
    private Rectangle2D extent = null;
197
    private XMLElement[] fields = null;
198
    private int numfeatures = 100;
199
    private int timeout = 10000;
200
    private String srs = null;
201
    private FMapWFSDriver wfsDriver = null;
202
    private WFSLayerNode wfsLayerNode = null;
203
    private Map allFieldsAndValuesKnown = null;
204
    
205
    /**
206
     * Constructor
207
     */
208
    public FLyrWFS(){
209
            super();
210
    }
211
    
212
    /**
213
     * Constructor to load a new layer from a catalog
214
     * search
215
     * @param args
216
     * Params to load a new layer
217
     * @throws WFSException 
218
     * @throws IOException 
219
     * @throws MalformedURLException 
220
     * @throws ConnectException 
221
     * @throws DriverIOException 
222
     */
223
    public FLyrWFS(Map args) throws WFSException, ConnectException, MalformedURLException, IOException, DriverIOException{
224
            String[] sLayer = (String[])args.get("layer");
225
            String[] sNamespace = (String[])args.get("namespace");
226
                String user = (String)args.get("user");
227
                String pwd = (String)args.get("pwd");
228
                String host = (String)args.get("host");        
229
                String projection = (String)args.get("projection");
230
                
231
                FMapWFSDriver driver = FMapWFSDriverFactory.getFMapDriverForURL(new URL(host));
232
                WFSLayerNode[] layers = driver.getLayerList();
233
                WFSLayerNode layer = driver.getLayerInfo(sLayer[0],sNamespace[0]);
234
                
235
                layer.setSelectedFields(layer.getFields());
236
                
237
                Vector vAtts = new Vector();
238
                if (layer.getFields().size() == 1){
239
                        XMLElement element = (XMLElement)layer.getFields().get(0);
240
                        if (element.getEntityType().getType() != IXMLType.COMPLEX){
241
                                vAtts.add(element);
242
                        }else{
243
                                vAtts = ((XMLComplexType)element.getEntityType()).getAttributes();
244
                        }
245
                }
246
                for (int i=0 ; i<layer.getFields().size() ; i++){
247
                        XMLElement element = (XMLElement)layer.getFields().get(i);
248
                        if (element.getEntityType().getType() != IXMLType.COMPLEX){
249
                                vAtts.add((XMLElement)layer.getFields().get(i));
250
                        }else{
251
                                
252
                        }
253
                }
254
                
255
                XMLElement[] atts = new XMLElement[vAtts.size()];
256
                for (int i=0 ; i<vAtts.size() ; i++){
257
                        atts[i] = (XMLElement)vAtts.get(i);
258
                }
259
        
260
                setHost(host);
261
                setName(sLayer[0]);
262
                setLayerName(sLayer[0]);
263
                setWfsLayerNode(layer);
264
                setFields(atts);
265
                setUserName(user);
266
                setPassword(pwd);
267
                setNumfeatures(10000);
268
                setTimeout(10000);
269
                setWfsDriver(driver);                        
270
                setProjection(CRSFactory.getCRS(projection));
271
                
272
            load();            
273
    }
274
    
275

    
276
    /**
277
     * Loads the features from the server
278
     */
279
    public void load() throws DriverIOException{
280
            WFSAdapter adapter = new WFSAdapter();
281
            try {
282
                    wfsDriver.getFeature(getWFSStatus());
283

    
284
                    adapter.setDriver((VectorialDriver) wfsDriver);
285
                    setSource(adapter);
286

    
287
                    if (getLegend() == null){
288
                            setLegend(LegendFactory.createSingleSymbolLegend(
289
                                    getShapeType()));
290
                    }
291
            } catch (Exception e){
292
                    e.printStackTrace();
293
                    throw new DriverIOException(e.getMessage());
294
            }
295
    }
296

    
297
    /**
298
     * Gets the WFS Status
299
     * @return
300
     */
301
    private WFSStatus getWFSStatus(){
302
            WFSStatus status = new WFSStatus(getLayerName(),getNameSapce());
303
            status.setUserName(getUserName());
304
            status.setPassword(getPassword());
305
            status.setBuffer(getNumfeatures());
306
            status.setTimeout(getTimeout());
307
            status.setFields(getFieldNames());
308
            status.setOnlineResource(getOnlineResource());
309
            status.setSrs(getSrs());
310
            status.setBBox(getExtent());
311
            //Filter Encoding transformation
312
            FilterEncoding fe = SQLExpressionFormat.createFilter();                                
313
                fe.setQuery(getFieldsQuery());
314
                fe.setBBox(getBbox(), getBboxPropertyName(), getSrs(), AFilter.BBOX_ENCLOSES);
315
                try {
316
                        status.setFilterQuery(URLEncoder.encode(fe.toString(),"8859_1"));
317
                } catch (UnsupportedEncodingException e) {
318
                        status.setFilterQuery(fe.toString());
319
                }
320
                status.setFilterVisualText(getVisualFilterQuery());
321
            return status;
322
    }
323

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

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

    
407
        /**
408
         * Return the fields name
409
         * @return
410
         */
411
        public String[] getFieldNames(){
412
                Vector vFields = new Vector();
413
                Hashtable hashFields = new Hashtable();
414
                for (int i=0 ; i<getFields().length ; i++){
415
                        //if is not the root element
416
                        if (getFields()[i].getParentElement() != null){
417
                                //If the parent node has been not added
418
                                if (hashFields.get(getFields()[i].getParentElement()) == null){
419
                                        hashFields.put(getFields()[i],"");
420
                                        vFields.add(getFields()[i].getFullName());
421
                                }                        
422
                        }
423
                }
424
                String[] fields = new String[vFields.size()];
425
                for (int i=0 ; i<vFields.size() ; i++){
426
                        fields[i] = (String)vFields.get(i);
427
                }
428
                return fields;
429
        }
430

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

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

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

    
476

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

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

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

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

    
518
        public HashMap getProperties() {
519
                HashMap info = new HashMap();
520
                info.put("name", getName());
521
                info.put("layerName", getLayerName());
522
                info.put("layerText", getLayerText());
523
                info.put("attributes", getFields());
524
                info.put("host", getHost());        
525
                info.put("wfsLayerNode", getWfsLayerNode());        
526
                WFSStatus status = new WFSStatus(getLayerName(),getNameSapce());
527
                status.setBuffer(getNumfeatures());
528
                status.setTimeout(getTimeout());
529
                status.setUserName(getUserName());
530
                status.setPassword(getPassword());
531
                status.setFilterQuery(getFieldsQuery());
532
                status.setFilterVisualText(getVisualFilterQuery());
533
                info.put("status",status);                        
534
                return info;
535

    
536
        }
537

    
538
        /**
539
         * @return Returns the wfsLayerNode.
540
         */
541
        public WFSLayerNode getWfsLayerNode() {
542
                return wfsLayerNode;
543
        }
544

    
545
        /**
546
         * @param wfsLayerNode The wfsLayerNode to set.
547
         */
548
        public void setWfsLayerNode(WFSLayerNode wfsLayerNode) {
549
                this.wfsLayerNode = wfsLayerNode;
550
        }
551

    
552
        public void setHost(String host2) {
553
                try {
554
                        setHost(new URL(host2));
555
                } catch (MalformedURLException e) {
556
                        // TODO Auto-generated catch block
557
                        e.printStackTrace();
558
                }                
559
        }
560
        
561
        public ImageIcon getTocImageIcon() {                        
562
                return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wfs2").getClassLoader().getResource("images/icoLayer.png"));
563
        }
564
        
565
        /*
566
         *  (non-Javadoc)
567
         * @see com.iver.cit.gvsig.fmap.layers.FLyrVect#isPropertiesMenuVisible()
568
         */
569
        public boolean isPropertiesMenuVisible(){
570
                return false;
571
        }
572

    
573
        public String getSrs() {
574
                return srs;
575
        }
576

    
577
        public void setSrs(String srs) {
578
                this.srs = srs;
579
        }
580
        
581
        /**
582
         * @return XMLEntity.
583
         * @throws XMLException
584
         */
585
        public XMLEntity getXMLEntity() throws XMLException {        
586
                XMLEntity xml = super.getXMLEntity();                
587
                
588
                // Full extent
589
                try {
590
                        xml.putProperty("fullExtent", StringUtilities.rect2String(getFullExtent()));
591
                } catch (DriverException e) {
592
                        // TODO Auto-generated catch block
593
                        e.printStackTrace();
594
                }
595

    
596
                // Host
597
                xml.putProperty("host", host.toExternalForm());
598
                
599
                // Layer name
600
                xml.putProperty("layerName", getLayerName());                
601
                xml.putProperty("name", getName());
602

    
603
                //Layer fields
604
                XMLElement[] fields = getFields();
605
                String strFields = "";
606
                for (int i=0 ; i<fields.length ; i++){
607
                        //If is not the root node
608
                        if (fields[i].getParentElement() != null){
609
                                strFields = strFields + fields[i].getFullName();
610
                                if (i < fields.length - 1){
611
                                        strFields = strFields + "~##SEP1##~";
612
                                }
613
                        }else{
614
                                xml.putProperty("rootNode", true);
615
                        }
616
                }
617
                xml.putProperty("fields", strFields);
618
                
619
                // User name
620
                xml.putProperty("user", getUserName());
621
        
622
                // SRS
623
                xml.putProperty("srs", getSrs());                
624

    
625
        // OnlineResources
626
        xml.putProperty("onlineResource", getOnlineResource());
627
      
628
            // TimeOut
629
                xml.putProperty("timeout", getTimeout());                
630

    
631
        // Buffer
632
        xml.putProperty("buffer", getNumfeatures());
633
        
634
        //Projection
635
        xml.putProperty("projection",getProjection().getAbrev());
636
        
637
        //Filter
638
        xml.putProperty("filterEncoding",getFieldsQuery());
639
        
640
        return xml;
641
        }
642
        
643
        /**
644
         * @param xml XMLEntity
645
         *
646
         * @throws XMLException
647
         * @throws DriverException
648
         * @throws DriverI OException
649
         */
650
        public void setXMLEntity(XMLEntity xml)throws XMLException {
651
                                                
652
                // Host
653
                try {
654
                        host = new URL(xml.getStringProperty("host"));
655
                } catch (MalformedURLException e) {
656
                        throw new XMLException(e);
657
                }
658
                
659
                // Layer name
660
                setLayerName(xml.getStringProperty("layerName"));                        
661
                setName(xml.getStringProperty("name"));                
662
                
663
                // User name
664
                if (xml.contains("user")){
665
                        setUserName(xml.getStringProperty("user"));
666
                }
667
                
668
                // SRS
669
                if (xml.contains("srs")){
670
                        setSrs(xml.getStringProperty("srs"));
671
                }
672
                
673
                // OnlineResources
674
                if (xml.contains("onlineResource")){
675
                        setOnlineResource(xml.getStringProperty("onlineResource"));
676
                }
677
                
678
                // TimeOut
679
                if (xml.contains("timeout")){
680
                        setTimeout(xml.getIntProperty("timeout"));
681
                }
682
                
683
                // Buffer
684
                if (xml.contains("buffer")){
685
                        setNumfeatures(xml.getIntProperty("buffer"));
686
                }
687
                
688
                 //Projection
689
                if (xml.contains("projection")){
690
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("projection")));
691
                }       
692
                
693
                 //Filter
694
                if (xml.contains("filterEncoding")){
695
                        setFieldsQuery(xml.getStringProperty("filterEncoding"));
696
                }   
697
                
698
                // Layer fields
699
                FMapWFSDriver driver;
700
                try {
701
                        driver = FMapWFSDriverFactory.getFMapDriverForURL(host);
702
                        setWfsDriver(driver);        
703
                        WFSAdapter adapter = new WFSAdapter();
704
                    adapter.setDriver((VectorialDriver) wfsDriver);
705
                    setSource(adapter);
706
                    super.setXMLEntity(xml);
707
                    setLegend(LegendFactory.createFromXML(xml.getChild(0)));
708
                } catch (Exception e) {
709
                        throw new XMLException(e);        
710
                }
711
                driver.getLayerList();
712
                WFSLayerNode layer = driver.getLayerInfo(getLayerName(),getNameSapce());                        
713
                XMLElement[] atts = null;                
714
                
715
//                The root element always exists
716
                XMLElement rootElement = (XMLElement)layer.getFields().get(0);
717
                
718
                if (xml.contains("fields")) {
719
                        String[] fields = xml.getStringProperty("fields").split("~##SEP1##~");        
720
                        if ((fields.length == 1) && (fields[0].equals(""))){
721
                                fields = new String[0];
722
                        }
723
                        //The root element always is a complex type
724
                        Vector allFields = ((XMLComplexType)rootElement.getEntityType()).getAttributes();
725
                        //If the root node has been selected
726
                        if (xml.contains("rootNode")){
727
                                if (xml.getBooleanProperty("rootNode")==true){
728
                                        atts = new XMLElement[fields.length + 1];
729
                                        atts[fields.length] = rootElement;
730
                                }else{
731
                                        atts = new XMLElement[fields.length];
732
                                }
733
                        }else{
734
                                atts = new XMLElement[fields.length];
735
                        }
736
                        //Adding the other fields
737
                        for (int i=0 ; i<fields.length ; i++){
738
                                for (int j=0 ; j<allFields.size() ; j++){
739
                                        XMLElement field = (XMLElement)allFields.get(j);
740
                                        if (field != null){
741
                                                XMLElement found = field.searchAttribute(fields[i]);
742
                                                if (found != null){
743
                                                        atts[i] = found;
744
                                                        break;
745
                                                }
746
                                        }
747
                                }                                        
748
                        }                        
749
                }else{
750
                        if (xml.contains("rootNode")){
751
                                if (xml.getBooleanProperty("rootNode")==true){
752
                                        atts = new XMLElement[1];
753
                                        atts[0] = rootElement;
754
                                }
755
                        }
756
                }
757
                layer.setSelectedFields(atts);
758
                setWfsLayerNode(layer);
759
                setFields(atts);        
760
                setAvailable(true);
761
        }
762

    
763
        /**
764
         * @return Returns the fieldsQuery.
765
         */
766
        public String getFieldsQuery() {
767
                return FieldsQuery;
768
        }
769

    
770
        /**
771
         * @param fieldsQuery The fieldsQuery to set.
772
         */
773
        public void setFieldsQuery(String fieldsQuery) {
774
                FieldsQuery = fieldsQuery;
775
        }
776
        
777
        /**
778
         * Sets all fields and values known about this layer
779
         * 
780
         * @param _allFieldsAndValuesKnown A Map
781
         */
782
        public void setAllFieldsAndValuesKnown(Map _allFieldsAndValuesKnown) {
783
                if (this.allFieldsAndValuesKnown == null)
784
                        allFieldsAndValuesKnown = new HashMap();
785
                
786
                allFieldsAndValuesKnown = _allFieldsAndValuesKnown;
787
        }
788
        
789
        /**
790
         * Gets all fields and values known about this layer
791
         * 
792
         * @return A Map
793
         */
794
        public Map getAllFieldsAndValuesKnown() {
795
                return allFieldsAndValuesKnown;
796
        }
797

    
798
        /**
799
         * @return Returns the extent.
800
         */
801
        public Rectangle2D getExtent() {
802
                return extent;
803
        }
804

    
805
        /**
806
         * @param extent The extent to set.
807
         */
808
        public void setExtent(Rectangle2D extent) {
809
                this.extent = extent;
810
        }
811

    
812
        /**
813
         * @return Returns the nameSapce.
814
         */
815
        public String getNameSapce() {
816
                return nameSapce;
817
        }
818

    
819
        /**
820
         * @param nameSapce The nameSapce to set.
821
         */
822
        public void setNameSapce(String nameSapce) {
823
                this.nameSapce = nameSapce;
824
        }
825

    
826
        /**
827
         * @return Returns the bbox.
828
         */
829
        public Rectangle2D getBbox() {
830
                return bbox;
831
        }
832

    
833
        /**
834
         * @param bbox The bounding box to set.
835
         */
836
        public void setBbox(Rectangle2D bbox) {
837
                this.bbox = bbox;
838
        }
839

    
840
        public String getBboxPropertyName() {
841
                return bboxPropertyName;
842
        }
843

    
844
        public void setBboxPropertyName(String bboxPropertyName) {
845
                this.bboxPropertyName = bboxPropertyName;
846
        }
847
}