Statistics
| Revision:

root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 29538

History | View | Annotate | Download (23.6 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.hardcode.gdbms.engine.data.driver.DriverException;
21
import com.hardcode.gdbms.engine.instruction.Adapter;
22
import com.iver.andami.PluginServices;
23
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
24
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
25
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
26
import com.iver.cit.gvsig.fmap.drivers.WFSDriverException;
27
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
28
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory;
29
import com.iver.cit.gvsig.fmap.drivers.wfs.filters.SQLExpressionFormat;
30
import com.iver.cit.gvsig.fmap.edition.wfs.WFSTLockFeaturesException;
31
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
32
import com.iver.utiles.StringUtilities;
33
import com.iver.utiles.XMLEntity;
34
import com.iver.utiles.extensionPoints.ExtensionPoint;
35
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
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 18381 2008-01-30 12:00:25Z jpiera $
80
 * $Log$
81
 * Revision 1.10.2.14  2007-06-29 10:55:12  jorpiell
82
 * Encoding problem fixed
83
 *
84
 * Revision 1.10.2.12  2007/01/25 16:11:15  jorpiell
85
 * Se han cambiado los imports que hac?an referencia a remoteServices. Esto es as?, porque se han renombrado las clases del driver de GML
86
 *
87
 * Revision 1.10.2.11  2007/01/08 09:51:39  ppiqueras
88
 * Corregidos bugs + nueva funcionalidad, como que almacene informaci?n de los campos y valores que posee.
89
 *
90
 * Revision 1.27  2006/12/26 10:25:37  ppiqueras
91
 * Corregidas las dependencias con las nuevas ubicaciones de clases: IXMLType, XMLElement, IXMLComplexType, etc. (en libRemoteServices)
92
 *
93
 * Revision 1.26  2006/12/26 09:28:01  ppiqueras
94
 * 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).
95
 *
96
 * Revision 1.24  2006/12/15 13:55:17  ppiqueras
97
 * Almacena todos los campos y valores conocidos de la capa.
98
 *
99
 * Revision 1.23  2006/12/11 11:02:24  ppiqueras
100
 * Corregido bug -> que se mantenga la frase de filtrado
101
 *
102
 * Revision 1.22  2006/11/28 08:04:51  jorpiell
103
 * Se guarda la query para que pueda ser recuperada desde la ventana de propiedades
104
 *
105
 * Revision 1.21  2006/11/16 17:17:48  jorpiell
106
 * Se guarda el filtro en el gvp
107
 *
108
 * Revision 1.20  2006/11/16 13:29:47  jorpiell
109
 * Se ha reescrito losl m?todo para  guardar y recuperar gvps
110
 *
111
 * Revision 1.19  2006/11/15 17:38:08  jorpiell
112
 * Ya se puede guardar una capa en WFS.
113
 *
114
 * Revision 1.18  2006/10/31 12:24:04  jorpiell
115
 * Comprobado el caso en el que los atributos no tienen tipo
116
 *
117
 * Revision 1.17  2006/10/31 09:55:28  jorpiell
118
 * Se ha modificado el constructor del WFS desde cat?logo
119
 *
120
 * Revision 1.16  2006/10/31 09:38:15  jorpiell
121
 * 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
122
 *
123
 * Revision 1.15  2006/10/23 07:37:04  jorpiell
124
 * Ya funciona el filterEncoding
125
 *
126
 * Revision 1.14  2006/10/10 12:55:06  jorpiell
127
 * Se ha a?adido el soporte de features complejas
128
 *
129
 * Revision 1.13  2006/10/02 12:54:35  jorpiell
130
 * No se pod?a crear un mapa que tubiera la opci?n enlace vivo habilitada
131
 *
132
 * Revision 1.12  2006/10/02 09:09:45  jorpiell
133
 * Cambios del 10 copiados al head
134
 *
135
 * Revision 1.10.2.3  2006/09/29 14:12:53  luisw2
136
 * CRSFactory.getCRS substitutes ProjectionPool.get
137
 *
138
 * Revision 1.10.2.2  2006/09/28 08:54:01  jorpiell
139
 * Ya se puede reproyectar
140
 *
141
 * Revision 1.10.2.1  2006/09/26 07:36:24  jorpiell
142
 * El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
