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