svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / Project.java @ 3060
History | View | Annotate | Download (26.3 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.Date; |
51 |
import java.util.Hashtable; |
52 |
import java.util.Iterator; |
53 |
|
54 |
import org.cresques.cts.IProjection; |
55 |
import org.cresques.cts.ProjectionPool; |
56 |
|
57 |
import com.hardcode.driverManager.DriverLoadException; |
58 |
import com.hardcode.gdbms.engine.data.DataSource; |
59 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
60 |
import com.hardcode.gdbms.engine.data.SourceInfo; |
61 |
import com.hardcode.gdbms.engine.data.db.DBSourceInfo; |
62 |
import com.hardcode.gdbms.engine.data.db.DBTableSourceInfo; |
63 |
import com.hardcode.gdbms.engine.data.file.FileSourceInfo; |
64 |
import com.hardcode.gdbms.engine.data.object.ObjectSourceInfo; |
65 |
import com.iver.cit.gvsig.fmap.DriverException; |
66 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
67 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
68 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
71 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
72 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
73 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
74 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
75 |
import com.iver.cit.gvsig.fmap.operations.selection.LinkSelectionListener; |
76 |
import com.iver.utiles.PostProcessSupport; |
77 |
import com.iver.utiles.StringUtilities; |
78 |
import com.iver.utiles.XMLEntity; |
79 |
|
80 |
|
81 |
/**
|
82 |
* Clase que representa un proyecto de openSIG
|
83 |
*
|
84 |
* @author Fernando Gonz?lez Cort?s
|
85 |
*/
|
86 |
public class Project implements Serializable, PropertyChangeListener { |
87 |
public static String VERSION = "0.5"; |
88 |
static private IProjection defaultProjection = ProjectionPool.get( |
89 |
"EPSG:23030");
|
90 |
private PropertyChangeSupport change; |
91 |
boolean modified = false; |
92 |
private String name; |
93 |
private String path; |
94 |
private String creationDate; |
95 |
private String modificationDate; |
96 |
private String owner; |
97 |
private String comments; |
98 |
private Color selectionColor = new Color(255, 255, 0); |
99 |
private ArrayList views = new ArrayList(); |
100 |
private ArrayList tables = new ArrayList(); |
101 |
private ArrayList maps = new ArrayList(); |
102 |
private ArrayList extents = new ArrayList(); |
103 |
|
104 |
/**
|
105 |
* Creates a new Project object.
|
106 |
*/
|
107 |
public Project() {
|
108 |
change = new PropertyChangeSupport(this); |
109 |
|
110 |
// change.addPropertyChangeListener(this);
|
111 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
112 |
modificationDate = creationDate; |
113 |
|
114 |
/* LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
|
115 |
.getPluginDirectory()
|
116 |
.getAbsolutePath() +
|
117 |
File.separator + "drivers");
|
118 |
*/
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* Obtiene la fecha de creaci?n del proyecto
|
123 |
*
|
124 |
* @return
|
125 |
*/
|
126 |
public String getCreationDate() { |
127 |
return creationDate;
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* Obtiene el nombre del proyecto
|
132 |
*
|
133 |
* @return
|
134 |
*/
|
135 |
public String getName() { |
136 |
return name;
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Obtiene la ruta completa del fichero donde se guardo por ?ltima vez el
|
141 |
* proyecto
|
142 |
*
|
143 |
* @return
|
144 |
*/
|
145 |
public String getPath() { |
146 |
return path;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Asigna la fecha de creaci?n del proyecto. Este m?todo tiene sentido s?lo
|
151 |
* por que al recuperar la fecha del XML hay que asignarla al objeto
|
152 |
* proyecto de alguna manera. La fecha se asigna en el constructor y no se
|
153 |
* deber?a de modificar nunca
|
154 |
*
|
155 |
* @param string
|
156 |
*/
|
157 |
public void setCreationDate(String string) { |
158 |
creationDate = string; |
159 |
modified = true;
|
160 |
change.firePropertyChange("", null, null); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* A?ade un mapa al proyecto
|
165 |
*
|
166 |
* @param m
|
167 |
*/
|
168 |
public void addMap(ProjectMap m) { |
169 |
maps.add(m); |
170 |
m.addPropertyChangeListener(this);
|
171 |
modified = true;
|
172 |
change.firePropertyChange("", null, null); |
173 |
m.setProject(this, maps.size() - 1); |
174 |
} |
175 |
|
176 |
/**
|
177 |
* Elimina un mapa del proyecto
|
178 |
*
|
179 |
* @param i indice del mapa
|
180 |
*/
|
181 |
public void delMap(int i) { |
182 |
maps.remove(i); |
183 |
modified = true;
|
184 |
change.firePropertyChange("", null, null); |
185 |
} |
186 |
|
187 |
/**
|
188 |
* Establece el nombre del proyecto
|
189 |
*
|
190 |
* @param string
|
191 |
*/
|
192 |
public void setName(String string) { |
193 |
name = string; |
194 |
modified = true;
|
195 |
change.firePropertyChange("", null, null); |
196 |
} |
197 |
|
198 |
/**
|
199 |
* establece la ruta completa de donde se encuentra guardado el proyecto
|
200 |
*
|
201 |
* @param string
|
202 |
*/
|
203 |
public void setPath(String string) { |
204 |
path = string; |
205 |
modified = true;
|
206 |
change.firePropertyChange("", null, null); |
207 |
} |
208 |
|
209 |
/**
|
210 |
* DOCUMENT ME!
|
211 |
*
|
212 |
* @param co DOCUMENT ME!
|
213 |
*
|
214 |
* @return DOCUMENT ME!
|
215 |
*/
|
216 |
public ProjectTable getTable(AlphanumericData co) {
|
217 |
/**
|
218 |
* Como las tablas se pueden a?adir cuando se pincha en "ver tabla" de
|
219 |
* una capa, se puede intentar a?adir dos veces la misma tabla
|
220 |
*/
|
221 |
for (int i = 0; i < tables.size(); i++) { |
222 |
if (((ProjectTable) tables.get(i)).getAssociatedTable() == co) {
|
223 |
return (ProjectTable) tables.get(i);
|
224 |
} |
225 |
} |
226 |
|
227 |
return null; |
228 |
} |
229 |
|
230 |
/**
|
231 |
* A?ade una tabla al proyecto
|
232 |
*
|
233 |
* @param t
|
234 |
*/
|
235 |
public void addTable(ProjectTable t) { |
236 |
tables.add(t); |
237 |
t.addPropertyChangeListener(this);
|
238 |
modified = true;
|
239 |
change.firePropertyChange("", null, null); |
240 |
t.setProject(this, tables.size() - 1); |
241 |
} |
242 |
|
243 |
/**
|
244 |
* Elimina una tabla del proyecto
|
245 |
*
|
246 |
* @param i indice de la tabla
|
247 |
*/
|
248 |
public void delTable(int i) { |
249 |
tables.remove(i); |
250 |
modified = true;
|
251 |
change.firePropertyChange("", null, null); |
252 |
} |
253 |
|
254 |
/**
|
255 |
* A?ade una vista al proyecto
|
256 |
*
|
257 |
* @param v
|
258 |
*/
|
259 |
public void addView(ProjectView v) { |
260 |
views.add(v); |
261 |
v.addPropertyChangeListener(this);
|
262 |
modified = true;
|
263 |
change.firePropertyChange("", null, null); |
264 |
v.setProject(this, views.size() - 1); |
265 |
} |
266 |
|
267 |
/**
|
268 |
* Elimina una tabla del proyecto
|
269 |
*
|
270 |
* @param i indice del proyecto
|
271 |
*/
|
272 |
public void delView(int i) { |
273 |
views.remove(i); |
274 |
modified = true;
|
275 |
change.firePropertyChange("", null, null); |
276 |
} |
277 |
|
278 |
/**
|
279 |
* Devuelve true si el proyecto (o alguna tabla, vista o mapa que contiene)
|
280 |
* fue modificado
|
281 |
*
|
282 |
* @return
|
283 |
*/
|
284 |
public boolean isModified() { |
285 |
return modified;
|
286 |
} |
287 |
|
288 |
/**
|
289 |
* Obtiene los comentarios
|
290 |
*
|
291 |
* @return
|
292 |
*/
|
293 |
public String getComments() { |
294 |
return comments;
|
295 |
} |
296 |
|
297 |
/**
|
298 |
* Obtiene la fecha de la ?ltima modificaci?n
|
299 |
*
|
300 |
* @return
|
301 |
*/
|
302 |
public String getModificationDate() { |
303 |
return modificationDate;
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* Obtiene el propietario del proyecto
|
308 |
*
|
309 |
* @return
|
310 |
*/
|
311 |
public String getOwner() { |
312 |
return owner;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* Establece una cadena como comentarios al proyecto
|
317 |
*
|
318 |
* @param string
|
319 |
*/
|
320 |
public void setComments(String string) { |
321 |
comments = string; |
322 |
modified = true;
|
323 |
change.firePropertyChange("", null, null); |
324 |
} |
325 |
|
326 |
/**
|
327 |
* Establece la fecha de la ?ltima modificaci?n
|
328 |
*
|
329 |
* @param string
|
330 |
*/
|
331 |
public void setModificationDate(String string) { |
332 |
modificationDate = string; |
333 |
modified = true;
|
334 |
change.firePropertyChange("", null, null); |
335 |
} |
336 |
|
337 |
/**
|
338 |
* Establece el propietario del proyecto
|
339 |
*
|
340 |
* @param string
|
341 |
*/
|
342 |
public void setOwner(String string) { |
343 |
owner = string; |
344 |
modified = true;
|
345 |
change.firePropertyChange("", null, null); |
346 |
} |
347 |
|
348 |
/**
|
349 |
* Establece el flag de modificado del proyecto
|
350 |
*
|
351 |
* @param b
|
352 |
*/
|
353 |
public void setModified(boolean b) { |
354 |
modified = b; |
355 |
} |
356 |
|
357 |
/**
|
358 |
* Obtiene el color de selecci?n que se usar? en el proyecto
|
359 |
*
|
360 |
* @return
|
361 |
*/
|
362 |
public Color getSelectionColor() { |
363 |
return selectionColor;
|
364 |
} |
365 |
|
366 |
/**
|
367 |
* Establece el color de selecci?n
|
368 |
*
|
369 |
* @param color
|
370 |
*/
|
371 |
public void setSelectionColor(Color color) { |
372 |
selectionColor = color; |
373 |
FSymbol.setSelectionColor(color); |
374 |
modified = true;
|
375 |
change.firePropertyChange("selectionColor", null, color); |
376 |
} |
377 |
|
378 |
/**
|
379 |
* Obtiene el color como un entero para su serializaci?n a XML
|
380 |
*
|
381 |
* @return
|
382 |
*/
|
383 |
public String getColor() { |
384 |
return StringUtilities.color2String(selectionColor);
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* M?todo invocado al recuperar de XML para establecer el color de
|
389 |
* seleccion del proyecto
|
390 |
*
|
391 |
* @param color Entero que representa un color
|
392 |
*/
|
393 |
public void setColor(String color) { |
394 |
modified = true;
|
395 |
selectionColor = StringUtilities.string2Color(color); |
396 |
} |
397 |
|
398 |
/* (non-Javadoc)
|
399 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
400 |
*/
|
401 |
public void propertyChange(PropertyChangeEvent evt) { |
402 |
this.modified = true; |
403 |
change.firePropertyChange(evt); |
404 |
} |
405 |
|
406 |
/**
|
407 |
* DOCUMENT ME!
|
408 |
*
|
409 |
* @param arg1
|
410 |
*/
|
411 |
public void addExtent(ProjectExtent arg1) { |
412 |
extents.add(arg1); |
413 |
modified = true;
|
414 |
change.firePropertyChange("addExtent", null, null); |
415 |
} |
416 |
|
417 |
/**
|
418 |
* DOCUMENT ME!
|
419 |
*
|
420 |
* @param arg0
|
421 |
*
|
422 |
* @return
|
423 |
*/
|
424 |
public Object removeExtent(int arg0) { |
425 |
modified = true;
|
426 |
change.firePropertyChange("delExtent", null, null); |
427 |
|
428 |
return extents.remove(arg0);
|
429 |
} |
430 |
|
431 |
/**
|
432 |
* DOCUMENT ME!
|
433 |
*
|
434 |
* @return DOCUMENT ME!
|
435 |
*/
|
436 |
public ProjectExtent[] getExtents() { |
437 |
return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]); |
438 |
} |
439 |
|
440 |
/**
|
441 |
* DOCUMENT ME!
|
442 |
*
|
443 |
* @param arg0
|
444 |
*/
|
445 |
public synchronized void addPropertyChangeListener( |
446 |
PropertyChangeListener arg0) {
|
447 |
change.addPropertyChangeListener(arg0); |
448 |
} |
449 |
|
450 |
/**
|
451 |
* DOCUMENT ME!
|
452 |
*
|
453 |
* @return
|
454 |
*/
|
455 |
public ArrayList getMaps() { |
456 |
return maps;
|
457 |
} |
458 |
|
459 |
/**
|
460 |
* DOCUMENT ME!
|
461 |
*
|
462 |
* @return
|
463 |
*/
|
464 |
public ArrayList getTables() { |
465 |
return tables;
|
466 |
} |
467 |
|
468 |
/**
|
469 |
* DOCUMENT ME!
|
470 |
*
|
471 |
* @return
|
472 |
*/
|
473 |
public ArrayList getViews() { |
474 |
return views;
|
475 |
} |
476 |
|
477 |
/**
|
478 |
* DOCUMENT ME!
|
479 |
*
|
480 |
* @return DOCUMENT ME!
|
481 |
*
|
482 |
* @throws DriverException
|
483 |
* @throws XMLException
|
484 |
*/
|
485 |
public XMLEntity getXMLEntity() throws DriverException, XMLException { |
486 |
XMLEntity xml = new XMLEntity();
|
487 |
xml.putProperty("className", this.getClass().getName()); |
488 |
xml.putProperty("VERSION", VERSION);
|
489 |
xml.putProperty("comments", comments);
|
490 |
xml.putProperty("creationDate", creationDate);
|
491 |
|
492 |
int numExtents = extents.size();
|
493 |
|
494 |
/*double[] xs = new double[size];
|
495 |
double[] ys = new double[size];
|
496 |
double[] ws = new double[size];
|
497 |
double[] hs = new double[size];
|
498 |
*/
|
499 |
xml.putProperty("numExtents", numExtents);
|
500 |
|
501 |
for (int i = 0; i < numExtents; i++) { |
502 |
/* Rectangle2D rect = (Rectangle2D) extents.get(i);
|
503 |
xs[i] = rect.getX();
|
504 |
ys[i] = rect.getY();
|
505 |
ws[i] = rect.getWidth();
|
506 |
hs[i] = rect.getHeight();
|
507 |
*/
|
508 |
xml.addChild(((ProjectExtent) extents.get(i)).getXMLEntity()); |
509 |
} |
510 |
|
511 |
// NUEVO: ESTO ESTA EN PRUEBAS. SIRVE PARA
|
512 |
// BORRAR LAS REFERENCIAS A DATASOURCES QUE HEMOS
|
513 |
// BORRADO. Hay que probar a borrarlos cuando se
|
514 |
// borra una tabla y cuando se borra una capa.
|
515 |
cleanBadReferences(); |
516 |
SourceInfo[] infos = LayerFactory.getDataSourceFactory().getDriverInfos();
|
517 |
xml.putProperty("data-source-count", infos.length);
|
518 |
|
519 |
for (int i = 0; i < infos.length; i++) { |
520 |
XMLEntity child = new XMLEntity();
|
521 |
SourceInfo di = infos[i]; |
522 |
|
523 |
if (di instanceof ObjectSourceInfo) { |
524 |
ObjectSourceInfo driver = (ObjectSourceInfo) di; |
525 |
child.putProperty("type", "sameDriverFile"); |
526 |
child.putProperty("gdbmsname", driver.name);
|
527 |
} else if (di instanceof FileSourceInfo) { |
528 |
FileSourceInfo vfdi = (FileSourceInfo) di; |
529 |
child.putProperty("type", "otherDriverFile"); |
530 |
child.putProperty("gdbmsname", vfdi.name);
|
531 |
child.putProperty("file", vfdi.file);
|
532 |
child.putProperty("driverName", vfdi.driverName);
|
533 |
} else if (di instanceof DBSourceInfo) { |
534 |
DBTableSourceInfo dbdi = (DBTableSourceInfo) di; |
535 |
child.putProperty("type", "db"); |
536 |
child.putProperty("gdbmsname", dbdi.name);
|
537 |
child.putProperty("dbms", dbdi.dbms);
|
538 |
child.putProperty("host", dbdi.host);
|
539 |
child.putProperty("port", dbdi.port);
|
540 |
child.putProperty("user", dbdi.user);
|
541 |
child.putProperty("password", dbdi.password);
|
542 |
child.putProperty("dbName", dbdi.dbName);
|
543 |
child.putProperty("tableName", dbdi.tableName);
|
544 |
child.putProperty("driverInfo", dbdi.driverName);
|
545 |
} |
546 |
|
547 |
xml.addChild(child); |
548 |
} |
549 |
|
550 |
/*
|
551 |
xml.putProperty("extentsX", xs);
|
552 |
xml.putProperty("extentsY", ys);
|
553 |
xml.putProperty("extentsW", ws);
|
554 |
xml.putProperty("extentsH", hs);
|
555 |
*/
|
556 |
xml.putProperty("numViews", views.size());
|
557 |
|
558 |
for (int i = 0; i < views.size(); i++) { |
559 |
xml.addChild(((ProjectView) views.get(i)).getXMLEntity()); |
560 |
} |
561 |
|
562 |
xml.putProperty("numMaps", maps.size());
|
563 |
|
564 |
for (int i = 0; i < maps.size(); i++) { |
565 |
xml.addChild(((ProjectMap) maps.get(i)).getXMLEntity()); |
566 |
} |
567 |
|
568 |
xml.putProperty("modificationDate", modificationDate);
|
569 |
xml.putProperty("modified", modified);
|
570 |
xml.putProperty("name", name);
|
571 |
xml.putProperty("owner", owner);
|
572 |
xml.putProperty("path", path);
|
573 |
xml.putProperty("selectionColor",
|
574 |
StringUtilities.color2String(selectionColor)); |
575 |
xml.putProperty("numTables", tables.size());
|
576 |
|
577 |
for (int i = 0; i < tables.size(); i++) { |
578 |
xml.addChild(((ProjectTable) tables.get(i)).getXMLEntity()); |
579 |
} |
580 |
|
581 |
xml.putProperty("projection", defaultProjection.getAbrev());
|
582 |
|
583 |
return xml;
|
584 |
} |
585 |
/**
|
586 |
* DOCUMENT ME!
|
587 |
*
|
588 |
* @param xml DOCUMENT ME!
|
589 |
*
|
590 |
* @return DOCUMENT ME!
|
591 |
* @throws XMLException
|
592 |
* @throws DriverException
|
593 |
* @throws DriverIOException
|
594 |
*/
|
595 |
public static Project createFromXML03(XMLEntity xml) |
596 |
throws XMLException, DriverException, DriverIOException {
|
597 |
Project p = new Project();
|
598 |
p.comments = xml.getStringProperty("comments");
|
599 |
p.creationDate = xml.getStringProperty("creationDate");
|
600 |
/*
|
601 |
double[] xs = xml.getDoubleArrayProperty("extentsX");
|
602 |
double[] ys = xml.getDoubleArrayProperty("extentsY");
|
603 |
double[] ws = xml.getDoubleArrayProperty("extentsW");
|
604 |
double[] hs = xml.getDoubleArrayProperty("extentsH");
|
605 |
*/
|
606 |
int numExtents=xml.getIntProperty("numExtents"); |
607 |
for (int i = 0; i < numExtents; i++) { |
608 |
ProjectExtent pe=ProjectExtent.createFromXML03(xml.getChild(i)); |
609 |
p.extents.add(pe); |
610 |
} |
611 |
|
612 |
int numViews = xml.getIntProperty("numViews"); |
613 |
|
614 |
for (int i = numExtents; i < numViews+numExtents; i++) { |
615 |
p.views.add(ProjectView.createFromXML03(xml.getChild(i), p)); |
616 |
} |
617 |
|
618 |
int numMaps = xml.getIntProperty("numMaps"); |
619 |
|
620 |
for (int i = numViews+numExtents; i < (numMaps + numViews+numExtents); i++) { |
621 |
p.maps.add(ProjectMap.createFromXML03(xml.getChild(i), p)); |
622 |
} |
623 |
|
624 |
p.modificationDate = xml.getStringProperty("modificationDate");
|
625 |
p.modified = xml.getBooleanProperty("modified");
|
626 |
p.name = xml.getStringProperty("name");
|
627 |
p.owner = xml.getStringProperty("owner");
|
628 |
p.path = xml.getStringProperty("path");
|
629 |
p.selectionColor = StringUtilities.string2Color(xml.getStringProperty( |
630 |
"selectionColor"));
|
631 |
|
632 |
int numTables = xml.getIntProperty("numTables"); |
633 |
|
634 |
for (int i = numExtents+numMaps + numViews; i < (numExtents+numTables + numMaps + numViews); |
635 |
i++) { |
636 |
p.tables.add(ProjectTable.createFromXML03(xml.getChild(i), p)); |
637 |
} |
638 |
String strProj = xml.getStringProperty("projection"); |
639 |
if (strProj != null) |
640 |
Project.setProjection(ProjectionPool.get(strProj)); |
641 |
|
642 |
return p;
|
643 |
} |
644 |
|
645 |
/**
|
646 |
* DOCUMENT ME!
|
647 |
*
|
648 |
* @param xml DOCUMENT ME!
|
649 |
*
|
650 |
* @return DOCUMENT ME!
|
651 |
*
|
652 |
* @throws XMLException
|
653 |
* @throws DriverException
|
654 |
* @throws DriverIOException
|
655 |
*/
|
656 |
public static Project createFromXML(XMLEntity xml) |
657 |
throws XMLException, DriverException, DriverIOException {
|
658 |
int childNumber = 0; |
659 |
Project p = new Project();
|
660 |
p.comments = xml.getStringProperty("comments");
|
661 |
p.creationDate = xml.getStringProperty("creationDate");
|
662 |
|
663 |
/*
|
664 |
double[] xs = xml.getDoubleArrayProperty("extentsX");
|
665 |
double[] ys = xml.getDoubleArrayProperty("extentsY");
|
666 |
double[] ws = xml.getDoubleArrayProperty("extentsW");
|
667 |
double[] hs = xml.getDoubleArrayProperty("extentsH");
|
668 |
*/
|
669 |
int numExtents = xml.getIntProperty("numExtents"); |
670 |
|
671 |
for (int i = 0; i < numExtents; i++) { |
672 |
ProjectExtent pe = ProjectExtent.createFromXML(xml.getChild(i)); |
673 |
p.extents.add(pe); |
674 |
} |
675 |
|
676 |
childNumber = numExtents; |
677 |
|
678 |
int numDataSources = xml.getIntProperty("data-source-count"); |
679 |
|
680 |
for (int i = childNumber; i < (childNumber + numDataSources); i++) { |
681 |
XMLEntity child = xml.getChild(i); |
682 |
|
683 |
if (child.getStringProperty("type").equals("otherDriverFile")) { |
684 |
LayerFactory.getDataSourceFactory().addFileDataSource(child.getStringProperty( |
685 |
"driverName"), child.getStringProperty("gdbmsname"), |
686 |
child.getStringProperty("file"));
|
687 |
} else if (child.getStringProperty("type").equals("sameDriverFile")) { |
688 |
/* String layerName = child.getStringProperty("layerName");
|
689 |
ProjectView vista = project.getViewByName(child.getStringProperty(
|
690 |
"viewName"));
|
691 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
|
692 |
|
693 |
modelo = ((AlphanumericData) layer).getRecordset();
|
694 |
associatedTable = (AlphanumericData) layer;
|
695 |
*/
|
696 |
} else if (child.getStringProperty("type").equals("db")) { |
697 |
LayerFactory.getDataSourceFactory().addDBDataSourceByTable(child.getStringProperty( |
698 |
"gdbmsname"), child.getStringProperty("host"), |
699 |
child.getIntProperty("port"),
|
700 |
child.getStringProperty("user"),
|
701 |
child.getStringProperty("password"),
|
702 |
child.getStringProperty("dbName"),
|
703 |
child.getStringProperty("tableName"),
|
704 |
child.getStringProperty("driverInfo"));
|
705 |
} |
706 |
} |
707 |
|
708 |
childNumber += numDataSources; |
709 |
|
710 |
int numViews = xml.getIntProperty("numViews"); |
711 |
|
712 |
for (int i = childNumber; i < (numViews + childNumber); i++) { |
713 |
p.views.add(ProjectView.createFromXML(xml.getChild(i), p)); |
714 |
} |
715 |
|
716 |
childNumber += numViews; |
717 |
|
718 |
int numMaps = xml.getIntProperty("numMaps"); |
719 |
|
720 |
for (int i = childNumber; i < (numMaps + childNumber); i++) { |
721 |
p.maps.add(ProjectMap.createFromXML(xml.getChild(i), p)); |
722 |
} |
723 |
|
724 |
childNumber += numMaps; |
725 |
p.modificationDate = xml.getStringProperty("modificationDate");
|
726 |
p.modified = xml.getBooleanProperty("modified");
|
727 |
p.name = xml.getStringProperty("name");
|
728 |
p.owner = xml.getStringProperty("owner");
|
729 |
p.path = xml.getStringProperty("path");
|
730 |
p.selectionColor = StringUtilities.string2Color(xml.getStringProperty( |
731 |
"selectionColor"));
|
732 |
|
733 |
int numTables = xml.getIntProperty("numTables"); |
734 |
|
735 |
for (int i = childNumber; i < (childNumber + numTables); i++) { |
736 |
p.tables.add(ProjectTable.createFromXML(xml.getChild(i), p)); |
737 |
} |
738 |
|
739 |
p.setLinkTable(); |
740 |
|
741 |
String strProj = xml.getStringProperty("projection"); |
742 |
|
743 |
if (strProj != null) { |
744 |
Project.setProjection(ProjectionPool.get(strProj)); |
745 |
} |
746 |
PostProcessSupport.executeCalls(); |
747 |
return p;
|
748 |
} |
749 |
|
750 |
/**
|
751 |
* Reestablece los link que ten?a cada tabla con las dem?s.
|
752 |
*/
|
753 |
public void setLinkTable() { |
754 |
ArrayList tables = getTables();
|
755 |
|
756 |
for (int i = 0; i < tables.size(); i++) { |
757 |
for (int j = 0; j < tables.size(); j++) { |
758 |
/*System.out.println("name = " +
|
759 |
((ProjectTable) tables.get(j)).getModelo().getName());
|
760 |
System.out.println("linktable = " +
|
761 |
((ProjectTable) tables.get(i)).getLinkTable());
|
762 |
*/
|
763 |
if ((((ProjectTable) tables.get(i)).getLinkTable() != null) && |
764 |
((ProjectTable) tables.get(i)).getLinkTable().equals(((ProjectTable) tables |
765 |
.get( |
766 |
j)).getModelo().getName())) { |
767 |
LinkSelectionListener lsl = new LinkSelectionListener(((ProjectTable) tables.get(
|
768 |
i)).getModelo(), |
769 |
((ProjectTable) tables.get(j)).getModelo(), |
770 |
((ProjectTable) tables.get(i)).getField1(), |
771 |
((ProjectTable) tables.get(i)).getField2()); |
772 |
((ProjectTable) tables.get(i)).getModelo() |
773 |
.addSelectionListener(lsl); |
774 |
} |
775 |
} |
776 |
} |
777 |
} |
778 |
|
779 |
/**
|
780 |
* Obtiene la vista que contiene a la capa que se pasa como par?metro
|
781 |
*
|
782 |
* @param layer Capa cuya vista se quiere obtener
|
783 |
*
|
784 |
* @return
|
785 |
*
|
786 |
* @throws RuntimeException Si la capa que se pasa como par?metro no se
|
787 |
* encuentra en ninguna vista
|
788 |
*/
|
789 |
public String getView(FLayer layer) { |
790 |
for (int v = 0; v < views.size(); v++) { |
791 |
ProjectView pView = (ProjectView) views.get(v); |
792 |
FLayers layers = pView.getMapContext().getLayers(); |
793 |
if (isView(layers,layer))return pView.getName(); |
794 |
} |
795 |
|
796 |
throw new RuntimeException("The layer is not in a view"); |
797 |
} |
798 |
public boolean isView(FLayers layers,FLayer layer) { |
799 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
800 |
if (layers.getLayer(i) instanceof FLayers){ |
801 |
return isView((FLayers)layers.getLayer(i),layer);
|
802 |
}else{
|
803 |
if (layers.getLayer(i) == layer) {
|
804 |
return true; |
805 |
} |
806 |
} |
807 |
} |
808 |
return false; |
809 |
} |
810 |
/**
|
811 |
* Devuelve la vista cuyo nombre coincide (sensible a mayusculas) con el
|
812 |
* que se pasa como par?metro. Devuelve null si no hay ninguna vista con
|
813 |
* ese nombre
|
814 |
*
|
815 |
* @param viewName Nombre de la vista que se quiere obtener
|
816 |
*
|
817 |
* @return DOCUMENT ME!
|
818 |
*/
|
819 |
public ProjectView getViewByName(String viewName) { |
820 |
Object o = getProjectElementByName(viewName, views);
|
821 |
|
822 |
if (o == null) { |
823 |
return null; |
824 |
} |
825 |
|
826 |
return (ProjectView) o;
|
827 |
} |
828 |
|
829 |
/**
|
830 |
* DOCUMENT ME!
|
831 |
*
|
832 |
* @return DOCUMENT ME!
|
833 |
*/
|
834 |
public static IProjection getProjection() { |
835 |
return defaultProjection;
|
836 |
} |
837 |
|
838 |
/**
|
839 |
* DOCUMENT ME!
|
840 |
*
|
841 |
* @param defaultProjection DOCUMENT ME!
|
842 |
*/
|
843 |
public static void setProjection(IProjection defaultProjection) { |
844 |
Project.defaultProjection = defaultProjection; |
845 |
} |
846 |
|
847 |
/**
|
848 |
* DOCUMENT ME!
|
849 |
*
|
850 |
* @param name DOCUMENT ME!
|
851 |
* @param l DOCUMENT ME!
|
852 |
*
|
853 |
* @return DOCUMENT ME!
|
854 |
*/
|
855 |
private Object getProjectElementByName(String name, ArrayList l) { |
856 |
for (Iterator iter = l.iterator(); iter.hasNext();) { |
857 |
ProjectElement elem = (ProjectElement) iter.next(); |
858 |
|
859 |
if (elem.getName().equals(name)) {
|
860 |
return elem;
|
861 |
} |
862 |
} |
863 |
|
864 |
return null; |
865 |
} |
866 |
|
867 |
/**
|
868 |
* DOCUMENT ME!
|
869 |
*
|
870 |
* @param name
|
871 |
*
|
872 |
* @return
|
873 |
*/
|
874 |
public ProjectTable getTableByName(String name) { |
875 |
Object o = getProjectElementByName(name, tables);
|
876 |
|
877 |
if (o == null) { |
878 |
return null; |
879 |
} |
880 |
|
881 |
return (ProjectTable) o;
|
882 |
} |
883 |
|
884 |
/**
|
885 |
* DOCUMENT ME!
|
886 |
*
|
887 |
* @param name
|
888 |
*
|
889 |
* @return
|
890 |
*/
|
891 |
public ProjectMap getLayoutByName(String name) { |
892 |
Object o = getProjectElementByName(name, maps);
|
893 |
|
894 |
if (o == null) { |
895 |
return null; |
896 |
} |
897 |
|
898 |
return (ProjectMap) o;
|
899 |
} |
900 |
|
901 |
public SelectableDataSource getDataSourceByLayer(FLayer layer) throws DriverException { |
902 |
ArrayList tables = getTables();
|
903 |
SelectableDataSource dataSource = null;
|
904 |
for (int i = 0; i < tables.size(); i++) { |
905 |
ProjectTable pt = (ProjectTable) tables.get(i); |
906 |
if (pt.getOriginal() == ((AlphanumericData) layer).getRecordset()){
|
907 |
dataSource = pt.getModelo(); |
908 |
break;
|
909 |
}else if (pt.getModelo() == ((AlphanumericData) layer).getRecordset()){ |
910 |
dataSource = pt.getModelo(); |
911 |
break;
|
912 |
} |
913 |
} |
914 |
|
915 |
if (dataSource == null){ |
916 |
//No se ha creado la tabla asociada al tema
|
917 |
dataSource = ((AlphanumericData) layer).getRecordset(); |
918 |
} |
919 |
|
920 |
return dataSource;
|
921 |
|
922 |
} |
923 |
|
924 |
/**
|
925 |
* Recorremos las capas y las tablas del proyecto, y creamos una lista
|
926 |
* con todos los datasources de GDBMS que estamos usando.
|
927 |
* Luego recorremos los que est?n registrados, y borramos
|
928 |
* aquellos que no est?n siendo usados, es decir, aquellos
|
929 |
* que no est?n en nuestra lista (un Hash con clave el nombre
|
930 |
* del GDBMS)
|
931 |
*
|
932 |
*/
|
933 |
private void cleanBadReferences() |
934 |
{ |
935 |
Hashtable usedDataSources = new Hashtable(); |
936 |
// Primero las tablas
|
937 |
int i, j;
|
938 |
for (i=0; i<tables.size(); i++) |
939 |
{ |
940 |
ProjectTable t = (ProjectTable) tables.get(i); |
941 |
SelectableDataSource ds = t.getModelo(); |
942 |
if (t.getOriginal() != null) |
943 |
usedDataSources.put(t.getOriginal().getName(), t.getOriginal()); |
944 |
usedDataSources.put(ds.getName(), ds); |
945 |
} |
946 |
|
947 |
// Ahora las vistas
|
948 |
try {
|
949 |
for (i=0; i<views.size(); i++) |
950 |
{ |
951 |
ProjectView pv = (ProjectView) views.get(i); |
952 |
|
953 |
FLayers lyrs = pv.getMapContext().getLayers(); |
954 |
FLayers lyrsOverview = pv.getMapOverViewContext().getLayers(); |
955 |
for (j=0; j<lyrs.getLayersCount(); j++) |
956 |
{ |
957 |
FLayer lyr = lyrs.getLayer(j); |
958 |
if (lyr instanceof FLyrVect) |
959 |
{ |
960 |
FLyrVect lyrVect = (FLyrVect) lyr; |
961 |
usedDataSources.put(lyrVect.getRecordset().getName(), lyrVect.getRecordset()); |
962 |
} |
963 |
} |
964 |
for (j=0; j<lyrsOverview.getLayersCount(); j++) |
965 |
{ |
966 |
FLayer lyr = lyrsOverview.getLayer(j); |
967 |
if (lyr instanceof FLyrVect) |
968 |
{ |
969 |
FLyrVect lyrVect = (FLyrVect) lyr; |
970 |
usedDataSources.put(lyrVect.getRecordset().getName(), lyrVect.getRecordset()); |
971 |
} |
972 |
} |
973 |
|
974 |
} // for i
|
975 |
} catch (DriverException e) {
|
976 |
// TODO Auto-generated catch block
|
977 |
e.printStackTrace(); |
978 |
} |
979 |
// Recorremos los dataSources y los borramos si no
|
980 |
// los estamos usando.
|
981 |
SourceInfo[] infos = LayerFactory.getDataSourceFactory().getDriverInfos();
|
982 |
try {
|
983 |
for (i=0; i < infos.length; i++) |
984 |
{ |
985 |
if (!usedDataSources.containsKey(infos[i].name))
|
986 |
{ |
987 |
DataSource ds;
|
988 |
ds = LayerFactory.getDataSourceFactory().createRandomDataSource(infos[i].name); |
989 |
ds.remove(); |
990 |
} |
991 |
} |
992 |
} catch (DriverLoadException e) {
|
993 |
// TODO Auto-generated catch block
|
994 |
e.printStackTrace(); |
995 |
} catch (NoSuchTableException e) {
|
996 |
// TODO Auto-generated catch block
|
997 |
e.printStackTrace(); |
998 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
999 |
// TODO Auto-generated catch block
|
1000 |
e.printStackTrace(); |
1001 |
} |
1002 |
} |
1003 |
} |