143
 *
144
 * Revision 1.10  2006/09/05 15:41:52  jorpiell
145
 * A?adida la funcionalidad de cargar WFS desde el cat?logo
146
 *
147
 * Revision 1.9  2006/07/05 12:05:41  jorpiell
148
 * Se ha modificado para que avise si se han recuperado las mismas features que marca el campo buffer
149
 *
150
 * Revision 1.8  2006/06/21 12:52:10  jorpiell
151
 * A?adido un icono para la capa WFS
152
 *
153
 * Revision 1.7  2006/06/21 12:35:45  jorpiell
154
 * 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
155
 *
156
 * Revision 1.6  2006/06/15 11:17:06  jorpiell
157
 * 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
158
 *
159
 * Revision 1.5  2006/06/14 07:57:19  jorpiell
160
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
161
 *
162
 * Revision 1.4  2006/06/05 16:49:31  caballero
163
 * poder editar y exportar
164
 *
165
 * Revision 1.3  2006/05/25 10:31:55  jorpiell
166
 * Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
167
 *
168
 * Revision 1.2  2006/05/23 13:21:59  jorpiell
169
 * Si hay alg?n problema en la carga se muestra un mensaje de error
170
 *
171
 * Revision 1.1  2006/05/19 12:54:11  jorpiell
172
 * Creada la capa WFS
173
 *
174
 *
175
 */
176
/**
177
 *  FMap's WFS Layer class.
178
 *
179
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
180
 */
