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 / SHPStoreProviderFactory.java @ 40559
History | View | Annotate | Download (7.02 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 |
package org.gvsig.fmap.dal.store.shp; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.List; |
28 |
|
29 |
import org.slf4j.Logger; |
30 |
import org.slf4j.LoggerFactory; |
31 |
|
32 |
import org.gvsig.fmap.dal.DALLocator; |
33 |
import org.gvsig.fmap.dal.DataManager; |
34 |
import org.gvsig.fmap.dal.DataParameters; |
35 |
import org.gvsig.fmap.dal.DataStoreProvider; |
36 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
37 |
import org.gvsig.fmap.dal.DataTypes; |
38 |
import org.gvsig.fmap.dal.exception.InitializeException; |
39 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
40 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
41 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory; |
45 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
46 |
import org.gvsig.fmap.geom.Geometry; |
47 |
import org.gvsig.fmap.geom.GeometryLocator; |
48 |
import org.gvsig.fmap.geom.type.GeometryType; |
49 |
import org.gvsig.tools.ToolsLocator; |
50 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
51 |
import org.gvsig.tools.dynobject.DynObject; |
52 |
|
53 |
public class SHPStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory{ |
54 |
|
55 |
private static final Logger logger = LoggerFactory.getLogger(SHPStoreProviderFactory.class); |
56 |
|
57 |
public static final String DEFAULT_GEOMETRY_FIELD_NAME = "GEOMETRY"; |
58 |
public static final int DEFAULT_GEOMETRY_TYPE = Geometry.TYPES.SURFACE; |
59 |
public static final int DEFAULT_GEOMETRY_SUBTYPE = Geometry.SUBTYPES.GEOM2D; |
60 |
|
61 |
protected SHPStoreProviderFactory(String name, String description) { |
62 |
super(name, description);
|
63 |
} |
64 |
|
65 |
public DataStoreProvider createProvider(DataParameters parameters,
|
66 |
DataStoreProviderServices providerServices) |
67 |
throws InitializeException {
|
68 |
return new SHPStoreProvider((SHPStoreParameters) parameters, providerServices); |
69 |
} |
70 |
|
71 |
public DynObject createParameters() {
|
72 |
return new SHPStoreParameters(); |
73 |
} |
74 |
|
75 |
public int allowCreate() { |
76 |
return YES;
|
77 |
} |
78 |
|
79 |
public int allowWrite() { |
80 |
return YES;
|
81 |
} |
82 |
|
83 |
public int allowRead() { |
84 |
return YES;
|
85 |
} |
86 |
|
87 |
public int hasRasterSupport() { |
88 |
return NO;
|
89 |
} |
90 |
|
91 |
public int hasTabularSupport() { |
92 |
return YES;
|
93 |
} |
94 |
|
95 |
public int hasVectorialSupport() { |
96 |
return YES;
|
97 |
} |
98 |
|
99 |
public int allowMultipleGeometryTypes() { |
100 |
return NO;
|
101 |
} |
102 |
|
103 |
|
104 |
public int allowEditableFeatureType() { |
105 |
return YES;
|
106 |
} |
107 |
|
108 |
public List getSupportedDataTypes() { |
109 |
|
110 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
111 |
|
112 |
List resp = new ArrayList<Integer>(); |
113 |
resp.add(manager.get(DataTypes.STRING)); |
114 |
resp.add(manager.get(DataTypes.INT)); |
115 |
resp.add(manager.get(DataTypes.FLOAT)); |
116 |
resp.add(manager.get(DataTypes.DATE)); |
117 |
resp.add(manager.get(DataTypes.GEOMETRY)); |
118 |
return resp;
|
119 |
} |
120 |
|
121 |
public List getSupportedGeometryTypesSubtypes() { |
122 |
// null means all supported
|
123 |
int[] item = null; |
124 |
List resp = new ArrayList<int[]>(); |
125 |
// ====================================== 2d
|
126 |
item = new int[2]; |
127 |
item[0] = Geometry.TYPES.POINT;
|
128 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
129 |
resp.add(item); |
130 |
|
131 |
item = new int[2]; |
132 |
item[0] = Geometry.TYPES.CURVE;
|
133 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
134 |
resp.add(item); |
135 |
|
136 |
item = new int[2]; |
137 |
item[0] = Geometry.TYPES.SURFACE;
|
138 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
139 |
resp.add(item); |
140 |
|
141 |
item = new int[2]; |
142 |
item[0] = Geometry.TYPES.MULTIPOINT;
|
143 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
144 |
resp.add(item); |
145 |
// ====================================== 3d
|
146 |
item = new int[2]; |
147 |
item[0] = Geometry.TYPES.POINT;
|
148 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
149 |
resp.add(item); |
150 |
|
151 |
item = new int[2]; |
152 |
item[0] = Geometry.TYPES.CURVE;
|
153 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
154 |
resp.add(item); |
155 |
|
156 |
item = new int[2]; |
157 |
item[0] = Geometry.TYPES.SURFACE;
|
158 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
159 |
resp.add(item); |
160 |
|
161 |
item = new int[2]; |
162 |
item[0] = Geometry.TYPES.MULTIPOINT;
|
163 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
164 |
resp.add(item); |
165 |
// ====================================== 2dm
|
166 |
item = new int[2]; |
167 |
item[0] = Geometry.TYPES.POINT;
|
168 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
169 |
resp.add(item); |
170 |
|
171 |
item = new int[2]; |
172 |
item[0] = Geometry.TYPES.CURVE;
|
173 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
174 |
resp.add(item); |
175 |
|
176 |
item = new int[2]; |
177 |
item[0] = Geometry.TYPES.SURFACE;
|
178 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
179 |
resp.add(item); |
180 |
|
181 |
item = new int[2]; |
182 |
item[0] = Geometry.TYPES.MULTIPOINT;
|
183 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
184 |
resp.add(item); |
185 |
// ======================================
|
186 |
|
187 |
return resp;
|
188 |
} |
189 |
|
190 |
public boolean allowsMandatoryAttributes() { |
191 |
return false; |
192 |
} |
193 |
|
194 |
public boolean allowsPrimaryKeyAttributes() { |
195 |
return false; |
196 |
} |
197 |
|
198 |
/**
|
199 |
* @return dummy feature type. Must be overridden by subclasses
|
200 |
*
|
201 |
*/
|
202 |
public FeatureType createDefaultFeatureType() {
|
203 |
DataManager dm = DALLocator.getDataManager(); |
204 |
EditableFeatureType eft = dm.createFeatureType(); |
205 |
|
206 |
EditableFeatureAttributeDescriptor efatd = |
207 |
eft.add(DEFAULT_GEOMETRY_FIELD_NAME, DataTypes.GEOMETRY); |
208 |
|
209 |
GeometryType gt = null;
|
210 |
try {
|
211 |
gt = GeometryLocator.getGeometryManager().getGeometryType( |
212 |
DEFAULT_GEOMETRY_TYPE, |
213 |
DEFAULT_GEOMETRY_SUBTYPE); |
214 |
efatd.setGeometryType(gt); |
215 |
} catch (Exception ex) { |
216 |
logger.info("Error while setting geom type: " + ex.getMessage());
|
217 |
logger.info("Trying deprecated way...");
|
218 |
efatd.setGeometryType(DEFAULT_GEOMETRY_TYPE); |
219 |
efatd.setGeometrySubType(DEFAULT_GEOMETRY_SUBTYPE); |
220 |
} |
221 |
eft.setDefaultGeometryAttributeName(DEFAULT_GEOMETRY_FIELD_NAME); |
222 |
return eft.getNotEditableCopy();
|
223 |
} |
224 |
|
225 |
|
226 |
} |