Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / Project.java @ 7543

History | View | Annotate | Download (39 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.project;
42

    
43
import java.awt.Color;
44
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeSupport;
47
import java.io.Serializable;
48
import java.text.DateFormat;
49
import java.util.ArrayList;
50
import java.util.Comparator;
51
import java.util.Date;
52
import java.util.Hashtable;
53
import java.util.Iterator;
54
import java.util.TreeMap;
55

    
56
import org.cresques.cts.IProjection;
57
import org.cresques.cts.ProjectionPool;
58

    
59
import com.hardcode.driverManager.DriverLoadException;
60
import com.hardcode.gdbms.engine.data.DataSource;
61
import com.hardcode.gdbms.engine.data.NoSuchTableException;
62
import com.hardcode.gdbms.engine.data.SourceInfo;
63
import com.hardcode.gdbms.engine.data.db.DBSourceInfo;
64
import com.hardcode.gdbms.engine.data.db.DBTableSourceInfo;
65
import com.hardcode.gdbms.engine.data.file.FileSourceInfo;
66
import com.hardcode.gdbms.engine.data.object.ObjectSourceInfo;
67
import com.iver.andami.PluginServices;
68
import com.iver.andami.ui.mdiManager.IWindow;
69
import com.iver.andami.ui.mdiManager.WindowInfo;
70
import com.iver.cit.gvsig.fmap.DriverException;
71
import com.iver.cit.gvsig.fmap.MapContext;
72
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
73
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
74
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
75
import com.iver.cit.gvsig.fmap.layers.FLayer;
76
import com.iver.cit.gvsig.fmap.layers.FLayers;
77
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
78
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
79
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
80
import com.iver.cit.gvsig.fmap.layers.XMLException;
81
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
82
import com.iver.cit.gvsig.fmap.operations.selection.LinkSelectionListener;
83
import com.iver.cit.gvsig.project.documents.ProjectDocument;
84
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory;
85
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
86
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
87
import com.iver.cit.gvsig.project.documents.gui.ProjectWindow;
88
import com.iver.cit.gvsig.project.documents.layout.ProjectMap;
89
import com.iver.cit.gvsig.project.documents.layout.ProjectMapFactory;
90
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
91
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
92
import com.iver.cit.gvsig.project.documents.view.ProjectView;
93
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory;
94
import com.iver.utiles.PostProcessSupport;
95
import com.iver.utiles.StringUtilities;
96
import com.iver.utiles.XMLEntity;
97

    
98

    
99
/**
100
 * Clase que representa un proyecto de openSIG
101
 *
102
 * @author Fernando Gonz?lez Cort?s
103
 */
104
public class Project implements Serializable, PropertyChangeListener {
105
        public static String VERSION = "1.0";
106
        static private IProjection defaultProjection = CRSFactory.getCRS(
107
                        "EPSG:23030");
108
        private PropertyChangeSupport change;
109
        boolean modified = false;
110
        private String name;
111
        //private String path;
112
        private String creationDate;
113
        private String modificationDate;
114
        private String owner;
115
        private String comments;
116
        private Color selectionColor = new Color(255, 255, 0);
117
        //private ArrayList views = new ArrayList();
118
        //private ArrayList tables = new ArrayList();
119
        //private ArrayList maps = new ArrayList();
120
        private ArrayList documents=new ArrayList();
121
        private ArrayList extents = new ArrayList();
122
        private int signatureAtStartup;
123
        // used to restore the position of the Project Manager window when loading a project from file
124
        private static WindowInfo seedProjectWindow = null;
125
        private IProjection projection;
126
         private TreeMap sortedDocuments = new TreeMap(new Comparator() {
127
         public int compare(Object o1, Object o2) {
128
             if ((o1 != null) && (o2 != null)) {
129
                     int priority1=((ProjectDocument)o1).getProjectDocumentFactory().getPriority();
130
                     int priority2=((ProjectDocument)o2).getProjectDocumentFactory().getPriority();
131
                 if (priority1>=priority2)
132
                         return 1;
133
                        return -1;
134
             }
135
             return 0;
136
         }
137
     }); // Para poder ordenar
138
        /**
139
         * Creates a new Project object.
140
         */
141
        public Project() {
142
                change = new PropertyChangeSupport(this);
143

    
144
                //        change.addPropertyChangeListener(this);
145
                creationDate = DateFormat.getDateInstance().format(new Date());
146
                modificationDate = creationDate;
147
//                signatureAtStartup = computeSignature();
148

    
149
                /*                LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
150
                   .getPluginDirectory()
151
                   .getAbsolutePath() +
152
                   File.separator + "drivers");
153
                 */
154
        }
155

    
156
        /**
157
         * Obtiene la fecha de creaci?n del proyecto
158
         *
159
         * @return
160
         */
161
        public String getCreationDate() {
162
                return creationDate;
163
        }
164

    
165
        /**
166
         * Obtiene el nombre del proyecto
167
         *
168
         * @return
169
         */
170
        public String getName() {
171
                return name;
172
        }
173

    
174
//        /**
175
//         * Obtiene la ruta completa del fichero donde se guardo por ?ltima vez el
176
//         * proyecto
177
//         *
178
//         * @return
179
//         */
180
//        public String getPath() {
181
//                return path;
182
//        }
183

    
184
        /**
185
         * Asigna la fecha de creaci?n del proyecto. Este m?todo tiene sentido s?lo
186
         * por que al recuperar la fecha del XML hay que asignarla al objeto
187
         * proyecto de alguna manera. La fecha se asigna en el constructor y no se
188
         * deber?a de modificar nunca
189
         *
190
         * @param string
191
         */
192
        public void setCreationDate(String string) {
193
                creationDate = string;
194
                modified = true;
195
                change.firePropertyChange("", null, null);
196
        }
197

    
198

    
199
        /**
200
         * Establece el nombre del proyecto
201
         *
202
         * @param string
203
         */
204
        public void setName(String string) {
205
                name = string;
206
                modified = true;
207
                change.firePropertyChange("", null, null);
208
        }
209

    
210
//        /**
211
//         * establece la ruta completa de donde se encuentra guardado el proyecto
212
//         *
213
//         * @param string
214
//         */
215
//        public void setPath(String string) {
216
//                path = string;
217
//                modified = true;
218
//                change.firePropertyChange("", null, null);
219
//        }
220

    
221
        /**
222
         * Devuelve a partir de la capa la tabla asociada.
223
         *
224
         * @param co Capa.
225
         *
226
         * @return ProjectTable de la tabla asociada.
227
         */
228
        public ProjectTable getTable(AlphanumericData co) {
229
                ArrayList tables=getDocumentsByType(ProjectTableFactory.registerName);
230
                /**
231
                 * Como las tablas se pueden a?adir cuando se pincha en "ver tabla" de
232
                 * una capa, se puede intentar a?adir dos veces la misma tabla
233
                 */
234
                for (int i = 0; i < tables.size(); i++) {
235
                        if (((ProjectTable) tables.get(i)).getAssociatedTable() == co) {
236
                                return (ProjectTable) tables.get(i);
237
                        }
238
                }
239

    
240
                return null;
241
        }
242

    
243
        /**
244
         * Devuelve a partir del nombre la tabla asociada.
245
         *
246
         * @param name Nombre.
247
         * @deprecated utilizar getProjectDocumentByName(...);
248
         * @return ProjectTable de la tabla asociada.
249
         */
250
        public ProjectTable getTable(String name) {
251
                ArrayList tables=getDocumentsByType(ProjectTableFactory.registerName);
252
                /**
253
                 * Como las tablas se pueden a?adir cuando se pincha en "ver tabla" de
254
                 * una capa, se puede intentar a?adir dos veces la misma tabla
255
                 */
256
                for (int i = 0; i < tables.size(); i++) {
257
                        if (((ProjectTable) tables.get(i)).getName().equals(name)) {
258
                                return (ProjectTable) tables.get(i);
259
                        }
260
                }
261

    
262
                return null;
263
        }
264

    
265
        /**
266
         * Devuelve true si el proyecto (o alguna tabla, vista o mapa que contiene)
267
         * fue modificado
268
         *
269
         * @return
270
         */
271
        public boolean isModified() {
272
                if (this.getDocumentsByType(ProjectMapFactory.registerName).size()==0 && this.getDocumentsByType(ProjectViewFactory.registerName).size()==0 && this.getDocumentsByType(ProjectTableFactory.registerName).size() == 0){
273
                        return false;
274
                }
275
                return true;
276
                ///return modified;    TODO El atributo modified solo detecta cuando se elimina o a?ade una vista,
277
                ///mapa o tabla pero no cuando se modifican.
278
        }
279

    
280
        /**
281
         * Obtiene los comentarios
282
         *
283
         * @return
284
         */
285
        public String getComments() {
286
                return comments;
287
        }
288

    
289
        /**
290
         * Obtiene la fecha de la ?ltima modificaci?n
291
         *
292
         * @return
293
         */
294
        public String getModificationDate() {
295
                return modificationDate;
296
        }
297

    
298
        /**
299
         * Obtiene el propietario del proyecto
300
         *
301
         * @return
302
         */
303
        public String getOwner() {
304
                return owner;
305
        }
306

    
307
        /**
308
         * Establece una cadena como comentarios al proyecto
309
         *
310
         * @param string
311
         */
312
        public void setComments(String string) {
313
                comments = string;
314
                modified = true;
315
                change.firePropertyChange("", null, null);
316
        }
317

    
318
        /**
319
         * Establece la fecha de la ?ltima modificaci?n
320
         *
321
         * @param string
322
         */
323
        public void setModificationDate(String string) {
324
                modificationDate = string;
325
                modified = true;
326
                change.firePropertyChange("", null, null);
327
        }
328

    
329
        /**
330
         * Establece el propietario del proyecto
331
         *
332
         * @param string
333
         */
334
        public void setOwner(String string) {
335
                owner = string;
336
                modified = true;
337
                change.firePropertyChange("", null, null);
338
        }
339

    
340
        /**
341
         * Establece el flag de modificado del proyecto
342
         *
343
         * @param b
344
         */
345
        public void setModified(boolean b) {
346
                modified = b;
347
        }
348

    
349
        /**
350
         * Obtiene el color de selecci?n que se usar? en el proyecto
351
         *
352
         * @return
353
         */
354
        public Color getSelectionColor() {
355
                return selectionColor;
356
        }
357

    
358
        /**
359
         * Establece el color de selecci?n
360
         *
361
         * @param color
362
         */
363
        public void setSelectionColor(Color color) {
364
                selectionColor = color;
365
                FSymbol.setSelectionColor(color);
366
                modified = true;
367
                change.firePropertyChange("selectionColor", null, color);
368
        }
369

    
370
        /**
371
         * Obtiene el color como un entero para su serializaci?n a XML
372
         *
373
         * @return
374
         */
375
        public String getColor() {
376
                return StringUtilities.color2String(selectionColor);
377
        }
378

    
379
        /**
380
         * M?todo invocado al recuperar de XML para establecer el color de
381
         * seleccion del proyecto
382
         *
383
         * @param color Entero que representa un color
384
         */
385
        public void setColor(String color) {
386
                modified = true;
387
                selectionColor = StringUtilities.string2Color(color);
388
        }
389

    
390
        /* (non-Javadoc)
391
         * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
392
         */
393
        public void propertyChange(PropertyChangeEvent evt) {
394
                this.modified = true;
395
                change.firePropertyChange(evt);
396
        }
397

    
398
        /**
399
         * DOCUMENT ME!
400
         *
401
         * @param arg1
402
         */
403
        public void addExtent(ProjectExtent arg1) {
404
                extents.add(arg1);
405
                modified = true;
406
                change.firePropertyChange("addExtent", null, null);
407
        }
408

    
409
        /**
410
         * DOCUMENT ME!
411
         *
412
         * @param arg0
413
         *
414
         * @return
415
         */
416
        public Object removeExtent(int arg0) {
417
                modified = true;
418
                change.firePropertyChange("delExtent", null, null);
419

    
420
                return extents.remove(arg0);
421
        }
422

    
423
        /**
424
         * DOCUMENT ME!
425
         *
426
         * @return DOCUMENT ME!
427
         */
428
        public ProjectExtent[] getExtents() {
429
                return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]);
430
        }
