svn-gvsig-desktop / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / file / dbf / DBFDataExplorer.java @ 20033
History | View | Annotate | Download (3.18 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.DataManager; |
7 |
import org.gvsig.data.IDataExplorerParameters; |
8 |
import org.gvsig.data.IDataStore; |
9 |
import org.gvsig.data.IDataStoreParameters; |
10 |
import org.gvsig.data.datastores.vectorial.file.AbstractDataExplorerFile; |
11 |
import org.gvsig.data.datastores.vectorial.file.RemoveFileException; |
12 |
import org.gvsig.data.datastores.vectorial.file.exception.FileNotFoundDriverException; |
13 |
import org.gvsig.data.exception.InitializeException; |
14 |
import org.gvsig.data.exception.InitializeWriterException; |
15 |
import org.gvsig.data.exception.OpenException; |
16 |
import org.gvsig.data.exception.ReadException; |
17 |
import org.gvsig.data.vectorial.IFeatureType; |
18 |
import org.gvsig.data.vectorial.INewDataStoreParameters; |
19 |
|
20 |
public class DBFDataExplorer extends AbstractDataExplorerFile { |
21 |
|
22 |
public static String DATASOURCE_NAME="DBFDataExplorer"; |
23 |
|
24 |
protected DBFDataExplorerParameters parameters;
|
25 |
protected File path; |
26 |
|
27 |
|
28 |
public IDataStoreParameters[] list() throws ReadException { |
29 |
if (!this.path.exists()){ |
30 |
new FileNotFoundDriverException(this.getName()+": Path not found '"+this.path+"'",new Exception()); |
31 |
} |
32 |
// DataManager dsm=DataManager.getManager();
|
33 |
|
34 |
String files[] = this.path.list(); |
35 |
int i;
|
36 |
File theFile;
|
37 |
ArrayList fileList = new ArrayList(); |
38 |
IDataStoreParameters dsp = null;
|
39 |
|
40 |
for (i=0;i<files.length;i++){ |
41 |
theFile = new File(this.path,files[i]); |
42 |
|
43 |
if (this.isValid(theFile)){ |
44 |
dsp= this.newParameter(theFile);
|
45 |
|
46 |
|
47 |
// dsp=dsm.createDataStoreParameters(DBFStore.DATASTORE_NAME);
|
48 |
|
49 |
// ((IDriverStoreParameters)dsp).setDriverParameters(param);
|
50 |
|
51 |
fileList.add(dsp); |
52 |
|
53 |
} |
54 |
|
55 |
|
56 |
} |
57 |
IDataStoreParameters[] x = new IDataStoreParameters[1]; |
58 |
x[0]=dsp;
|
59 |
return (IDataStoreParameters[])fileList.toArray(x); |
60 |
} |
61 |
|
62 |
protected IDataStoreParameters newParameter(File file){ |
63 |
DBFStoreParameters param = new DBFStoreParameters();
|
64 |
param.setDBFFile(file); |
65 |
return param;
|
66 |
} |
67 |
|
68 |
protected boolean isValid(String file){ |
69 |
return this.isValid(new File(file)); |
70 |
|
71 |
} |
72 |
|
73 |
protected boolean isValid(File file){ |
74 |
if (!file.exists()){
|
75 |
return false; |
76 |
} |
77 |
return (file.getName().toLowerCase().endsWith(".dbf")); |
78 |
} |
79 |
|
80 |
public String getName() { |
81 |
return DATASOURCE_NAME;
|
82 |
} |
83 |
|
84 |
public void init(IDataExplorerParameters parameters) { |
85 |
this.parameters = (DBFDataExplorerParameters)parameters;
|
86 |
this.path = this.parameters.getSource(); |
87 |
} |
88 |
|
89 |
public boolean canCreate() { |
90 |
return true; |
91 |
} |
92 |
|
93 |
public IDataStoreParameters add(INewDataStoreParameters ndsp) throws OpenException, InitializeWriterException { |
94 |
IDataStoreParameters dsp=ndsp.getDataStoreParameters(); |
95 |
IFeatureType ft=ndsp.getFeatureType(); |
96 |
DBFFeaturesWriter.create((DBFStoreParameters)dsp,ft); |
97 |
return dsp;
|
98 |
} |
99 |
|
100 |
public INewDataStoreParameters createNewDataStoreParameter(IDataStoreParameters dsp) {
|
101 |
DBFNewStoreParameters dbfnsp=new DBFNewStoreParameters();
|
102 |
dbfnsp.setDataStoreParameters(dsp); |
103 |
return dbfnsp;
|
104 |
} |
105 |
|
106 |
public void remove(IDataStoreParameters dsp) throws RemoveFileException { |
107 |
DBFStoreParameters dbfsp=(DBFStoreParameters)dsp; |
108 |
File f=dbfsp.getDBFFile();
|
109 |
if (f.exists()) {
|
110 |
if (!f.delete()){
|
111 |
throw new RemoveFileException(this.getName(),new Exception()); |
112 |
} |
113 |
} |
114 |
|
115 |
} |
116 |
} |