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