Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / dxf / DXFDataExplorer.java @ 20744

History | View | Annotate | Download (3.08 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.FileExplorer;
10
import org.gvsig.data.datastores.vectorial.file.exception.FileNotFoundException;
11
import org.gvsig.data.datastores.vectorial.file.exception.RemoveFileException;
12
import org.gvsig.data.exception.InitializeException;
13
import org.gvsig.data.exception.InitializeWriterException;
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 FileExplorer {
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 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
                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(){
53
                return new DXFStoreParameters();
54
        }
55

    
56
        protected IDataStoreParameters 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(IDataExplorerParameters 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 IDataStoreParameters add(INewFeatureStoreParameters ndsp) throws InitializeWriterException, InitializeException {
88
                IDataStoreParameters dsp=ndsp.getDataStoreParameters();
89

    
90

    
91

    
92
                return dsp;
93
        }
94

    
95
        public INewDataStoreParameters createNewDataStoreParameter() {
96
                DXFNewStoreParameters dbfnsp=new DXFNewStoreParameters();
97
                dbfnsp.init(this.newParameter());
98
                return dbfnsp;
99
        }
100

    
101
        public void remove(IDataStoreParameters 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 IFeatureType[] getFeatureTypes(IDataStoreParameters dsp) throws ReadException {
113
                return new IFeatureType[] {DXFStore.newFeatureType()};
114
        }
115
}