Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / shp / SHPStoreParameters.java @ 25789

History | View | Annotate | Download (4.64 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

    
28
package org.gvsig.fmap.dal.store.shp;
29

    
30
import java.io.File;
31

    
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters;
34
import org.gvsig.fmap.dal.store.shp.utils.SHP;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DelegatedDynObject;
37
import org.gvsig.tools.dynobject.DynClass;
38
import org.gvsig.tools.dynobject.DynField;
39
import org.gvsig.tools.dynobject.DynObjectManager;
40
import org.gvsig.tools.exception.NotYetImplemented;
41
import org.gvsig.tools.persistence.PersistenceException;
42
import org.gvsig.tools.persistence.PersistentState;
43

    
44
public class SHPStoreParameters extends DBFStoreParameters {
45

    
46
    public static final String DYNCLASS_NAME = "SHPStoreParameters";
47

    
48
        private static final String FIELD_SHXFILENAME = "shxfilename";
49
    private static final String FIELD_SHPFILENAME = "shpfilename";
50

    
51
    protected static DynClass DYNCLASS = null;
52

    
53
    protected void initialize() {
54
                this.delegatedDynObjet = (DelegatedDynObject) ToolsLocator
55
                                .getDynObjectManager()
56
                                .createDynObject(DYNCLASS);
57
        }
58

    
59
        public String getDataStoreName() {
60
                return SHPStoreProvider.NAME;
61
        }
62

    
63
        public boolean isValid() {
64
                return super.isValid() && (this.getSHPFileName() != null);
65
        }
66

    
67
        public File getFile() {
68
                return new File(this.getSHPFileName());
69
        }
70

    
71
        public void setFile(File aFile) {
72
                this.setSHPFile(aFile);
73
        }
74

    
75
        public String getSHPFileName() {
76
                return (String) this.getDynValue(FIELD_SHPFILENAME);
77
        }
78

    
79
        public File getSHPFile() {
80
                return new File((String) this.getDynValue(FIELD_SHPFILENAME));
81
        }
82

    
83
        public void setSHPFile(File aFile) {
84
                this.setDynValue(FIELD_SHPFILENAME, aFile.getPath());
85
                if (this.getDBFFileName() == null){
86
                        this.setDBFFile(SHP.getDbfFile(aFile));
87
                }
88
                if (this.getSHXFileName() == null) {
89
                        this.setSHXFile(SHP.getShxFile(aFile));
90
                }
91
        }
92

    
93
        public void setSHPFileName(String aFileName) {
94
                this.setDynValue(FIELD_SHPFILENAME, aFileName);
95
                if (this.getDBFFileName() == null) {
96
                        this.setDBFFile(SHP.getDbfFile(new File(aFileName)));
97
                }
98
                if (this.getSHXFileName() == null) {
99
                        this.setSHXFile(SHP.getShxFile(new File(aFileName)));
100
                }
101
        }
102

    
103
        public String getSHXFileName() {
104
                return (String) this.getDynValue(FIELD_SHXFILENAME);
105
        }
106

    
107
        public File getSHXFile() {
108
                return new File((String) this.getDynValue(FIELD_SHXFILENAME));
109
        }
110
        public void setSHXFile(File aFile) {
111
                this.setDynValue(FIELD_SHXFILENAME, aFile.getPath());
112
        }
113

    
114
        public void setSHXFileName(String aFileName) {
115
                this.setDynValue(FIELD_SHXFILENAME, aFileName);
116
        }
117

    
118

    
119

    
120
        public String getDescription() {
121
                return SHPStoreProvider.DESCRIPTION;
122
        }
123

    
124
        public void getState(PersistentState arg0) throws PersistenceException {
125
                // TODO Auto-generated method stub
126
                throw new NotYetImplemented();
127
        }
128

    
129
        public void setState(PersistentState state) throws PersistenceException {
130
                // TODO Auto-generated method stub
131
                super.setState(state);
132
                throw new NotYetImplemented();
133
        }
134

    
135
    protected static void registerDynClass() {
136
        DynObjectManager dynman = ToolsLocator.getDynObjectManager();
137
        DynClass dynClass;
138
        DynField field;
139
        if (DYNCLASS == null) {
140
                DynClass dbfDynClass = DBFStoreParameters.DYNCLASS;
141
                        dynClass = dynman.add(DYNCLASS_NAME);
142

    
143
            field = dynClass.addDynField(FIELD_SHPFILENAME);
144
            field.setDescription("SHP file name");
145
            field.setType(DataTypes.STRING);
146
            field.setMandatory(true);
147

    
148
            field = dynClass.addDynField(FIELD_SHXFILENAME);
149
            field.setDescription("SHX file name");
150
            field.setType(DataTypes.STRING);
151
            field.setMandatory(true);
152

    
153
            // The SHP store parameters extend the DBF store parameters
154
            dynClass.extend(dbfDynClass);
155

    
156
            DYNCLASS = dynClass;
157
        }
158
    }
159
}