Revision 3060 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/Project.java

View differences:

Project.java
48 48
import java.text.DateFormat;
49 49
import java.util.ArrayList;
50 50
import java.util.Date;
51
import java.util.Hashtable;
51 52
import java.util.Iterator;
52 53

  
53 54
import org.cresques.cts.IProjection;
54 55
import org.cresques.cts.ProjectionPool;
55 56

  
57
import com.hardcode.driverManager.DriverLoadException;
58
import com.hardcode.gdbms.engine.data.DataSource;
59
import com.hardcode.gdbms.engine.data.NoSuchTableException;
56 60
import com.hardcode.gdbms.engine.data.SourceInfo;
57 61
import com.hardcode.gdbms.engine.data.db.DBSourceInfo;
58 62
import com.hardcode.gdbms.engine.data.db.DBTableSourceInfo;
......
63 67
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
64 68
import com.iver.cit.gvsig.fmap.layers.FLayer;
65 69
import com.iver.cit.gvsig.fmap.layers.FLayers;
70
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
66 71
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
67 72
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
68 73
import com.iver.cit.gvsig.fmap.layers.XMLException;
......
79 84
 * @author Fernando Gonz?lez Cort?s
80 85
 */
81 86
public class Project implements Serializable, PropertyChangeListener {
82
	public static String VERSION = "0.3-GISPLANET";
87
	public static String VERSION = "0.5";
83 88
	static private IProjection defaultProjection = ProjectionPool.get(
84 89
			"EPSG:23030");
85 90
	private PropertyChangeSupport change;
......
503 508
			xml.addChild(((ProjectExtent) extents.get(i)).getXMLEntity());
504 509
		}
505 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();
506 516
		SourceInfo[] infos = LayerFactory.getDataSourceFactory().getDriverInfos();
507 517
		xml.putProperty("data-source-count", infos.length);
508 518

  
......
910 920
        return dataSource;
911 921
        
912 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
    }
913 1003
}

Also available in: Unified diff