Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / main / java / org / gvsig / fmap / dal / store / shp / SHPStoreParameters.java @ 40596

History | View | Annotate | Download (3.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.fmap.dal.store.shp;
26

    
27
import java.io.File;
28

    
29
import org.cresques.cts.IProjection;
30
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
31
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters;
32
import org.gvsig.fmap.dal.store.shp.utils.SHP;
33

    
34
public class SHPStoreParameters extends DBFStoreParameters {
35

    
36
    public static final String PARAMETERS_DEFINITION_NAME = "SHPStoreParameters";
37

    
38
        private static final String SHXFILE_PARAMTER_NAME = "shxfile";
39
    private static final String SHPFILE_PARAMTER_NAME = "shpfile";
40
        private static final String CRS_PARAMTER_NAME = "CRS";
41

    
42
        public SHPStoreParameters() {
43
                this(PARAMETERS_DEFINITION_NAME);
44
        }
45

    
46
        @Override
47
        public void validate() throws ValidateDataParametersException {
48
                fixParameters();
49
                super.validate();
50
        }
51
        
52
        public void fixParameters() {
53
                File file = this.getSHPFile();
54
                if( file!=null ) {
55
                        if (this.getDBFFile() == null){
56
                                this.setDBFFile(SHP.getDbfFile(file));
57
                        }
58
                        if (this.getSHXFile() == null) {
59
                                this.setSHXFile(SHP.getShxFile(file));
60
                        }
61
                }
62
        }
63
        
64
        public SHPStoreParameters(String parametersDefinitionName) {
65
                super(parametersDefinitionName, SHPStoreProvider.NAME);
66
        }
67

    
68
        public boolean isValid() {
69
                return super.isValid() && (this.getSHPFileName() != null);
70
        }
71

    
72
        public File getFile() {
73
                return this.getSHPFile();
74
        }
75

    
76
        public void setFile(File file) {
77
                this.setSHPFile(file);
78
        }
79
        public void setFile(String fileName) {
80
                this.setSHPFile(fileName);
81
        }
82
        
83
        
84
        public String getSHPFileName() {
85
                if( this.getSHPFile()==null ) {
86
                        return null;
87
                }
88
                return this.getSHPFile().getAbsolutePath();
89
        }
90

    
91
        public File getSHPFile() {
92
                return (File) this.getDynValue(SHPFILE_PARAMTER_NAME);
93
        }
94

    
95
        public void setSHPFile(File file) {
96
                this.setDynValue(SHPFILE_PARAMTER_NAME, file);
97
                if (this.getDBFFile() == null){
98
                        this.setDBFFile(SHP.getDbfFile(file));
99
                }
100
                if (this.getSHXFile() == null) {
101
                        this.setSHXFile(SHP.getShxFile(file));
102
                }
103
        }
104

    
105
        public void setSHPFile(String fileName) {
106
                this.setDynValue(SHPFILE_PARAMTER_NAME, fileName);
107
                File file = (File) this.getDynValue(SHPFILE_PARAMTER_NAME);
108
                if (this.getDBFFile() == null){
109
                        this.setDBFFile(SHP.getDbfFile(file));
110
                }
111
                if (this.getSHXFile() == null) {
112
                        this.setSHXFile(SHP.getShxFile(file));
113
                }
114
        }
115

    
116
        public String getSHXFileName() {
117
                if( this.getSHXFile()==null ) {
118
                        return null;
119
                }
120
                return this.getSHXFile().getPath();
121
        }
122

    
123
        public File getSHXFile() {
124
                return (File) this.getDynValue(SHXFILE_PARAMTER_NAME);
125
        }
126
        public void setSHXFile(File file) {
127
                this.setDynValue(SHXFILE_PARAMTER_NAME, file);
128
        }
129

    
130
        public void setSHXFile(String fileName) {
131
                this.setDynValue(SHXFILE_PARAMTER_NAME, fileName);
132
        }
133

    
134
        public void setCRS(IProjection srs) {
135
                setDynValue(CRS_PARAMTER_NAME, srs);
136
        }
137

    
138
        public void setCRS(String srs) {
139
                setDynValue(CRS_PARAMTER_NAME, srs);
140
        }
141

    
142
        public IProjection getCRS() {
143
                return (IProjection) getDynValue(CRS_PARAMTER_NAME);
144
        }
145

    
146
}