Statistics
| Revision:

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

History | View | Annotate | Download (3.45 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.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.IFileStoreParameters;
11
import org.gvsig.data.datastores.vectorial.file.exception.FileNotFoundException;
12
import org.gvsig.data.datastores.vectorial.file.exception.RemoveFileException;
13
import org.gvsig.data.exception.InitializeException;
14
import org.gvsig.data.exception.ReadException;
15
import org.gvsig.data.exception.WriteException;
16
import org.gvsig.data.vectorial.IFeatureStore;
17
import org.gvsig.data.vectorial.IFeatureType;
18
import org.gvsig.data.vectorial.INewFeatureStoreParameters;
19

    
20
public class DBFDataExplorer extends FileExplorer {
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 FileNotFoundException(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

    
44
                        if (this.isValid(theFile)){
45
                                dsp= this.newParameter(theFile);
46

    
47

    
48
//                                dsp=dsm.createDataStoreParameters(DBFStore.DATASTORE_NAME);
49

    
50
//                                ((IDriverStoreParameters)dsp).setDriverParameters(param);
51

    
52
                                fileList.add(dsp);
53

    
54
                        }
55

    
56

    
57
                }
58
                IDataStoreParameters[] x = new IDataStoreParameters[1];
59
                x[0]=dsp;
60
                return (IDataStoreParameters[])fileList.toArray(x);
61
        }
62

    
63
        protected IFileStoreParameters newParameter(){
64
                return new DBFStoreParameters();
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(IDataExplorerParameters 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 IDataStoreParameters add(INewFeatureStoreParameters ndsp) throws InitializeException, WriteException {
98
                IDataStoreParameters dsp=ndsp.getDataStoreParameters();
99
                IFeatureType ft=ndsp.getFeatureType();
100
                DBFFeaturesWriter.create((DBFStoreParameters)dsp,ft);
101
                return dsp;
102
        }
103

    
104
        public INewDataStoreParameters createNewDataStoreParameter() {
105

    
106
                DBFNewStoreParameters dbfnsp=new DBFNewStoreParameters();
107
                dbfnsp.init(this.newParameter());
108
                return dbfnsp;
109
        }
110

    
111
        public void remove(IDataStoreParameters dsp) throws RemoveFileException {
112
                DBFStoreParameters dbfsp=(DBFStoreParameters)dsp;
113
                File f=dbfsp.getFile();
114
                if (f.exists()) {
115
                        if (!f.delete()){
116
                                throw new RemoveFileException(this.getName(),new Exception());
117
                        }
118
                }
119

    
120
        }
121

    
122
        public IFeatureType[] getFeatureTypes(IDataStoreParameters dsp) throws ReadException {
123
                IFeatureStore fs  = (IFeatureStore)this.createDataStore(dsp);
124

    
125
                return new IFeatureType[] {fs.getDefaultFeatureType()};
126
        }
127
}