431

    
432
        /**
433
         * DOCUMENT ME!
434
         *
435
         * @param arg0
436
         */
437
        public synchronized void addPropertyChangeListener(
438
                PropertyChangeListener arg0) {
439
                change.addPropertyChangeListener(arg0);
440
        }
441

    
442
        /**
443
         * DOCUMENT ME!
444
         * @deprecated utilizar getDocument(String s);
445
         * @return
446
         */
447
        public ArrayList getMaps() {
448
                return getDocumentsByType(ProjectMapFactory.registerName);
449
        }
450

    
451
        /**
452
         * DOCUMENT ME!
453
         * @deprecated utilizar getDocument(String s);
454
         * @return
455
         */
456
        public ArrayList getTables() {
457
                return getDocumentsByType(ProjectTableFactory.registerName);
458
        }
459

    
460
        /**
461
         * DOCUMENT ME!
462
         * @deprecated utilizar getDocument(String s);
463
         * @return
464
         */
465
        public ArrayList getViews() {
466
                return getDocumentsByType(ProjectViewFactory.registerName);
467
        }
468
        /**
469
         * A?ade un mapa al proyecto
470
         * @deprecated utilizar addDocument(ProjectDocument pD);
471
         * @param m
472
         */
473
        public void addMap(ProjectMap m) {
474
                addDocument(m);
475
        }
