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 |
package org.gvsig.data.datastores.vectorial.file.shp; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import org.gvsig.data.IDataExplorerParameters; |
6 |
import org.gvsig.data.IDataStoreParameters; |
7 |
import org.gvsig.data.INewDataStoreParameters; |
8 |
import org.gvsig.data.datastores.vectorial.file.RemoveFileException; |
9 |
import org.gvsig.data.datastores.vectorial.file.dbf.DBFDataExplorer; |
10 |
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP; |
11 |
import org.gvsig.data.exception.InitializeWriterException; |
12 |
import org.gvsig.data.exception.OpenException; |
13 |
import org.gvsig.data.vectorial.IFeatureType; |
14 |
import org.gvsig.data.vectorial.INewFeatureStoreParameters; |
15 |
|
16 |
public class SHPDataExplorer extends DBFDataExplorer { |
17 |
protected SHPDataExplorerParameters parameters;
|
18 |
public static String DATASOURCE_NAME="ShpDataExplorer"; |
19 |
|
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 |
public void init(IDataExplorerParameters parameters) { |
37 |
this.parameters = (SHPDataExplorerParameters)parameters;
|
38 |
this.path = this.parameters.getSource(); |
39 |
} |
40 |
|
41 |
|
42 |
public String getName() { |
43 |
return DATASOURCE_NAME;
|
44 |
} |
45 |
|
46 |
|
47 |
public IDataStoreParameters add(INewFeatureStoreParameters ndsp) throws OpenException, InitializeWriterException { |
48 |
IDataStoreParameters dsp=ndsp.getDataStoreParameters(); |
49 |
IFeatureType ft=ndsp.getFeatureType(); |
50 |
ShpFeaturesWriter.create((SHPStoreParameters)dsp,ft); |
51 |
return dsp;
|
52 |
} |
53 |
|
54 |
public INewDataStoreParameters createNewDataStoreParameter(IDataStoreParameters dsp) {
|
55 |
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 |
} |