181
public class FLyrWFS extends FLyrVect{
182
        /**
183
         * @param visualFilterQuery the visualFilterQuery to set
184
         */
185
        public void setVisualFilterQuery(String visualFilterQuery) {
186
                this.visualFilterQuery = visualFilterQuery;
187
        }
188

    
189
        /**
190
         * @return the bbox
191
         */
192
        public Rectangle2D getBbox() {
193
                return bbox;
194
        }
195

    
196
        /**
197
         * @param bbox the bbox to set
198
         */
199
        public void setBbox(Rectangle2D bbox) {
200
                this.bbox = bbox;
201
        }
202

    
203
        /**
204
         * @return the bboxPropertyName
205
         */
206
        public String getBboxPropertyName() {
207
                return bboxPropertyName;
208
        }
209

    
210
        /**
211
         * @param bboxPropertyName the bboxPropertyName to set
212
         */
213
        public void setBboxPropertyName(String bboxPropertyName) {
214
                this.bboxPropertyName = bboxPropertyName;
215
        }
216

    
217
        private URL host = null;
218
        private String onlineResource = null;
219
        private String name = null;
220
        private String layerName = null;
221
        private String nameSpace = null;
222
        private String userName = null;
223
        private String password = null;
224
        private String FieldsQuery = null;
225
        private Rectangle2D bbox = null;
226
        private String bboxPropertyName = null;
227
        private String visualFilterQuery = null;
228
        private XMLElement[] fields = null;
229
        private int numfeatures = 100;
230
        private int timeout = 10000;
231
        private int wfstExpiryTime = 0;
232
        private String srs = null;
233
        private FMapWFSDriver wfsDriver = null;
234
        private WFSLayerNode wfsLayerNode = null;
235
        private Map allFieldsAndValuesKnown = null;
236
        private WFSStatus status = null;
237

    
238
        /**
239
         * Constructor
240
         */
241
        public FLyrWFS(){
242
                super();
243
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("WFSExtension");
244
                if (extensionPoint != null){
245
                        try {
246
                                WFSLayerListener listener = (WFSLayerListener)extensionPoint.create("WFSLayerListener");
247
                                listener.setWfsLayer(this);
248
                                addLayerListener(listener);
249
                        } catch (Exception e) {
250
                                //Impossible to Use the WFST lockoperation
251
                        }
252
                }
253
        }
254

    
255
        /**
256
         * Constructor to load a new layer from a catalog
257
         * search
258
         * @param args
259
         * Params to load a new layer
260
         * @throws WFSDriverException 
261
         * @throws IOException 
262
         * @throws MalformedURLException 
263
         * @throws ConnectException 
264
         * @throws DriverIOException 
265
         */
266
        public FLyrWFS(Map args) throws WFSDriverException, ConnectException, MalformedURLException, IOException, DriverIOException{
267
                this();
268
                String[] sLayer = (String[])args.get("layer");
269
                String user = (String)args.get("user");
270
                String pwd = (String)args.get("pwd");
271
                String host = (String)args.get("host");        
272
                String projection = (String)args.get("projection");
273

    
274
                FMapWFSDriver driver = FMapWFSDriverFactory.getFMapDriverForURL(new URL(host));
275
                WFSLayerNode[] layers = driver.getLayerList();
276
                WFSLayerNode layer = driver.getLayerInfo(sLayer[0]);
277

    
278
                layer.setSelectedFields(layer.getFields());
279

    
280
                Vector vAtts = new Vector();
281
                if (layer.getFields().size() == 1){
282
                        XMLElement element = (XMLElement)layer.getFields().get(0);
283
                        if (element.getEntityType().getType() != IXMLType.COMPLEX){
284
                                vAtts.add(element);
285
                        }else{
286
                                vAtts = ((XMLComplexType)element.getEntityType()).getAttributes();
287
                        }
288
                }
289
                for (int i=0 ; i<layer.getFields().size() ; i++){
290
                        XMLElement element = (XMLElement)layer.getFields().get(i);
291
                        if (element.getEntityType().getType() != IXMLType.COMPLEX){
292
                                vAtts.add((XMLElement)layer.getFields().get(i));
293
                        }else{
294

    
295
                        }
296
                }
297

    
298
                XMLElement[] atts = new XMLElement[vAtts.size()];
299
                for (int i=0 ; i<vAtts.size() ; i++){
300
                        atts[i] = (XMLElement)vAtts.get(i);
301
                }
302

    
303
                setHost(host);
304
                setName(sLayer[0]);
305
                setLayerName(sLayer[0]);
306
                setWfsLayerNode(layer);
307
                setFields(atts);
308
                setUserName(user);
309
                setPassword(pwd);
310
                setNumfeatures(10000);
311
                setTimeout(10000);
312
                setWfsDriver(driver);                        
313
                setProjection(CRSFactory.getCRS(projection));
314

    
315
                load();            
316
        }
317

    
318

    
319
        /**
320
         * Loads the features from the server
321
         */
322
        public void load(){
323
                WFSAdapter adapter = new WFSAdapter();
324
                try {
325
                        wfsDriver.getFeature(getWFSStatus());
326

    
327
                        adapter.setDriver((VectorialDriver) wfsDriver);
328
                        setSource(adapter);
329

    
330
                        if (getLegend() == null){
331
                                setLegend(LegendFactory.createSingleSymbolLegend(
332
                                                getShapeType()));
333
                        }
334
                } catch (Exception e){
335
                        e.printStackTrace();                        
336
                }
337
        }
338

    
339
        /**
340
         * Gets the WFS Status
341
         * @return
342
         */
343
        private WFSStatus getWFSStatus(){
344
                if (status == null){
345
                        status = wfsDriver.getStatus();
346
                }else{
347
                        status.setFeatureName(getLayerName());
348
                }
349
                status.setUserName(getUserName());
350
                status.setPassword(getPassword());
351
                status.setBuffer(getNumfeatures());
352
                status.setTimeout(getTimeout());
353
                status.setFields(getFieldNames());
354
                status.setOnlineResource(getOnlineResource());
355
                status.setSrs(getSrs());
356
                status.setBBox(getBbox());
357
                //Filter Encoding transformation
358
                FilterEncoding fe = SQLExpressionFormat.createFilter();                                
359
                fe.setQuery(getFieldsQuery());
360
                status.setFilterQuery(fe.toString());
361
                status.setFilterVisualText(getVisualFilterQuery());
362
                return status;
363
        }
364

    
365
        /**
366
         * @return Returns the layerName.
367
         */
368
        public String getLayerName() {
369
                return layerName;
370
        }
371
        /**
372
         * @param layerName The layerName to set.
373
         */
374
        public void setLayerName(String layerName) {
375
                this.layerName = layerName;
376
        }
377
        /**
378
         * @return Returns the numfeatures.
379
         */
380
        public int getNumfeatures() {
381
                return numfeatures;
382
        }
383
        /**
384
         * @param numfeatures The numfeatures to set.
385
         */
386
        public void setNumfeatures(int numfeatures) {
387
                this.numfeatures = numfeatures;
388
        }
389

    
390
        /**
391
         * @return Returns the pwd.
392
         */
393
        public String getPassword() {
394
                return password;
395
        }
396
        /**
397
         * @param pwd The pwd to set.
398
         */
399
        public void setPassword(String password) {
400
                this.password = password;
401
        }
402
        /**
403
         * @return Returns the timeout.
404
         */
405
        public int getTimeout() {
406
                return timeout;
407
        }
408
        /**
409
         * @param timeout The timeout to set.
410
         */
411
        public void setTimeout(int timeout) {
412
                this.timeout = timeout;
413
        }
414
        /**
415
         * @return Returns the user.
416
         */
417
        public String getUserName() {
418
                return userName;
419
        }
420
        /**
421
         * @param user The user to set.
422
         */
423
        public void setUserName(String userName) {
424
                this.userName = userName;
425
        }
426
        /**
427
         * @return The visual filtering text from "Where"
428
         */
429
        public String getVisualFilterQuery() {
430
                return visualFilterQuery;
431
        }
432
        /**
433
         * @param visualFilterQuery The visual filtering text from "Where"
434
         */
435
        public void setVisualFilterQueyr(String visualFilterQuery) {
436
                this.visualFilterQuery = visualFilterQuery;
437
        }
438
        /**
439
         * @return Returns the fields.
440
         */
441
        public XMLElement[] getFields() {
442
                if (fields == null){
443
                        return new XMLElement[0];
444
                }
445
                return fields;
446
        }
447

    
448
        /**
449
         * Return the fields name
450
         * @return
451
         */
452
        public String[] getFieldNames(){
453
                Vector vFields = new Vector();
454
                for (int i=0 ; i<getFields().length ; i++){
455
                        if ((getFields()[i].getEntityType() == null) || 
456
                                        (getFields()[i].getEntityType().getType() != IXMLType.COMPLEX)){
457
                                vFields.add(getFields()[i].getName());
458
                        }
459
                }
460
                String[] fields = new String[vFields.size()];
461
                for (int i=0 ; i<vFields.size() ; i++){
462
                        fields[i] = (String)vFields.get(i);
463
                }
464
                return fields;
465
        }
466

    
467
        /**
468
         * @param fields The fields to set.
469
         */
470
        public void setFields(XMLElement[] fields) {
471
                this.fields = fields;
472
        }
473
        /**
474
         * @return Returns the name.
475
         */
476
        public String getName() {
477
                return name;
478
        }
479
        /**
480
         * @param name The name to set.
481
         */
482
        public void setName(String name) {
483
                this.name = name;
484
        }
485
        /**
486
         * @return Returns the host.
487
         */
488
        public URL getHost() {
489
                return host;
490
        }
491
        /**
492
         * @param host The host to set.
493
         */
494
        public void setHost(URL host) {
495
                this.host = host;
496
        }
497

    
498
        /**
499
         * @return Returns the wfs.
500
         */
501
        public FMapWFSDriver getWfsDriver() {
502
                return wfsDriver;
503
        }
504

    
505
        /**
506
         * @param wfs The wfs to set.
507
         */
508
        public void setWfsDriver(FMapWFSDriver wfs) {
509
                this.wfsDriver = wfs;
510
        }
511

    
512

    
513
        /*
514
         *  (non-Javadoc)
515
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getStrategy()
516
         */
517
        //        public Strategy getStrategy() {
518
        //        if (wfsStrategy == null){
519
        //        wfsStrategy = new WFSStrategy(this);
520
        //        }
521
        //        return wfsStrategy;
522
        //        }
523

    
524
        /*
525
         *  (non-Javadoc)
526
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
527
         */
528
        public Rectangle2D getFullExtent() {
529
                Rectangle2D extent = wfsDriver.getFullExtent();
530
                if (extent == null){
531
                        return null;
532
                }
533
                if (getCoordTrans() != null){
534
                        return getCoordTrans().convert(extent);
535
                }
536
                return extent;
537
        }
538

    
539
        /**
540
         * @return Returns the onlineResource.
541
         */
542
        public String getOnlineResource() {
543
                return onlineResource;
544
        }
545

    
546
        /**
547
         * @param onlineResource The onlineResource to set.
548
         */
549
        public void setOnlineResource(String onlineResource) {
550
                this.onlineResource = onlineResource;
551
        }
552

    
553
        public HashMap getProperties() {
554
                HashMap info = new HashMap();
555
                info.put("name", getName());
556
                info.put("layerName", getLayerName());
557
                // layer text is no longer available
558
                //info.put("layerText", getLayerText());
559
                info.put("attributes", getFields());
560
                info.put("host", getHost());
561
                info.put("wfsLayerNode", getWfsLayerNode());
562
                WFSStatus status = new WFSStatus(getLayerName(),getNameSpace());
563
                status.setBuffer(getNumfeatures());
564
                status.setTimeout(getTimeout());
565
                status.setUserName(getUserName());
566
                status.setPassword(getPassword());
567
                status.setFilterQuery(getFieldsQuery());
568
                status.setFilterVisualText(getVisualFilterQuery());
569
                info.put("status",status);
570
                return info;
571
        }
572

    
573
        /**
574
         * @return Returns the wfsLayerNode.
575
         */
576
        public WFSLayerNode getWfsLayerNode() {
577
                return wfsLayerNode;
578
        }
579

    
580
        /**
581
         * @param wfsLayerNode The wfsLayerNode to set.
582
         */
583
        public void setWfsLayerNode(WFSLayerNode wfsLayerNode) {
584
                this.wfsLayerNode = wfsLayerNode;
585
        }
586

    
587
        public void setHost(String host2) {
588
                try {
589
                        setHost(new URL(host2));
590
                } catch (MalformedURLException e) {
591
                        // TODO Auto-generated catch block
592
                        e.printStackTrace();
593
                }                
594
        }
595

    
596
        public ImageIcon getTocImageIcon() {                        
597
                return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wfs2").getClassLoader().getResource("images/icoLayer.png"));
598
        }
599

    
600
        /*
601
         *  (non-Javadoc)
602
         * @see com.iver.cit.gvsig.fmap.layers.FLyrVect#isPropertiesMenuVisible()
603
         */
604
        public boolean isPropertiesMenuVisible(){
605
                return false;
606
        }
607

    
608
        public String getSrs() {
609
                return srs;
610
        }
611

    
612
        public void setSrs(String srs) {
613
                this.srs = srs;
614
        }
615

    
616
        /**
617
         * @return XMLEntity.
618
         * @throws XMLException
619
         */
620
        public XMLEntity getXMLEntity() throws XMLException {        
621
                XMLEntity xml = super.getXMLEntity();                
622

    
623
                xml.putProperty("fullExtent", StringUtilities.rect2String(getFullExtent()));
624

    
625
                // Host
626
                xml.putProperty("host", host.toExternalForm());
627

    
628
                // Layer name
629
                xml.putProperty("layerName", getLayerName());                
630
                xml.putProperty("name", getName());
631

    
632
                //Layer fields
633
                XMLElement[] fields = getFields();
634
                String strFields = "";
635
                for (int i=0 ; i<fields.length ; i++){
636
                        //If is not the root node
637
                        if (fields[i].getParentElement() != null){
638
                                strFields = strFields + fields[i].getFullName();
639
                                if (i < fields.length - 1){
640
                                        strFields = strFields + "~##SEP1##~";
641
                                }
642
                        }else{
643
                                xml.putProperty("rootNode", true);
644
                        }
645
                }
646
                xml.putProperty("fields", strFields);
647

    
648
                // User name
649
                xml.putProperty("user", getUserName());
650

    
651
                // SRS
652
                xml.putProperty("srs", getSrs());                
653

    
654
                // OnlineResources
655
                xml.putProperty("onlineResource", getOnlineResource());
656

    
657
                // TimeOut
658
                xml.putProperty("timeout", getTimeout());                
659

    
660
                // Buffer
661
                xml.putProperty("buffer", getNumfeatures());
662

    
663
                //Projection
664
                xml.putProperty("projection",getProjection().getAbrev());
665

    
666
                //Filter
667
                xml.putProperty("filterEncoding",getFieldsQuery());
668

    
669
                return xml;
670
        }
671

    
672
        /**
673
         * @param xml XMLEntity
674
         *
675
         * @throws XMLException
676
         * @throws DriverException
677
         * @throws DriverI OException
678
         */
679
        public void setXMLEntity(XMLEntity xml)throws XMLException {
680

    
681
                // Host
682
                try {
683
                        host = new URL(xml.getStringProperty("host"));
684
                } catch (MalformedURLException e) {
685
                        throw new XMLException(e);
686
                }
687

    
688
                // Layer name
689
                setLayerName(xml.getStringProperty("layerName"));                        
690
                setName(xml.getStringProperty("name"));                
691

    
692
                // User name
693
                if (xml.contains("user")){
694
                        setUserName(xml.getStringProperty("user"));
695
                }
696

    
697
                // SRS
698
                if (xml.contains("srs")){
699
                        setSrs(xml.getStringProperty("srs"));
700
                }
701

    
702
                // OnlineResources
703
                if (xml.contains("onlineResource")){
704
                        setOnlineResource(xml.getStringProperty("onlineResource"));
705
                }
706

    
707
                // TimeOut
708
                if (xml.contains("timeout")){
709
                        setTimeout(xml.getIntProperty("timeout"));
710
                }
711

    
712
                // Buffer
713
                if (xml.contains("buffer")){
714
                        setNumfeatures(xml.getIntProperty("buffer"));
715
                }
716

    
717
                //Projection
718
                if (xml.contains("projection")){
719
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("projection")));
720
                }       