476

    
477
        /**
478
         * Elimina un mapa del proyecto
479
         * @deprecated utilizar delDocument(ProjectDocument pD);
480
         * @param i indice del mapa
481
         */
482
        public void delMap(int i) {
483
                ArrayList list=getDocumentsByType(ProjectMapFactory.registerName);
484
                delDocument((ProjectDocument)list.get(i));
485
        }
486
        /**
487
         * A?ade una tabla al proyecto
488
         * @deprecated utilizar addDocument(ProjectDocument pD);
489
         * @param t
490
         */
491
        public void addTable(ProjectTable t) {
492
                addDocument(t);
493
        }
494

    
495
        /**
496
         * Elimina una tabla del proyecto
497
         * @deprecated utilizar delDocument(ProjectDocument pD);
498
         * @param i indice de la tabla
499
         */
500
        public void delTable(int i) {
501
                ArrayList list=getDocumentsByType(ProjectTableFactory.registerName);
502
                delDocument((ProjectDocument)list.get(i));
503
        }
504
        /**
505
         * A?ade una vista al proyecto
506
         * @deprecated utilizar addDocument(ProjectDocument pD);
507
         * @param v
508
         */
509
        public void addView(ProjectView v) {
510
                addDocument(v);
511
        }
512

    
513
        /**
514
         * Elimina una tabla del proyecto
515
         * @deprecated utilizar delDocument(ProjectDocument pD);
516
         * @param i indice del proyecto
517
         */
518
        public void delView(int i) {
519
                ArrayList list=getDocumentsByType(ProjectViewFactory.registerName);
520
                delDocument((ProjectDocument)list.get(i));
521
        }
522

    
523

    
524
        /**
525
         * DOCUMENT ME!
526
         *
527
         * @return DOCUMENT ME!
528
         *
529
         * @throws DriverException
530
         * @throws XMLException
531
         */
532
        public XMLEntity getXMLEntity() {
533
                XMLEntity xml = new XMLEntity();
534
                xml.putProperty("className", this.getClass().getName());
535
                xml.putProperty("VERSION", VERSION);
536
                xml.putProperty("comments", comments);
537
                xml.putProperty("creationDate", creationDate);
538

    
539
                int numExtents = extents.size();
540
                xml.putProperty("numExtents", numExtents);
541

    
542
                for (int i = 0; i < numExtents; i++) {
543
                        xml.addChild(((ProjectExtent) extents.get(i)).getXMLEntity());
544
                }
545

    
546
        // NUEVO: ESTO ESTA EN PRUEBAS. SIRVE PARA
547
        // BORRAR LAS REFERENCIAS A DATASOURCES QUE HEMOS
548
        // BORRADO. Hay que probar a borrarlos cuando se
549
        // borra una tabla y cuando se borra una capa.
550
        cleanBadReferences();
551
                SourceInfo[] infos = LayerFactory.getDataSourceFactory().getDriverInfos();
552
                xml.putProperty("data-source-count", infos.length);
553

    
554
                for (int i = 0; i < infos.length; i++) {
555
                        SourceInfo di = infos[i];
556
                        XMLEntity child = this.getSourceInfoXMLEntity(di);
557
                        xml.addChild(child);
558
                }
559
                int numDocuments=0;
560
                for (int i = 0; i < documents.size(); i++) {
561
                        try {
562
                                XMLEntity xmlchild=((ProjectDocument) documents.get(i)).getXMLEntity();
563
                                xml.addChild(xmlchild);
564
                                numDocuments++;
565
                        } catch (SaveException e) {
566
                                e.showError();
567
                        }
568
                }
569
                xml.putProperty("numDocuments", numDocuments);
570
        /*        int numViews=0;
571
                for (int i = 0; i < views.size(); i++) {
572
                        try {
573
                                XMLEntity xmlchild=((ProjectView) views.get(i)).getXMLEntity();
574
                                xml.addChild(xmlchild);
575
                                numViews++;
576
                        } catch (SaveException e) {
577
                                e.showError();
578
                        }
579
                }
580
                xml.putProperty("numViews", numViews);
581

582
                int numMaps=0;
583
                for (int i = 0; i < maps.size(); i++) {
584
                        try {
585
                                XMLEntity xmlchild=((ProjectMap) maps.get(i)).getXMLEntity();
586
                                xml.addChild(xmlchild);
587
                                numMaps++;
588
                        } catch (SaveException e) {
589
                                e.showError();
590
                        }
591
                }
592
                xml.putProperty("numMaps", numMaps);
593
                */
594
                xml.putProperty("modificationDate", modificationDate);
595
                xml.putProperty("modified", modified);
596
                xml.putProperty("name", name);
597
                xml.putProperty("owner", owner);
598
                //xml.putProperty("path", path);
599
                xml.putProperty("selectionColor",
600
                        StringUtilities.color2String(selectionColor));
601
/*
602
                int numTables=0;
603
                for (int i = 0; i < tables.size(); i++) {
604
                        try {
605
                                XMLEntity xmlchild=((ProjectTable) tables.get(i)).getXMLEntity();
606
                                xml.addChild(xmlchild);
607
                                numTables++;
608
                        } catch (SaveException e) {
609

610
                                e.showError();
611
                        }
612
                }
613
                xml.putProperty("numTables", numTables);
614
        */
615
                xml.putProperty("projection", defaultProjection.getAbrev());
616

    
617
                // save the properties of the Project Manager window
618
                IWindow[] andamiViews = PluginServices.getMDIManager().getAllWindows();
619
                for (int i=0; i<andamiViews.length; i++) {
620
                        if (andamiViews[i] instanceof ProjectWindow) {
621
                                ProjectWindow pw = (ProjectWindow) andamiViews[i];
622
                                try {
623
                                        XMLEntity xmlchild = null;
624
                                        xmlchild = getWindowInfoXMLEntity(pw);
625
                                        if (xmlchild!=null) {
626
                                                xml.addChild(xmlchild);
627
                                        }
628
                                }
629
                                catch (SaveException e){
630
                                        e.showError();
631
                                }
632
                        }
633
                }
634

    
635
                return xml;
636
        }
