svn-gvsig-desktop / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / file / dxf / DXFDataExplorer.java @ 20049
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.IDataExplorerParameters; |
7 |
import org.gvsig.data.IDataStoreParameters; |
8 |
import org.gvsig.data.INewDataStoreParameters; |
9 |
import org.gvsig.data.datastores.vectorial.file.AbstractDataExplorerFile; |
10 |
import org.gvsig.data.datastores.vectorial.file.RemoveFileException; |
11 |
import org.gvsig.data.datastores.vectorial.file.exception.FileNotFoundDriverException; |
12 |
import org.gvsig.data.exception.InitializeWriterException; |
13 |
import org.gvsig.data.exception.OpenException; |
14 |
import org.gvsig.data.exception.ReadException; |
15 |
import org.gvsig.data.vectorial.IFeatureType; |
16 |
import org.gvsig.data.vectorial.INewFeatureStoreParameters; |
17 |
|
18 |
public class DXFDataExplorer extends AbstractDataExplorerFile { |
19 |
public static String DATASOURCE_NAME="DXFDataSource"; |
20 |
protected DXFDataExplorerParameters parameters;
|
21 |
protected File path; |
22 |
|
23 |
|
24 |
public IDataStoreParameters[] list() throws ReadException { |
25 |
if (!this.path.exists()){ |
26 |
new FileNotFoundDriverException(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 |
IDataStoreParameters 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 |
IDataStoreParameters[] x = new IDataStoreParameters[1]; |
48 |
x[0]=dsp;
|
49 |
return (IDataStoreParameters[])fileList.toArray(x); |
50 |
} |
51 |
|
52 |
protected IDataStoreParameters newParameter(File file){ |
53 |
DXFStoreParameters param = new DXFStoreParameters();
|
54 |
param.setDXFFile(file); |
55 |
return param;
|
56 |
} |
57 |
|
58 |
protected boolean isValid(String file){ |
59 |
return this.isValid(new File(file)); |
60 |
|
61 |
} |
62 |
|
63 |
protected boolean isValid(File file){ |
64 |
if (!file.exists()){
|
65 |
return false; |
66 |
} |
67 |
return (file.getName().toLowerCase().endsWith(".dxf")); |
68 |
} |
69 |
|
70 |
public String getName() { |
71 |
return DATASOURCE_NAME;
|
72 |
} |
73 |
|
74 |
public void init(IDataExplorerParameters parameters) { |
75 |
this.parameters = (DXFDataExplorerParameters)parameters;
|
76 |
this.path = this.parameters.getSource(); |
77 |
} |
78 |
|
79 |
public boolean canCreate() { |
80 |
return true; |
81 |
} |
82 |
|
83 |
public IDataStoreParameters add(INewFeatureStoreParameters ndsp) throws OpenException, InitializeWriterException { |
84 |
IDataStoreParameters dsp=ndsp.getDataStoreParameters(); |
85 |
|
86 |
|
87 |
|
88 |
return dsp;
|
89 |
} |
90 |
|
91 |
public INewDataStoreParameters createNewDataStoreParameter(IDataStoreParameters dsp) {
|
92 |
DXFNewStoreParameters dbfnsp=new DXFNewStoreParameters();
|
93 |
dbfnsp.setDataStoreParameters(dsp); |
94 |
return dbfnsp;
|
95 |
} |
96 |
|
97 |
public void remove(IDataStoreParameters dsp) throws RemoveFileException { |
98 |
DXFStoreParameters dxfsp=(DXFStoreParameters)dsp; |
99 |
File f=dxfsp.getDXFFile();
|
100 |
if (f.exists()) {
|
101 |
if (!f.delete()){
|
102 |
throw new RemoveFileException(this.getName(),new Exception()); |
103 |
} |
104 |
} |
105 |
|
106 |
} |
107 |
|
108 |
public IFeatureType[] getFeatureTypes(IDataStoreParameters dsp) throws ReadException { |
109 |
return new IFeatureType[] {DXFStore.newFeatureType()}; |
110 |
} |
111 |
} |