721

    
722
                //Filter
723
                if (xml.contains("filterEncoding")){
724
                        setFieldsQuery(xml.getStringProperty("filterEncoding"));
725
                }   
726

    
727
                // Layer fields
728
                FMapWFSDriver driver;
729
                try {
730
                        driver = FMapWFSDriverFactory.getFMapDriverForURL(host);
731
                        setWfsDriver(driver);        
732
                        WFSAdapter adapter = new WFSAdapter();
733
                        adapter.setDriver((VectorialDriver) wfsDriver);
734
                        setSource(adapter);                        
735
                } catch (Exception e) {
736
                        throw new XMLException(e);        
737
                }
738
                driver.getLayerList();
739
                WFSLayerNode layer = driver.getLayerInfo(getLayerName());                        
740
                XMLElement[] atts = null;                
741

    
742
                //                The root element always exists
743
                XMLElement rootElement = (XMLElement)layer.getFields().get(0);
744

    
745
                if (xml.contains("fields")) {
746
                        String[] fields = xml.getStringProperty("fields").split("~##SEP1##~");        
747
                        if ((fields.length == 1) && (fields[0].equals(""))){
748
                                fields = new String[0];
749
                        }
750
                        //The root element always is a complex type
751
                        Vector allFields = ((XMLComplexType)rootElement.getEntityType()).getAttributes();
752
                        //If the root node has been selected
753
                        if (xml.contains("rootNode")){
754
                                if (xml.getBooleanProperty("rootNode")==true){
755
                                        atts = new XMLElement[fields.length + 1];
756
                                        atts[fields.length] = rootElement;
757
                                }else{
758
                                        atts = new XMLElement[fields.length];
759
                                }
760
                        }else{
761
                                atts = new XMLElement[fields.length];
762
                        }
763
                        //Adding the other fields
764
                        for (int i=0 ; i<fields.length ; i++){
765
                                for (int j=0 ; j<allFields.size() ; j++){
766
                                        XMLElement field = (XMLElement)allFields.get(j);
767
                                        if (field != null){
768
                                                XMLElement found = field.searchAttribute(fields[i]);
769
                                                if (found != null){
770
                                                        atts[i] = found;
771
                                                        break;
772
                                                }
773
                                        }
774
                                }                                        
775
                        }                        
776
                }else{
777
                        if (xml.contains("rootNode")){
778
                                if (xml.getBooleanProperty("rootNode")==true){
779
                                        atts = new XMLElement[1];
780
                                        atts[0] = rootElement;
781
                                }
782
                        }
783
                }