637
        /**
638
         * DOCUMENT ME!
639
         *
640
         * @param xml DOCUMENT ME!
641
         *
642
         * @return DOCUMENT ME!
643
         * @throws XMLException
644
         * @throws DriverException
645
         * @throws DriverIOException
646
         * @throws OpenException
647
         */
648
        public static Project createFromXML03(XMLEntity xml)
649
                throws OpenException {
650
                Project p = new Project();
651
                try{
652
                p.comments = xml.getStringProperty("comments");
653
                p.creationDate = xml.getStringProperty("creationDate");
654

    
655
                int numExtents=xml.getIntProperty("numExtents");
656
                for (int i = 0; i < numExtents; i++) {
657
                        ProjectExtent pe=ProjectExtent.createFromXML03(xml.getChild(i));
658
                        p.extents.add(pe);
659
                }
660

    
661
                int numDocuments=0;
662
                if (xml.contains("numDocuments")) {
663
                        numDocuments=xml.getIntProperty("numDocuments");
664
                }else {
665
                        int numViews = xml.getIntProperty("numViews");
666
                        int numMaps = xml.getIntProperty("numMaps");
667
                        int numTables = xml.getIntProperty("numTables");
668
                        numDocuments=numViews+numMaps+numTables;
669
                }
670
                for (int i = numExtents; i < numDocuments+numExtents; i++) {
671
                        ProjectDocument pD=ProjectDocument.createFromXML03(xml.getChild(i), p);
672
                        p.addDocument(pD);
673
                        p.sortedDocuments.put(pD,new Integer(i));
674
                }
675
                ProjectDocument[] sortDocKeys=(ProjectDocument[])p.sortedDocuments.keySet().toArray(new ProjectDocument[0]);
676
                Integer[] sortDocValues=(Integer[])p.sortedDocuments.values().toArray(new Integer[0]);
677

    
678
                int i=0;
679
                for (int k = numExtents; k < (numDocuments + numExtents); k++) {
680
                                sortDocKeys[i].setXMLEntity(xml.getChild(sortDocValues[i].intValue()),p);
681
                        i++;
682
                }
683

    
684
                p.modificationDate = xml.getStringProperty("modificationDate");
685
                p.modified = xml.getBooleanProperty("modified");
686
                p.name = xml.getStringProperty("name");
687
                p.owner = xml.getStringProperty("owner");
688
                p.selectionColor = StringUtilities.string2Color(xml.getStringProperty(
689
                                        "selectionColor"));
690

    
691
                String strProj = xml.getStringProperty("projection");
692
                if (strProj != null)
693
                        p.setProjection( CRSFactory.getCRS(strProj));
694
                }catch (Exception e) {
695
                        throw new OpenException(e,p.getClass().getName());
696
                }
697
                return p;
698
        }
699

    
700
        /**
701
         * DOCUMENT ME!
702
         *
703
         * @param xml DOCUMENT ME!
704
         *
705
         * @return DOCUMENT ME!
706
         *
707
         * @throws XMLException
708
         * @throws DriverException
709
         * @throws DriverIOException
710
         * @throws OpenException
711
         * @throws VersionException
712
         */
713
        public static Project createFromXML(XMLEntity xml)
