Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / file / shp / SHPDataExplorer.java @ 20049

History | View | Annotate | Download (2.42 KB)

1 19844 vcaballero
package org.gvsig.data.datastores.vectorial.file.shp;
2 19533 jmvivo
3
import java.io.File;
4
5 19907 vcaballero
import org.gvsig.data.IDataExplorerParameters;
6 19673 vcaballero
import org.gvsig.data.IDataStoreParameters;
7 20049 jmvivo
import org.gvsig.data.INewDataStoreParameters;
8 19907 vcaballero
import org.gvsig.data.datastores.vectorial.file.RemoveFileException;
9
import org.gvsig.data.datastores.vectorial.file.dbf.DBFDataExplorer;
10 19844 vcaballero
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP;
11 19673 vcaballero
import org.gvsig.data.exception.InitializeWriterException;
12 19907 vcaballero
import org.gvsig.data.exception.OpenException;
13 19673 vcaballero
import org.gvsig.data.vectorial.IFeatureType;
14 20045 jmvivo
import org.gvsig.data.vectorial.INewFeatureStoreParameters;
15 19533 jmvivo
16 19907 vcaballero
public class SHPDataExplorer extends DBFDataExplorer {
17
        protected SHPDataExplorerParameters parameters;
18 19943 vcaballero
        public static String DATASOURCE_NAME="ShpDataExplorer";
19 19533 jmvivo
20
        protected boolean isValid(File file) {
21
                if (!file.exists()){
22
                        return false;
23
                }
24
                if (!(file.getName().toLowerCase().endsWith(".shp"))){
25
                        return false;
26
                }
27
                File shx = SHP.getShxFile(file);
28
                if (!shx.exists()){
29
                        return false;
30
                }
31
                File dbf = SHP.getDbfFile(file);
32
                return super.isValid(dbf);
33
        }
34
35
36 19907 vcaballero
        public void init(IDataExplorerParameters parameters) {
37
                this.parameters = (SHPDataExplorerParameters)parameters;
38 19533 jmvivo
                this.path = this.parameters.getSource();
39
        }
40
41 19673 vcaballero
42
        public String getName() {
43
                return DATASOURCE_NAME;
44
        }
45
46 19907 vcaballero
47 20045 jmvivo
        public IDataStoreParameters add(INewFeatureStoreParameters ndsp) throws OpenException, InitializeWriterException {
48 19907 vcaballero
                IDataStoreParameters dsp=ndsp.getDataStoreParameters();
49
                IFeatureType ft=ndsp.getFeatureType();
50
                ShpFeaturesWriter.create((SHPStoreParameters)dsp,ft);
51
                return dsp;
52
        }
53
54 20049 jmvivo
        public INewDataStoreParameters createNewDataStoreParameter(IDataStoreParameters dsp) {
55 19907 vcaballero
                SHPNewStoreParameters dbfnsp=new SHPNewStoreParameters();
56
                dbfnsp.setDataStoreParameters(dsp);
57
                return dbfnsp;
58
        }
59
60
        public void remove(IDataStoreParameters dsp) throws RemoveFileException {
61
                SHPStoreParameters shpsp=(SHPStoreParameters)dsp;
62
                File shp=shpsp.getSHPFile();
63
                File dbf=shpsp.getDBFFile();
64
                File shx=shpsp.getSHXFile();
65
                if (shp.exists()) {
66
//                        shp.deleteOnExit();
67
68
                        if (!shp.delete()){
69
                                throw new RemoveFileException(shp.getName(),new Exception());
70
                        }
71
                }
72
                if (dbf.exists()) {
73
//                        dbf.deleteOnExit();
74
                        if (!dbf.delete()){
75
                                throw new RemoveFileException(dbf.getName(),new Exception());
76
                        }
77
                }
78
                if (shx.exists()) {
79
//                        shx.deleteOnExit();
80
                        if (!shx.delete()){
81
                                throw new RemoveFileException(shx.getName(),new Exception());
82
                        }
83
                }
84
        }
85 19533 jmvivo
}