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