Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / dgn / DGNDataExplorer.java @ 20971

History | View | Annotate | Download (2.12 KB)

1
package org.gvsig.data.datastores.vectorial.file.dgn;
2

    
3
import java.io.File;
4
import java.util.ArrayList;
5

    
6
import org.gvsig.data.DataException;
7
import org.gvsig.data.IDataExplorerParameters;
8
import org.gvsig.data.IDataStoreParameters;
9
import org.gvsig.data.ReadException;
10
import org.gvsig.data.datastores.vectorial.file.FileExplorer;
11
import org.gvsig.data.datastores.vectorial.file.FileNotFoundException;
12
import org.gvsig.data.vectorial.IFeatureType;
13

    
14
public class DGNDataExplorer extends FileExplorer {
15

    
16
    public static String DATASOURCE_NAME="DGNDataExplorer";
17

    
18
        protected DGNDataExplorerParameters parameters;
19
        protected File path;
20

    
21

    
22
        public IDataStoreParameters[] list() throws ReadException {
23
                if (!this.path.exists()){
24
                        new FileNotFoundException(this.getName()+": Path not found '"+this.path+"'",new Exception());
25
                }
26
//                DataManager dsm=DataManager.getManager();
27

    
28
                String files[] = this.path.list();
29
                int i;
30
                File theFile;
31
                ArrayList fileList = new ArrayList();
32
                IDataStoreParameters dsp = null;
33

    
34
                for (i=0;i<files.length;i++){
35
                        theFile = new File(this.path,files[i]);
36

    
37
                        if (this.isValid(theFile)){
38
                                dsp= this.newParameter(theFile);
39

    
40

    
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
                DGNStoreParameters param = new DGNStoreParameters();
54
                param.setFile(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(".dgn"));
68
        }
69

    
70
        public String getName() {
71
                return DATASOURCE_NAME;
72
        }
73

    
74
        public void init(IDataExplorerParameters parameters) {
75
                this.parameters = (DGNDataExplorerParameters)parameters;
76
                this.path = this.parameters.getSource();
77
        }
78

    
79
        public IFeatureType[] getFeatureTypes(IDataStoreParameters dsp) throws ReadException {
80
                try {
81
                        return new IFeatureType[] {DGNStore.newFeatureType()};
82
                } catch (DataException e) {
83
                        throw new ReadException(this.getName(),e);
84
                }
85
        }
86

    
87

    
88

    
89
}