784
                layer.setSelectedFields(atts);
785
                setWfsLayerNode(layer);
786
                setFields(atts);        
787
                setAvailable(true);
788

    
789
                try{
790
                        //Set the legend
791
                        driver.getFeature(getWFSStatus());
792
                        super.setXMLEntity(xml);
793
                        setLegend(LegendFactory.createFromXML(xml.getChild(0)));
794
                } catch (Exception e) {
795
                        throw new XMLException(e);        
796
                }
797
        }
798

    
799
        /**
800
         * @return Returns the fieldsQuery.
801
         */
802
        public String getFieldsQuery() {
803
                return FieldsQuery;
804
        }
805

    
806
        /**
807
         * @param fieldsQuery The fieldsQuery to set.
808
         */
809
        public void setFieldsQuery(String fieldsQuery) {
810
                FieldsQuery = fieldsQuery;
811
        }
812

    
813
        /**
814
         * Sets all fields and values known about this layer
815
         * 
816
         * @param _allFieldsAndValuesKnown A Map
817
         */
818
        public void setAllFieldsAndValuesKnown(Map _allFieldsAndValuesKnown) {
819
                if (this.allFieldsAndValuesKnown == null)
820
                        allFieldsAndValuesKnown = new HashMap();
821

    
822
                allFieldsAndValuesKnown = _allFieldsAndValuesKnown;
823
        }