714
                throws OpenException {
715

    
716
                int childNumber = 0;
717
                Project p = new Project();
718
                try{
719
                p.comments = xml.getStringProperty("comments");
720
                p.creationDate = xml.getStringProperty("creationDate");
721
                int numExtents = xml.getIntProperty("numExtents");
722

    
723
                for (int i = 0; i < numExtents; i++) {
724
                        ProjectExtent pe = ProjectExtent.createFromXML(xml.getChild(i));
725
                        p.extents.add(pe);
726
                }
727

    
728
                childNumber = numExtents;
729

    
730
                int numDataSources = xml.getIntProperty("data-source-count");
731

    
732
                for (int i = childNumber; i < (childNumber + numDataSources); i++) {
733
                        XMLEntity child = xml.getChild(i);
734

    
735
                        if (child.getStringProperty("type").equals("otherDriverFile")) {
736
                                LayerFactory.getDataSourceFactory().addFileDataSource(child.getStringProperty(
737
                                                "driverName"), child.getStringProperty("gdbmsname"),
738
                                        child.getStringProperty("file"));
739
                        } else if (child.getStringProperty("type").equals("sameDriverFile")) {
740
                        } else if (child.getStringProperty("type").equals("db")) {
741
                                LayerFactory.getDataSourceFactory().addDBDataSourceByTable(child.getStringProperty(
742
                                                "gdbmsname"), child.getStringProperty("host"),
743
                                        child.getIntProperty("port"),
744
                                        child.getStringProperty("user"),
745
                                        child.getStringProperty("password"),
746
                                        child.getStringProperty("dbName"),
747
                                        child.getStringProperty("tableName"),
748
                                        child.getStringProperty("driverInfo"));
749
                        }
750
                }
751

    
752
                childNumber += numDataSources;
753
                int numDocuments=0;
754
                if (xml.contains("numDocuments")) {
755
                        numDocuments=xml.getIntProperty("numDocuments");
756
                }else {
757
                        int numViews = xml.getIntProperty("numViews");
758
                        int numMaps = xml.getIntProperty("numMaps");
759
                        int numTables = xml.getIntProperty("numTables");
760
                        numDocuments=numViews+numMaps+numTables;
761
                }
762

    
763
                for (int i = childNumber; i < (numDocuments + childNumber); i++) {
764
                        try{
765
                                ProjectDocument pD=ProjectDocument.createFromXML(xml.getChild(i), p);
766
                                p.addDocument(pD);
767
                                p.sortedDocuments.put(pD,new Integer(i));
768
                                if (pD.getSeedViewInfo()!=null) { // open the view, if it was open, and restore its dimensions
769
                                        IWindow window=pD.createWindow();
770
                                        PluginServices.getMDIManager().addWindow(window);
771
                                        PluginServices.getMDIManager().changeWindowInfo(window, pD.getSeedViewInfo());
772
                                }
773
                        }catch(OpenException e){
774
                                e.showError();
775
                        }
776
                }
777
                ProjectDocument[] sortDocKeys=(ProjectDocument[])p.sortedDocuments.keySet().toArray(new ProjectDocument[0]);
778
                Integer[] sortDocValues=(Integer[])p.sortedDocuments.values().toArray(new Integer[0]);
779

    
780
                int i=0;
781
                for (int k = childNumber; k < (numDocuments + childNumber); k++) {
782
                        try{
783
                        sortDocKeys[i].setXMLEntity(xml.getChild(sortDocValues[i].intValue()),p);
784
                        }catch(OpenException e){
785
                                e.showError();
786
                        }
787
                        i++;
788
                }
789
                childNumber += numDocuments;
790

    
791
                p.modificationDate = xml.getStringProperty("modificationDate");
792
                p.modified = xml.getBooleanProperty("modified");
793
                p.name = xml.getStringProperty("name");
794
                p.owner = xml.getStringProperty("owner");
795
                p.selectionColor = StringUtilities.string2Color(xml.getStringProperty(
796
                                        "selectionColor"));
797

    
798
                p.setLinkTable();
799
                String strProj = xml.getStringProperty("projection");
800

    
801
                if (strProj != null) {
802
                        p.setProjection( CRSFactory.getCRS(strProj));
803
                }
804
        PostProcessSupport.executeCalls();
805
                }catch (Exception e) {
806
                        throw new OpenException(e,p.getClass().getName());
807
                }
808
//                p.setSignature( p.hashCode());
809
                return p;
810

    
811
        }
812

    
813
//        private void setSignature(int signature) {
814
//                this.signatureAtStartup = computeSignature();
815
//        }
816

    
817
        /**
818
         * Reestablece los link que ten?a cada tabla con las dem?s.
819
         */
820
        public void setLinkTable() {
821
                ArrayList tables = getDocumentsByType(ProjectTableFactory.registerName);
822

    
823
                for (int i = 0; i < tables.size(); i++) {
824
                        for (int j = 0; j < tables.size(); j++) {
825
                                /*System.out.println("name = " +
826
                                        ((ProjectTable) tables.get(j)).getModelo().getName());
827
                                System.out.println("linktable = " +
828
                                        ((ProjectTable) tables.get(i)).getLinkTable());
829
*/
830
                                try {
831
                                if ((((ProjectTable) tables.get(i)).getLinkTable() != null) &&
832
                                                ((ProjectTable) tables.get(i)).getLinkTable().equals(((ProjectTable) tables
833
                                                                                                                                                                  .get(
834
                                                                j)).getModelo().getRecordset().getName())) {
835
                                        LinkSelectionListener lsl;
836

    
837
                                                lsl = new LinkSelectionListener(((ProjectTable) tables.get(
838
                                                                        i)).getModelo().getRecordset(),
839
                                                                        ((ProjectTable) tables.get(j)).getModelo().getRecordset(),
840
                                                                ((ProjectTable) tables.get(i)).getField1(),
841
                                                                ((ProjectTable) tables.get(i)).getField2());
842

    
843
                                                (((ProjectTable) tables.get(i)).getModelo().getRecordset())
844
                                         .addSelectionListener(lsl);
845

    
846
                                }
847
                                } catch (DriverLoadException e) {
848
                                        // TODO Auto-generated catch block
849
                                        e.printStackTrace();
850
                                }
851
                        }
852
                }
853
        }
854

    
855
        /**
856
         * Obtiene la vista que contiene a la capa que se pasa como par?metro
857
         *
858
         * @param layer Capa cuya vista se quiere obtener
859
         *
860
         * @return
861
         *
862
         * @throws RuntimeException Si la capa que se pasa como par?metro no se
863
         *                    encuentra en ninguna vista
864
         */
865
        public String getView(FLayer layer) {
866
                ArrayList views=getDocumentsByType(ProjectViewFactory.registerName);
867
                for (int v = 0; v < views.size(); v++) {
868
                        ProjectView pView = (ProjectView) views.get(v);
869
                        FLayers layers = pView.getMapContext().getLayers();
870
                        if (isView(layers,layer))return pView.getName();
871
                }
872

    
873
                throw new RuntimeException("The layer is not in a view");
874
        }
875

    
876
        public boolean isView(FLayers layers, FLayer layer) {
877
                for (int i = 0; i < layers.getLayersCount(); i++) {
878
                        if (layers.getLayer(i) instanceof FLayers){
879
                                return isView((FLayers)layers.getLayer(i),layer);
880
                        }
881
                        if (layers.getLayer(i) == layer) {
882
                                        return true;
883
                        }
884
                }
885
                return false;
886
        }
887

    
888
        /**
889
         * Devuelve la vista cuyo nombre coincide (sensible a mayusculas) con el
890
         * que se pasa como par?metro. Devuelve null si no hay ninguna vista con
891
         * ese nombre
892
         *
893
         * @param viewName Nombre de la vista que se quiere obtener
894
         *
895
         * @return DOCUMENT ME!
896
         */
