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 @ 41860

History | View | Annotate | Download (4.33 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40559 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5 40435 jjdelcerro
 *
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 40559 jjdelcerro
 * as published by the Free Software Foundation; either version 3
9 40435 jjdelcerro
 * 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 40559 jjdelcerro
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23 40435 jjdelcerro
 */
24
25
package org.gvsig.fmap.dal.store.shp;
26
27
import java.io.File;
28 41526 jjdelcerro
import org.apache.commons.lang3.BooleanUtils;
29 40435 jjdelcerro
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
32
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters;
33
import org.gvsig.fmap.dal.store.shp.utils.SHP;
34
35
public class SHPStoreParameters extends DBFStoreParameters {
36
37
    public static final String PARAMETERS_DEFINITION_NAME = "SHPStoreParameters";
38
39 41526 jjdelcerro
    private static final String SHXFILE_PARAMTER_NAME = "shxfile";
40 40435 jjdelcerro
    private static final String SHPFILE_PARAMTER_NAME = "shpfile";
41 41526 jjdelcerro
    private static final String CRS_PARAMTER_NAME = "CRS";
42
    private static final String USE_NULLGEOMETRY_PARAMTER_NAME = "useNullGeometry";
43 41808 jjdelcerro
    private static final String ALLOW_INCONSISTENCIES_IN_GEOMETRY_TYPE = "allowInconsistenciesInGeometryType";
44 40435 jjdelcerro
45
        public SHPStoreParameters() {
46
                this(PARAMETERS_DEFINITION_NAME);
47
        }
48
49
        @Override
50
        public void validate() throws ValidateDataParametersException {
51
                fixParameters();
52
                super.validate();
53
        }
54
55
        public void fixParameters() {
56
                File file = this.getSHPFile();
57
                if( file!=null ) {
58
                        if (this.getDBFFile() == null){
59
                                this.setDBFFile(SHP.getDbfFile(file));
60
                        }
61
                        if (this.getSHXFile() == null) {
62
                                this.setSHXFile(SHP.getShxFile(file));
63
                        }
64
                }
65
        }
66
67
        public SHPStoreParameters(String parametersDefinitionName) {
68
                super(parametersDefinitionName, SHPStoreProvider.NAME);
69
        }
70
71
        public boolean isValid() {
72
                return super.isValid() && (this.getSHPFileName() != null);
73
        }
74
75
        public File getFile() {
76
                return this.getSHPFile();
77
        }
78
79
        public void setFile(File file) {
80
                this.setSHPFile(file);
81
        }
82
        public void setFile(String fileName) {
83
                this.setSHPFile(fileName);
84
        }
85
86
87
        public String getSHPFileName() {
88
                if( this.getSHPFile()==null ) {
89
                        return null;
90
                }
91
                return this.getSHPFile().getAbsolutePath();
92
        }
93
94
        public File getSHPFile() {
95
                return (File) this.getDynValue(SHPFILE_PARAMTER_NAME);
96
        }
97
98
        public void setSHPFile(File file) {
99
                this.setDynValue(SHPFILE_PARAMTER_NAME, file);
100
                if (this.getDBFFile() == null){
101
                        this.setDBFFile(SHP.getDbfFile(file));
102
                }
103
                if (this.getSHXFile() == null) {
104
                        this.setSHXFile(SHP.getShxFile(file));
105
                }
106
        }
107
108
        public void setSHPFile(String fileName) {
109
                this.setDynValue(SHPFILE_PARAMTER_NAME, fileName);
110
                File file = (File) this.getDynValue(SHPFILE_PARAMTER_NAME);
111
                if (this.getDBFFile() == null){
112
                        this.setDBFFile(SHP.getDbfFile(file));
113
                }
114
                if (this.getSHXFile() == null) {
115
                        this.setSHXFile(SHP.getShxFile(file));
116
                }
117
        }
118
119
        public String getSHXFileName() {
120
                if( this.getSHXFile()==null ) {
121
                        return null;
122
                }
123
                return this.getSHXFile().getPath();
124
        }
125
126
        public File getSHXFile() {
127
                return (File) this.getDynValue(SHXFILE_PARAMTER_NAME);
128
        }
129
        public void setSHXFile(File file) {
130
                this.setDynValue(SHXFILE_PARAMTER_NAME, file);
131
        }
132
133
        public void setSHXFile(String fileName) {
134
                this.setDynValue(SHXFILE_PARAMTER_NAME, fileName);
135
        }
136
137
        public void setCRS(IProjection srs) {
138
                setDynValue(CRS_PARAMTER_NAME, srs);
139
        }
140
141
        public void setCRS(String srs) {
142
                setDynValue(CRS_PARAMTER_NAME, srs);
143
        }
144
145
        public IProjection getCRS() {
146
                return (IProjection) getDynValue(CRS_PARAMTER_NAME);
147
        }
148
149 41526 jjdelcerro
        public boolean getUseNullGeometry() {
150
                return BooleanUtils.isTrue((Boolean) getDynValue(USE_NULLGEOMETRY_PARAMTER_NAME));
151
        }
152
153 41808 jjdelcerro
        public boolean getAllowInconsistenciesInGeometryType() {
154
                return BooleanUtils.isTrue((Boolean) getDynValue(ALLOW_INCONSISTENCIES_IN_GEOMETRY_TYPE));
155
        }
156 40435 jjdelcerro
}