824

    
825
        /**
826
         * Gets all fields and values known about this layer
827
         * 
828
         * @return A Map
829
         */
830
        public Map getAllFieldsAndValuesKnown() {
831
                return allFieldsAndValuesKnown;
832
        }
833

    
834
        /**
835
         * @return the isWfstEditing
836
         */
837
        public boolean isWfstEditing() {
838
                return wfsDriver.isWfstEditing();
839
        }
840

    
841
        /**
842
         * @param isWfstEditing the isWfstEditing to set
843
         */
844
        public void setWfstEditing(boolean isWfstEditing) {
845
                wfsDriver.setWfstEditing(isWfstEditing);
846
        }
847

    
848
        /**
849
         * It locks all the features
850
         * @param expiryTime
851
         * The maximum time to edit
852
         * @throws WFSTLockFeaturesException 
853
         */
854
        public void lockCurrentFeatures(int expiryTime) throws WFSTLockFeaturesException{
855
                wfstExpiryTime = expiryTime;
856
                wfsDriver.lockCurrentFeatures(expiryTime);
857
        }
858

    
859
        /**
860
         * @return the wfstExpiryTime
861
         */
862
        public int getWfstExpiryTime() {
863
                return wfstExpiryTime;
864
        }
865

    
866
        /**
867
         * @return true if the layer can be edit using WFST
868
         */
