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 |
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.IFileStoreParameters; |
9 |
import org.gvsig.data.datastores.vectorial.file.dbf.DBFDataExplorer; |
10 |
import org.gvsig.data.datastores.vectorial.file.exception.RemoveFileException; |
11 |
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP; |
12 |
import org.gvsig.data.exception.InitializeException; |
13 |
import org.gvsig.data.exception.WriteException; |
14 |
import org.gvsig.data.vectorial.IFeatureType; |
15 |
import org.gvsig.data.vectorial.INewFeatureStoreParameters; |
16 |
|
17 |
public class SHPDataExplorer extends DBFDataExplorer { |
18 |
protected SHPDataExplorerParameters parameters;
|
19 |
public static String DATASOURCE_NAME="ShpDataExplorer"; |
20 |
|
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 |
public void init(IDataExplorerParameters parameters) { |
38 |
this.parameters = (SHPDataExplorerParameters)parameters;
|
39 |
this.path = this.parameters.getSource(); |
40 |
} |
41 |
|
42 |
|
43 |
public String getName() { |
44 |
return DATASOURCE_NAME;
|
45 |
} |
46 |
|
47 |
|
48 |
public IDataStoreParameters add(INewFeatureStoreParameters ndsp) throws WriteException, InitializeException { |
49 |
IDataStoreParameters dsp=ndsp.getDataStoreParameters(); |
50 |
IFeatureType ft=ndsp.getFeatureType(); |
51 |
ShpFeaturesWriter.create((SHPStoreParameters)dsp,ft); |
52 |
return dsp;
|
53 |
} |
54 |
|
55 |
public INewDataStoreParameters createNewDataStoreParameter() {
|
56 |
SHPNewStoreParameters dbfnsp=new SHPNewStoreParameters();
|
57 |
dbfnsp.init(this.newParameter());
|
58 |
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 |
|
87 |
protected IFileStoreParameters newParameter(){
|
88 |
return new SHPStoreParameters(); |
89 |
} |
90 |
} |