root / branches / Mobile_Compatible_Hito_1 / libFMap / src-file / org / gvsig / data / datastores / vectorial / file / shp / SHPDataExplorer.java @ 21606
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 |
|
9 |
import org.gvsig.data.datastores.vectorial.file.IFileStoreParameters; |
10 |
import org.gvsig.data.datastores.vectorial.file.dbf.DBFDataExplorer; |
11 |
import org.gvsig.data.datastores.vectorial.file.exception.RemoveFileException; |
12 |
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP; |
13 |
import org.gvsig.data.exception.InitializeException; |
14 |
import org.gvsig.data.exception.WriteException; |
15 |
import org.gvsig.data.vectorial.IFeatureType; |
16 |
import org.gvsig.data.vectorial.INewFeatureStoreParameters; |
17 |
|
18 |
public class SHPDataExplorer extends DBFDataExplorer { |
19 |
protected SHPDataExplorerParameters parameters;
|
20 |
public static String DATASOURCE_NAME="ShpDataExplorer"; |
21 |
|
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 |
public void init(IDataExplorerParameters parameters) { |
39 |
this.parameters = (SHPDataExplorerParameters)parameters;
|
40 |
this.path = this.parameters.getSource(); |
41 |
} |
42 |
|
43 |
|
44 |
public String getName() { |
45 |
return DATASOURCE_NAME;
|
46 |
} |
47 |
|
48 |
|
49 |
public IDataStoreParameters add(INewFeatureStoreParameters ndsp) throws WriteException, InitializeException { |
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() {
|
57 |
SHPNewStoreParameters dbfnsp=new SHPNewStoreParameters();
|
58 |
dbfnsp.init(this.newParameter());
|
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 |
|
88 |
protected IFileStoreParameters newParameter(){
|
89 |
return new SHPStoreParameters(); |
90 |
} |
91 |
} |