897
        /*public ProjectView getViewByName(String viewName) {
898
                ArrayList views=getDocuments(PluginServices.getText(this,"Vista"));
899
                Object o = getProjectDocumentByName(viewName, PluginServices.getText(this,"Vista"));
900

901
                if (o == null) {
902
                        return null;
903
                }
904

905
                return (ProjectView) o;
906
        }
907
*/
908
        /**
909
         * DOCUMENT ME!
910
         *
911
         * @return DOCUMENT ME!
912
         */
913
        public IProjection getProjection() {
914
                if (projection == null)
915
                        projection = Project.defaultProjection;
916
                return projection;
917
        }
918

    
919
        /**
920
         * DOCUMENT ME!
921
         *
922
         * @param defaultProjection DOCUMENT ME!
923
         */
924
        public void setProjection(IProjection projection) {
925
                this.projection = projection;
926
        }
927

    
928

    
929
        /**
930
         * Sets the projection used when no projection is defined
931
         * @param defaultProjection DOCUMENT ME!
932
         */
933
        public static void setDefaultProjection(IProjection defaultProjection) {
934
                Project.defaultProjection = defaultProjection;
935
        }
936

    
937
        public static IProjection getDefaultProjection() {
938
                return Project.defaultProjection;
939
        }
940

    
941
        /**
942
         * Obtiene un documento a partir de su nombre y el nombre de registro en el pointExtension,
943
         * este ?ltimo se puede obtener del Project****Factory.registerName.
944
         *
945
         * @param name Nombre del documento
946
         * @param type nombre de registro en el extensionPoint
947
         *
948
         * @return Documento
949
         */
950
        public ProjectDocument getProjectDocumentByName(String name, String type) {
951
                ArrayList docs=getDocumentsByType(type);
952
                for (Iterator iter = docs.iterator(); iter.hasNext();) {
953
                        ProjectDocument elem = (ProjectDocument) iter.next();
954

    
955
                        if (elem.getName().equals(name)) {
956
                                return elem;
957
                        }
958
                }
959

    
960
                return null;
961
        }
962

    
963
        /**
964
         * DOCUMENT ME!
965
         *
966
         * @param name
967
         *
968
         * @return
969
         */
970
        /*public ProjectTable getTableByName(String name) {
971
                ArrayList tables=getDocuments(PluginServices.getText(this,"Tabla"));
972
                Object o = getProjectElementByName(name, tables);
973

974
                if (o == null) {
975
                        return null;
976
                }
977

978
                return (ProjectTable) o;
979
        }
980
*/
981
        /**
982
         * DOCUMENT ME!
983
         *
984
         * @param name
985
         *
986
         * @return
987
         */
988
        /*public ProjectMap getLayoutByName(String name) {
989
                Object o = getProjectElementByName(name, maps);
990

991
                if (o == null) {
992
                        return null;
993
                }
994

995
                return (ProjectMap) o;
996
        }
997
*/
998
    public SelectableDataSource getDataSourceByLayer(FLayer layer) throws DriverException {
999
        ArrayList tables = getDocumentsByType(ProjectTableFactory.registerName);
1000
        SelectableDataSource dataSource = null;
1001
        try {
1002
        for (int i = 0; i < tables.size(); i++) {
1003
            ProjectTable pt = (ProjectTable) tables.get(i);
1004
            if (pt.getOriginal() == ((AlphanumericData) layer).getRecordset()){
1005
                dataSource = pt.getModelo().getRecordset();
1006
                break;
1007
            }else if (pt.getModelo() == ((AlphanumericData) layer).getRecordset()){
1008

    
1009
                                        dataSource = pt.getModelo().getRecordset();
1010

    
1011
                break;
1012
            }
1013
        }
1014
        } catch (DriverLoadException e) {
1015
                        // TODO Auto-generated catch block
1016
                        e.printStackTrace();
1017
                }
1018

    
1019
        if (dataSource == null){
1020
            //No se ha creado la tabla asociada al tema
1021
            dataSource = ((AlphanumericData) layer).getRecordset();
1022
        }
1023

    
1024
        return dataSource;
1025

    
1026
    }
1027

    
1028
    /**
1029
     * Recorremos las capas y las tablas del proyecto, y creamos una lista
1030
     * con todos los datasources de GDBMS que estamos usando.
1031
     * Luego recorremos los que est?n registrados, y borramos
1032
     * aquellos que no est?n siendo usados, es decir, aquellos
1033
     * que no est?n en nuestra lista (un Hash con clave el nombre
1034
     * del GDBMS)
1035
     *
1036
     */
1037
    private void cleanBadReferences()
