svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_mobile_shp_driver / src-file / org / gvsig / data / datastores / vectorial / file / dbf / DBFDataExplorer.java @ 21865
History | View | Annotate | Download (3.6 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.dbf; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.gvsig.data.DataException; |
7 |
import org.gvsig.data.DataExplorerParameters; |
8 |
import org.gvsig.data.DataStoreParameters; |
9 |
import org.gvsig.data.NewDataStoreParameters; |
10 |
import org.gvsig.data.InitializeException; |
11 |
import org.gvsig.data.ReadException; |
12 |
import org.gvsig.data.WriteException; |
13 |
import org.gvsig.data.datastores.vectorial.file.AbstractDataExplorerFile; |
14 |
import org.gvsig.data.datastores.vectorial.file.IFileStoreParameters; |
15 |
import org.gvsig.data.datastores.vectorial.file.exception.FileNotFoundException; |
16 |
import org.gvsig.data.datastores.vectorial.file.exception.RemoveFileException; |
17 |
import org.gvsig.data.vectorial.FeatureStore; |
18 |
import org.gvsig.data.vectorial.FeatureType; |
19 |
import org.gvsig.data.vectorial.NewFeatureStoreParameters; |
20 |
|
21 |
public class DBFDataExplorer extends AbstractDataExplorerFile { |
22 |
|
23 |
public static String DATASOURCE_NAME = "DBFDataExplorer"; |
24 |
|
25 |
protected DBFDataExplorerParameters parameters;
|
26 |
|
27 |
protected File path; |
28 |
|
29 |
public DataStoreParameters[] list() throws ReadException { |
30 |
if (!this.path.exists()) { |
31 |
new FileNotFoundException(this.getName() + ": Path not found '" |
32 |
+ this.path + "'", new Exception()); |
33 |
} |
34 |
// DataManager dsm=DataManager.getManager();
|
35 |
|
36 |
String files[] = this.path.list(); |
37 |
int i;
|
38 |
File theFile;
|
39 |
ArrayList fileList = new ArrayList(); |
40 |
DataStoreParameters dsp = null;
|
41 |
|
42 |
for (i = 0; i < files.length; i++) { |
43 |
theFile = new File(this.path, files[i]); |
44 |
|
45 |
if (this.isValid(theFile)) { |
46 |
dsp = this.newParameter(theFile);
|
47 |
|
48 |
// dsp=dsm.createDataStoreParameters(DBFStore.DATASTORE_NAME);
|
49 |
|
50 |
// ((IDriverStoreParameters)dsp).setDriverParameters(param);
|
51 |
|
52 |
fileList.add(dsp); |
53 |
|
54 |
} |
55 |
|
56 |
} |
57 |
DataStoreParameters[] x = new DataStoreParameters[1]; |
58 |
x[0] = dsp;
|
59 |
return (DataStoreParameters[]) fileList.toArray(x); |
60 |
} |
61 |
|
62 |
protected IFileStoreParameters newParameter() {
|
63 |
return new DBFStoreParameters(); |
64 |
} |
65 |
|
66 |
protected IFileStoreParameters newParameter(File file) { |
67 |
IFileStoreParameters param = this.newParameter();
|
68 |
param.setFile(file); |
69 |
return param;
|
70 |
} |
71 |
|
72 |
protected boolean isValid(String file) { |
73 |
return this.isValid(new File(file)); |
74 |
|
75 |
} |
76 |
|
77 |
protected boolean isValid(File file) { |
78 |
if (!file.exists()) {
|
79 |
return false; |
80 |
} |
81 |
return (file.getName().toLowerCase().endsWith(".dbf")); |
82 |
} |
83 |
|
84 |
public String getName() { |
85 |
return DATASOURCE_NAME;
|
86 |
} |
87 |
|
88 |
public void init(DataExplorerParameters parameters) { |
89 |
this.parameters = (DBFDataExplorerParameters) parameters;
|
90 |
this.path = this.parameters.getSource(); |
91 |
} |
92 |
|
93 |
public boolean canCreate() { |
94 |
return true; |
95 |
} |
96 |
|
97 |
public DataStoreParameters add(NewFeatureStoreParameters ndsp)
|
98 |
throws InitializeException, WriteException {
|
99 |
DataStoreParameters dsp = ndsp.getDataStoreParameters(); |
100 |
FeatureType ft = ndsp.getFeatureType(); |
101 |
DBFFeaturesWriter.create((DBFStoreParameters) dsp, ft); |
102 |
return dsp;
|
103 |
} |
104 |
|
105 |
public NewDataStoreParameters createNewDataStoreParameter() {
|
106 |
|
107 |
DBFNewStoreParameters dbfnsp = new DBFNewStoreParameters();
|
108 |
dbfnsp.init(this.newParameter());
|
109 |
return dbfnsp;
|
110 |
} |
111 |
|
112 |
public void remove(DataStoreParameters dsp) throws RemoveFileException { |
113 |
DBFStoreParameters dbfsp = (DBFStoreParameters) dsp; |
114 |
File f = dbfsp.getDBFFile();
|
115 |
if (f.exists()) {
|
116 |
if (!f.delete()) {
|
117 |
throw new RemoveFileException(this.getName(), new Exception()); |
118 |
} |
119 |
} |
120 |
|
121 |
} |
122 |
|
123 |
public FeatureType[] getFeatureTypes(DataStoreParameters dsp) |
124 |
throws ReadException {
|
125 |
FeatureStore fs = (FeatureStore) this.createDataStore(dsp);
|
126 |
|
127 |
return new FeatureType[] { fs.getDefaultFeatureType() }; |
128 |
} |
129 |
|
130 |
public void dispose() throws DataException { |
131 |
// TODO Auto-generated method stub
|
132 |
|
133 |
} |
134 |
} |