svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / dxf / DXFDataExplorer.java @ 21602
History | View | Annotate | Download (3.03 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.dxf; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.gvsig.data.DataExplorerParameters; |
7 |
import org.gvsig.data.DataStoreParameters; |
8 |
import org.gvsig.data.NewDataStoreParameters; |
9 |
import org.gvsig.data.InitializeException; |
10 |
import org.gvsig.data.ReadException; |
11 |
import org.gvsig.data.datastores.vectorial.file.FileExplorer; |
12 |
import org.gvsig.data.datastores.vectorial.file.FileNotFoundException; |
13 |
import org.gvsig.data.datastores.vectorial.file.RemoveFileException; |
14 |
import org.gvsig.data.vectorial.FeatureType; |
15 |
import org.gvsig.data.vectorial.InitializeWriterException; |
16 |
import org.gvsig.data.vectorial.NewFeatureStoreParameters; |
17 |
|
18 |
public class DXFDataExplorer extends FileExplorer { |
19 |
public static String DATASOURCE_NAME="DXFDataSource"; |
20 |
protected DXFDataExplorerParameters parameters;
|
21 |
protected File path; |
22 |
|
23 |
|
24 |
public DataStoreParameters[] list() throws ReadException { |
25 |
if (!this.path.exists()){ |
26 |
new FileNotFoundException(this.getName()+": Path not found '"+this.path+"'",new Exception()); |
27 |
} |
28 |
// DataManager dsm=DataManager.getManager();
|
29 |
|
30 |
String files[] = this.path.list(); |
31 |
int i;
|
32 |
File theFile;
|
33 |
ArrayList fileList = new ArrayList(); |
34 |
DataStoreParameters dsp = null;
|
35 |
|
36 |
for (i=0;i<files.length;i++){ |
37 |
theFile = new File(this.path,files[i]); |
38 |
|
39 |
if (this.isValid(theFile)){ |
40 |
dsp= this.newParameter(theFile);
|
41 |
fileList.add(dsp); |
42 |
|
43 |
} |
44 |
|
45 |
|
46 |
} |
47 |
DataStoreParameters[] x = new DataStoreParameters[1]; |
48 |
x[0]=dsp;
|
49 |
return (DataStoreParameters[])fileList.toArray(x); |
50 |
} |
51 |
|
52 |
protected DataStoreParameters newParameter(){
|
53 |
return new DXFStoreParameters(); |
54 |
} |
55 |
|
56 |
protected DataStoreParameters newParameter(File file){ |
57 |
DXFStoreParameters param = (DXFStoreParameters) this.newParameter();
|
58 |
param.setFile(file); |
59 |
return param;
|
60 |
} |
61 |
|
62 |
protected boolean isValid(String file){ |
63 |
return this.isValid(new File(file)); |
64 |
|
65 |
} |
66 |
|
67 |
protected boolean isValid(File file){ |
68 |
if (!file.exists()){
|
69 |
return false; |
70 |
} |
71 |
return (file.getName().toLowerCase().endsWith(".dxf")); |
72 |
} |
73 |
|
74 |
public String getName() { |
75 |
return DATASOURCE_NAME;
|
76 |
} |
77 |
|
78 |
public void init(DataExplorerParameters parameters) { |
79 |
this.parameters = (DXFDataExplorerParameters)parameters;
|
80 |
this.path = this.parameters.getSource(); |
81 |
} |
82 |
|
83 |
public boolean canCreate() { |
84 |
return true; |
85 |
} |
86 |
|
87 |
public DataStoreParameters add(NewFeatureStoreParameters ndsp) throws InitializeWriterException, InitializeException { |
88 |
DataStoreParameters dsp=ndsp.getDataStoreParameters(); |
89 |
|
90 |
|
91 |
|
92 |
return dsp;
|
93 |
} |
94 |
|
95 |
public NewDataStoreParameters createNewDataStoreParameter() {
|
96 |
DXFNewStoreParameters dbfnsp=new DXFNewStoreParameters();
|
97 |
dbfnsp.init(this.newParameter());
|
98 |
return dbfnsp;
|
99 |
} |
100 |
|
101 |
public void remove(DataStoreParameters dsp) throws RemoveFileException { |
102 |
DXFStoreParameters dxfsp=(DXFStoreParameters)dsp; |
103 |
File f=dxfsp.getFile();
|
104 |
if (f.exists()) {
|
105 |
if (!f.delete()){
|
106 |
throw new RemoveFileException(this.getName(),new Exception()); |
107 |
} |
108 |
} |
109 |
|
110 |
} |
111 |
|
112 |
public FeatureType[] getFeatureTypes(DataStoreParameters dsp) throws ReadException { |
113 |
return new FeatureType[] {DXFStore.newFeatureType()}; |
114 |
} |
115 |
} |