1038
    {
1039
            ArrayList tables=getDocumentsByType(ProjectTableFactory.registerName);
1040
        Hashtable usedDataSources = new Hashtable();
1041
        // Primero las tablas
1042
        int i, j;
1043
        try {
1044
        for (i=0; i<tables.size(); i++)
1045
        {
1046
            ProjectTable t = (ProjectTable) tables.get(i);
1047
            SelectableDataSource ds;
1048

    
1049
                                ds = t.getModelo().getRecordset();
1050

    
1051
            if (t.getOriginal() != null)
1052
                usedDataSources.put(t.getOriginal().getRecordset().getName(), t.getOriginal());
1053
            usedDataSources.put(ds.getName(), ds);
1054
        }
1055
        } catch (DriverLoadException e) {
1056
                        // TODO Auto-generated catch block
1057
                        e.printStackTrace();
1058
                }
1059
        // Ahora las vistas
1060
        ArrayList views=getDocumentsByType(ProjectViewFactory.registerName);
1061
        try {
1062
            for (i=0; i<views.size(); i++)
1063
            {
1064
                ProjectView pv = (ProjectView) views.get(i);
1065

    
1066
                FLayers lyrs = pv.getMapContext().getLayers();
1067

    
1068
                for (j=0; j<lyrs.getLayersCount(); j++)
1069
                {
1070
                    FLayer lyr = lyrs.getLayer(j);
1071
                    if (lyr instanceof FLyrVect)
1072
                    {
1073
                        FLyrVect lyrVect = (FLyrVect) lyr;
1074
                        if (lyrVect.isAvailable())
1075
                                usedDataSources.put(lyrVect.getRecordset().getName(), lyrVect.getSource().getRecordset());
1076
                    }
1077
                }
1078
                MapContext aux = pv.getMapOverViewContext();
1079
                if (aux != null)
1080
                {
1081
                    FLayers lyrsOverview = aux.getLayers();
1082
                    for (j=0; j<lyrsOverview.getLayersCount(); j++)
1083
                    {
1084
                        FLayer lyr = lyrsOverview.getLayer(j);
1085
                        if (lyr instanceof FLyrVect)
1086
                        {
1087
                            FLyrVect lyrVect = (FLyrVect) lyr;
1088
                            usedDataSources.put(lyrVect.getSource().getRecordset().getName(), lyrVect.getSource().getRecordset());
1089
                        }
1090
                    }
1091
                }
1092

    
1093
            } // for i
1094
        } catch (DriverLoadException e) {
1095
                        // TODO Auto-generated catch block
1096
                        e.printStackTrace();
1097
                } catch (DriverException e) {
1098
                        // TODO Auto-generated catch block
1099
                        e.printStackTrace();
1100
                }
1101
        // Recorremos los dataSources y los borramos si no
1102
        // los estamos usando.
1103
        SourceInfo[] infos = LayerFactory.getDataSourceFactory().getDriverInfos();
1104
        try {
1105
            for (i=0; i < infos.length; i++)
1106
            {
1107
                if (!usedDataSources.containsKey(infos[i].name))
1108
                {
1109
                    DataSource ds;
1110
                    ds = LayerFactory.getDataSourceFactory().createRandomDataSource(infos[i].name);
1111
                    ds.remove();
1112
                }
1113
            }
1114
        } catch (DriverLoadException e) {
1115
            // TODO Auto-generated catch block
1116
            e.printStackTrace();
1117
        } catch (NoSuchTableException e) {
1118
            // TODO Auto-generated catch block
1119
            e.printStackTrace();
1120
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
1121
            // TODO Auto-generated catch block
1122
            e.printStackTrace();
1123
        }
1124
    }
1125

    
1126
    /**
1127
         * DOCUMENT ME!
1128
         *
1129
         * @return DOCUMENT ME!
1130
     * @throws SaveException
1131
         * @throws XMLException
1132
         * @throws SaveException
1133
         */
1134
        public XMLEntity getWindowInfoXMLEntity(IWindow window) throws SaveException {
1135
                if (window!=null && PluginServices.getMDIManager().getWindowInfo(window)!=null) {
1136
                        WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(window);
1137
                        XMLEntity xml = new XMLEntity();
1138
                        //xml.putProperty("nameClass", this.getClass().getName());
1139
                        try{
1140
                                xml.setName("ViewInfoProperties");
1141
                                xml.putProperty("className", this.getClass().getName());
1142
                                xml.putProperty("X", vi.getX());
1143
                                xml.putProperty("Y", vi.getY());
1144
                                xml.putProperty("Width", vi.getWidth());
1145
                                xml.putProperty("Height", vi.getHeight());
1146
                                xml.putProperty("isVisible", vi.isVisible());
1147
                                xml.putProperty("isResizable", vi.isResizable());
1148
                                xml.putProperty("isMaximizable", vi.isMaximizable());
1149
                                xml.putProperty("isModal", vi.isModal());
1150
                                xml.putProperty("isModeless", vi.isModeless());
1151
                                xml.putProperty("isClosed", vi.isClosed());
1152
                                if (vi.isMaximized()==true) {
1153
                                        xml.putProperty("isMaximized", vi.isMaximized());
1154
                                        xml.putProperty("normalX", vi.getNormalX());
1155
                                        xml.putProperty("normalY", vi.getNormalY());
1156
                                        xml.putProperty("normalWidth", vi.getNormalWidth());
1157
                                        xml.putProperty("normalHeight", vi.getNormalHeight());
1158
                                }
1159
                        }catch (Exception e) {
1160
                                throw new SaveException(e,this.getClass().getName());
1161
                        }
1162
                        return xml;
1163
                }
1164
                return null;
1165
        }
1166

    
1167
        public static WindowInfo createWindowInfoFromXMLEntity(XMLEntity xml)
1168
        {
1169
                WindowInfo result = new WindowInfo();
1170
                result.setX(xml.getIntProperty("X"));
1171
                result.setY(xml.getIntProperty("Y"));
1172
                result.setHeight(xml.getIntProperty("Height"));
1173
                result.setWidth(xml.getIntProperty("Width"));
1174
                result.setClosed(xml.getBooleanProperty("isClosed"));
1175
                if (xml.contains("isMaximized")) {
1176
                        boolean maximized = xml.getBooleanProperty("isMaximized");
1177
                        result.setMaximized(maximized);
1178
                        if (maximized==true) {
1179
                                result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
1180
                        }
1181
                        else {
1182
                                result.setNormalBounds(result.getBounds());
1183
                        }
1184
                }
1185

    
1186
                return result;
1187
        }
1188

    
1189
        public static WindowInfo getSeedProjectWindow() {
1190
                return seedProjectWindow;
1191
        }
1192

    
1193
        public XMLEntity getSourceInfoXMLEntity(SourceInfo di) {
1194
                XMLEntity child = new XMLEntity();
1195

    
1196

    
1197
                if (di instanceof ObjectSourceInfo) {
1198
                        ObjectSourceInfo driver = (ObjectSourceInfo) di;
1199
                        child.putProperty("type", "sameDriverFile");
1200
                        child.putProperty("gdbmsname", driver.name);
1201
                } else if (di instanceof FileSourceInfo) {
1202
                        FileSourceInfo vfdi = (FileSourceInfo) di;
1203
                        child.putProperty("type", "otherDriverFile");
1204
                        child.putProperty("gdbmsname", vfdi.name);
1205
                        child.putProperty("file", vfdi.file);
1206
                        child.putProperty("driverName", vfdi.driverName);
1207
                } else if (di instanceof DBSourceInfo) {
1208
                        DBTableSourceInfo dbdi = (DBTableSourceInfo) di;
1209
                        child.putProperty("type", "db");
1210
                        child.putProperty("gdbmsname", dbdi.name);
1211
                        child.putProperty("dbms", dbdi.dbms);
1212
                        child.putProperty("host", dbdi.host);
1213
                        child.putProperty("port", dbdi.port);
1214
                        child.putProperty("user", dbdi.user);
1215
                        child.putProperty("password", dbdi.password);
1216
                        child.putProperty("dbName", dbdi.dbName);
1217
                        child.putProperty("tableName", dbdi.tableName);
1218
                        child.putProperty("driverInfo", dbdi.driverName);
1219
                }
1220

    
1221
                return child;
1222
        }