869
        public boolean isTransactional(){
870
                return wfsDriver.isTransactional();
871
        }
872

    
873
        /**
874
         * @param wfstExpiryTime the wfstExpiryTime to set
875
         */
876
        public void setWfstExpiryTime(int wfstExpiryTime) {
877
                this.wfstExpiryTime = wfstExpiryTime;
878
        }        
879

    
880
        /**
881
         * @return the isWfstGeometriesUpdated
882
         */
883
        public boolean isWfstSrsBasedOnXML() {
884
                return getWFSStatus().isSRSBasedOnXML();
885
        }
886

    
887
        /**
888
         * @param isWfstGeometriesUpdated the isWfstGeometriesUpdated to set
889
         */
890
        public void setWfstSrsBasedOnXML(boolean isSrsBasedOnXML) {
891
                getWFSStatus().setSRSBasedOnXML(isSrsBasedOnXML);
892
        }
893

    
894
        /**
895
         * @return the isLockFeaturesEnabled
896
         */
897
        public boolean isWfstLockFeaturesEnabled() {
898
                return getWFSStatus().isLockFeaturesEnabled();
899
        }
900

    
901
        /**
902
         * @param isLockFeaturesEnabled the isLockFeaturesEnabled to set
903
         */
904
        public void setWfstLockFeaturesEnabled(boolean isLockFeaturesEnabled) {
905
                getWFSStatus().setLockFeaturesEnabled(isLockFeaturesEnabled);
906
        }        
907

    
908
        /**
909
         * @return the nameSpace
910
         */
911
        public String getNameSpace() {
912
                return nameSpace;
913
        }
914

    
915
        /**
916
         * @param nameSpace the nameSpace to set
917
         */
918
        public void setNameSpace(String nameSpace) {
919
                this.nameSpace = nameSpace;
920
        }
921
}