1223
        /**
1224
         * Devuelve un arrayList con todos los documentos del tipo especificado como par?metro.
1225
         *
1226
         * @param registerName nombre de registro en el extensionPoint
1227
         *
1228
         * @return Documentos del tipo especificado
1229
         */
1230
        public ArrayList getDocumentsByType(String registerName) {
1231
                ArrayList docuArray=new ArrayList();
1232
                for (int i=0;i<documents.size();i++) {
1233
                        ProjectDocument projectDocument=(ProjectDocument)documents.get(i);
1234
                        ProjectDocumentFactory pdf=projectDocument.getProjectDocumentFactory();
1235
                        if (pdf==null)
1236
                                continue;
1237
                        if (pdf.getRegisterName().equals(registerName)) {
1238
                                docuArray.add(projectDocument);
1239
                        }
1240
                }
1241
                return docuArray;
1242
        }
1243
        /**
1244
         * Devuelve un arrayList con todos los documentos.
1245
         *
1246
         * @return Documentos
1247
         */
1248
        public ArrayList getDocuments() {
1249
                ArrayList docuArray=new ArrayList();
1250
                for (int i=0;i<documents.size();i++) {
1251
                        ProjectDocument projectDocument=(ProjectDocument)documents.get(i);
1252
                        docuArray.add(projectDocument);
1253
                }
1254
                return docuArray;
1255
        }
1256
        /**
1257
         * Inserta un documento.
1258
         *
1259
         * @param doc Documento
1260
         */
1261
        public void addDocument(ProjectDocument doc) {
1262
                documents.add(doc);
1263
                doc.addPropertyChangeListener(this);
1264
                modified = true;
1265
                change.firePropertyChange("", null, null);
1266
                doc.setProject(this, 0);
1267
                doc.afterAdd();
1268

    
1269
        }
1270
        /**
1271
         * Borra un documento.
1272
         *
1273
         * @param doc Documento
1274
         */
1275
        public void delDocument(ProjectDocument doc) {
1276
                documents.remove(doc);
1277
                modified = true;
1278
                change.firePropertyChange("", null, null);
1279
                doc.afterRemove();
1280
        }
1281

    
1282
//        public boolean hasChanged() {
1283
//                return signatureAtStartup != computeSignature();
1284
//        }
1285

    
1286
//        public int computeSignature() {
1287
//
1288
////                /* TODO method also present in ProjectMap, ProjectTable,
1289
////                 *  ProjectView and ProjectExtent
1290
////                 */
1291
//                int result = 17;
1292
////
1293
////                Class clazz = getClass();
1294
////                Field[] fields = clazz.getDeclaredFields();
1295
////                for (int i = 0; i < fields.length; i++) {
1296
////                        try {
1297
////                                // don't compute following fields
1298
////                                if (fields[i].getName().equals("modificationDate")
1299
////                                                || fields[i].getName().equals("creationDate")
1300
////                                                || fields[i].getName().equals("signatureAtStartup")
1301
////                                                || fields[i].getName().equals("change")
1302
////                                                || Modifier.isStatic(fields[i].getModifiers()))
1303
////                                        continue;
1304
////
1305
////
1306
////                                String type = fields[i].getType().getName();
1307
////                                if (type.equals("boolean")) {
1308
////                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
1309
////                                } else if (type.equals("java.lang.String")) {
1310
////                                        Object v = fields[i].get(this);
1311
////                                        if (v == null) {
1312
////                                                result += 37;
1313
////                                                continue;
1314
////                                        }
1315
////                                        char[] chars = ((String) v).toCharArray();
1316
////                                        for (int j = 0; j < chars.length; j++) {
1317
////                                                result += 37 + (int) chars[i];
1318
////                                        }
1319
////                                } else if (type.equals("byte")) {
1320
////                                        result += 37 + (int) fields[i].getByte(this);
1321
////                                } else if (type.equals("char")) {
1322
////                                        result += 37 + (int) fields[i].getChar(this);
1323
////                                } else if (type.equals("short")) {
1324
////                                        result += 37 + (int) fields[i].getShort(this);
1325
////                                } else if (type.equals("int")) {
1326
////                                        result += 37 + fields[i].getInt(this);
1327
////                                } else if (type.equals("long")) {
1328
////                                        long f = fields[i].getLong(this) ;
1329
////                                        result += 37 + (f ^ (f >>> 32));
1330
////                                } else if (type.equals("float")) {
1331
////                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
1332
////                                } else if (type.equals("double")) {
1333
////                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
1334
////                                        result += 37 + (f ^ (f >>> 32));
1335
////                                } else {
1336
//////                                        Object obj = fields[i].get(this);
1337
//////                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
1338
////                                }
1339
////                        } catch (Exception e) { e.printStackTrace(); }
1340
////
1341
////                }
1342
////
1343
////                for (int i = 0; i < views.size(); i++) {
1344
////                        ProjectView e = (ProjectView) views.get(i);
1345
////                        result += 37 + e.computeSignature();
1346
////                }
1347
////
1348
////                for (int i = 0; i < tables.size(); i++) {
1349
////                        ProjectTable e = (ProjectTable) tables.get(i);
1350
////                        result += 37 + e.computeSignature();
1351
////                }
1352
////
1353
////                for (int i = 0; i < maps.size(); i++) {
1354
////                        ProjectMap e = (ProjectMap) maps.get(i);
1355
////                        result += 37 + e.computeSignature();
1356
////                }
1357
////
1358
////                for (int i = 0; i < extents.size(); i++) {
1359
////                        ProjectExtent e = (ProjectExtent) extents.get(i);
1360
////                        result += 37 + e.computeSignature();
1361
////                }
1362
//
1363
//
1364
//                return result;
1365
//        }
1366

    
1367
}