svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / spi / AbstractFeatureStoreProvider.java @ 29326
History | View | Annotate | Download (9.81 KB)
1 |
package org.gvsig.fmap.dal.feature.spi; |
---|---|
2 |
|
3 |
import java.util.Iterator; |
4 |
|
5 |
import org.gvsig.fmap.dal.DALLocator; |
6 |
import org.gvsig.fmap.dal.DataServerExplorer; |
7 |
import org.gvsig.fmap.dal.DataStoreParameters; |
8 |
import org.gvsig.fmap.dal.exception.CloseException; |
9 |
import org.gvsig.fmap.dal.exception.DataException; |
10 |
import org.gvsig.fmap.dal.exception.InitializeException; |
11 |
import org.gvsig.fmap.dal.exception.OpenException; |
12 |
import org.gvsig.fmap.dal.exception.ReadException; |
13 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
14 |
import org.gvsig.fmap.dal.feature.FeatureLocks; |
15 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
16 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
17 |
import org.gvsig.fmap.dal.feature.FeatureType; |
18 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
19 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
20 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
21 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
22 |
import org.gvsig.fmap.geom.primitive.Envelope; |
23 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
24 |
import org.gvsig.tools.dynobject.DynClass; |
25 |
import org.gvsig.tools.dynobject.DynObject; |
26 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
27 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
28 |
|
29 |
|
30 |
public abstract class AbstractFeatureStoreProvider implements |
31 |
FeatureStoreProvider { |
32 |
|
33 |
private FeatureStoreProviderServices store;
|
34 |
private DelegatedDynObject metadata;
|
35 |
private DataStoreParameters parameters;
|
36 |
|
37 |
/**
|
38 |
* Default Constructor.
|
39 |
*
|
40 |
* @param params
|
41 |
* @param storeServices
|
42 |
* @param metadata
|
43 |
*/
|
44 |
protected AbstractFeatureStoreProvider(DataStoreParameters params,
|
45 |
DataStoreProviderServices storeServices, DynObject metadata) { |
46 |
this.store = (FeatureStoreProviderServices) storeServices;
|
47 |
this.metadata = (DelegatedDynObject) metadata;
|
48 |
this.parameters = params;
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* Constructor when cannot create metada in constrution time. <br>
|
53 |
* <br>
|
54 |
* <strong>Note: </strong> Don't use it if not is necesary. Set metada
|
55 |
* <strong>as soon as posible</strong> by
|
56 |
* {@link AbstractFeatureStoreProvider#setMetadata(DynObject)}
|
57 |
*
|
58 |
* @param params
|
59 |
* @param storeServices
|
60 |
*/
|
61 |
protected AbstractFeatureStoreProvider(DataStoreParameters params,
|
62 |
DataStoreProviderServices storeServices) { |
63 |
this.store = (FeatureStoreProviderServices) storeServices;
|
64 |
this.metadata = null; |
65 |
this.parameters = params;
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* Set metada container if this not set at construction time and only in one
|
70 |
* time. In other case an Exception will be throw
|
71 |
*
|
72 |
* @param metadata
|
73 |
*/
|
74 |
protected void setMetadata(DynObject metadata) { |
75 |
if (this.metadata != null) { |
76 |
// FIXME Exception
|
77 |
throw new IllegalStateException(); |
78 |
} |
79 |
this.metadata = (DelegatedDynObject) metadata;
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* @return the parameters
|
84 |
*/
|
85 |
public DataStoreParameters getParameters() {
|
86 |
return parameters;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Create or get a resource of <code>type</code> for <code>params</code> in
|
91 |
* {@link ResourceManager}
|
92 |
*
|
93 |
* @param type
|
94 |
* @param params
|
95 |
* @return
|
96 |
* @throws InitializeException
|
97 |
*/
|
98 |
protected ResourceProvider createResource(String type, Object[] params) |
99 |
throws InitializeException {
|
100 |
ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator |
101 |
.getResourceManager(); |
102 |
ResourceProvider resource = manager.createResource(type, params); |
103 |
return resource;
|
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
*
|
109 |
* @see
|
110 |
* org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getStoreServices()
|
111 |
*/
|
112 |
public FeatureStoreProviderServices getStoreServices() {
|
113 |
return this.store; |
114 |
} |
115 |
|
116 |
public FeatureStore getFeatureStore() {
|
117 |
return this.store.getFeatureStore(); |
118 |
} |
119 |
|
120 |
/**
|
121 |
* unsupported by default, override this otherwise
|
122 |
*
|
123 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#allowWrite()
|
124 |
*/
|
125 |
public boolean allowWrite() { |
126 |
return false; |
127 |
} |
128 |
|
129 |
|
130 |
/**
|
131 |
* unsupported by default, override this otherwise
|
132 |
*
|
133 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#performChanges(Iterator,
|
134 |
* Iterator, Iterator, Iterator)
|
135 |
*/
|
136 |
|
137 |
public void performChanges(Iterator deleteds, Iterator inserteds, |
138 |
Iterator updateds, Iterator featureTypesChanged) |
139 |
throws DataException {
|
140 |
// FIXME exception
|
141 |
throw new UnsupportedOperationException(); |
142 |
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* unsupported by default, override this otherwise
|
147 |
*
|
148 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#isLocksSupported()
|
149 |
*/
|
150 |
public boolean isLocksSupported() { |
151 |
return false; |
152 |
} |
153 |
|
154 |
/**
|
155 |
* Default Factory of {@link FeatureProvider}. Create a new default
|
156 |
* {@link FeatureProvider} instance.<br>
|
157 |
*
|
158 |
* Override this if you need an special implemtation of
|
159 |
* {@link FeatureProvider}.
|
160 |
*
|
161 |
* @return
|
162 |
* @throws DataException
|
163 |
*
|
164 |
* @see {@link org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createFeatureProvider(FeatureType)}
|
165 |
*/
|
166 |
|
167 |
public FeatureProvider createFeatureProvider(FeatureType type)
|
168 |
throws DataException {
|
169 |
return this.store.createDefaultFeatureProvider(type); |
170 |
} |
171 |
|
172 |
/**
|
173 |
* unsupported by default (return <code>null</code>), override this
|
174 |
* otherwise
|
175 |
*
|
176 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createFeatureLocks()
|
177 |
*/
|
178 |
public FeatureLocks createFeatureLocks() throws DataException { |
179 |
return null; |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Default Factory of {@link FeatureSelection}. Create a new default
|
184 |
* {@link FeatureSelection} instance.<br>
|
185 |
*
|
186 |
* Override this if you need an special implemtation of
|
187 |
* {@link FeatureSelection}.
|
188 |
*
|
189 |
* @return
|
190 |
* @throws DataException
|
191 |
*
|
192 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createFeatureSelection()
|
193 |
*/
|
194 |
public FeatureSelection createFeatureSelection() throws DataException { |
195 |
return this.store.createDefaultFeatureSelection(); |
196 |
} |
197 |
|
198 |
/**
|
199 |
* do nothing by default, override this otherwise
|
200 |
*
|
201 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#refresh()
|
202 |
*/
|
203 |
public void refresh() throws OpenException { |
204 |
// Do nothing by default
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* do nothing by default, override this otherwise
|
209 |
*
|
210 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#close()
|
211 |
*/
|
212 |
public void close() throws CloseException { |
213 |
// Do nothing by default
|
214 |
} |
215 |
|
216 |
public void dispose() throws CloseException { |
217 |
this.metadata = null; |
218 |
this.store = null; |
219 |
} |
220 |
|
221 |
/**
|
222 |
* unsupported geometry by default (return <code>null</code>), override this
|
223 |
* otherwise
|
224 |
*
|
225 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getEnvelope()
|
226 |
*/
|
227 |
public Envelope getEnvelope() throws DataException { |
228 |
return null; |
229 |
} |
230 |
|
231 |
/**
|
232 |
* unsupported geometry write by default (return <code>false</code>),
|
233 |
* override this otherwise
|
234 |
*
|
235 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#canWriteGeometry(int,
|
236 |
* int)
|
237 |
*/
|
238 |
public boolean canWriteGeometry(int geometryType, int geometrySubType) |
239 |
throws DataException {
|
240 |
return false; |
241 |
} |
242 |
|
243 |
// --- Metadata methods ---
|
244 |
|
245 |
|
246 |
public void delegate(DynObject dynObject) { |
247 |
if (this.metadata == null) { |
248 |
return;
|
249 |
} |
250 |
this.metadata.delegate(dynObject);
|
251 |
} |
252 |
|
253 |
public DynClass getDynClass() {
|
254 |
if (this.metadata == null) { |
255 |
return null; |
256 |
} |
257 |
return this.metadata.getDynClass(); |
258 |
} |
259 |
|
260 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
261 |
if (this.metadata == null) { |
262 |
return null; |
263 |
} |
264 |
// TODO this.open??
|
265 |
return this.metadata.getDynValue(name); |
266 |
} |
267 |
|
268 |
public boolean hasDynValue(String name) { |
269 |
if (this.metadata == null) { |
270 |
return false; |
271 |
} |
272 |
// TODO this.open??
|
273 |
return this.metadata.hasDynValue(name); |
274 |
} |
275 |
|
276 |
public void implement(DynClass dynClass) { |
277 |
if (this.metadata == null) { |
278 |
return;
|
279 |
} |
280 |
this.metadata.implement(dynClass);
|
281 |
|
282 |
} |
283 |
|
284 |
public Object invokeDynMethod(int code, DynObject context) |
285 |
throws DynMethodException {
|
286 |
if (this.metadata == null) { |
287 |
return null; |
288 |
} |
289 |
// TODO this.open??
|
290 |
return this.metadata.invokeDynMethod(this, code, context); |
291 |
} |
292 |
|
293 |
public Object invokeDynMethod(String name, DynObject context) |
294 |
throws DynMethodException {
|
295 |
if (this.metadata == null) { |
296 |
return null; |
297 |
} |
298 |
// TODO this.open??
|
299 |
return this.metadata.invokeDynMethod(this, name, context); |
300 |
} |
301 |
|
302 |
public void setDynValue(String name, Object value) |
303 |
throws DynFieldNotFoundException {
|
304 |
if (this.metadata == null) { |
305 |
return;
|
306 |
} |
307 |
// TODO this.open??
|
308 |
this.metadata.setDynValue(name, value);
|
309 |
} |
310 |
|
311 |
// --- end Metadata methods ---
|
312 |
|
313 |
/**
|
314 |
* unsupported by default, override this otherwise
|
315 |
*
|
316 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#allowAutomaticValues()
|
317 |
*/
|
318 |
public boolean allowAutomaticValues() { |
319 |
return false; |
320 |
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* unsupported by default, override this otherwise
|
325 |
*
|
326 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#append(org.gvsig.
|
327 |
* fmap.dal.feature.spi.FeatureProvider)
|
328 |
*/
|
329 |
public void append(FeatureProvider featureProvider) throws DataException { |
330 |
// FIXME exception
|
331 |
throw new UnsupportedOperationException(); |
332 |
} |
333 |
|
334 |
/**
|
335 |
* unsupported by default, override this otherwise
|
336 |
*
|
337 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#beginAppend()
|
338 |
*/
|
339 |
public void beginAppend() throws DataException { |
340 |
// FIXME exception
|
341 |
throw new UnsupportedOperationException(); |
342 |
} |
343 |
|
344 |
/**
|
345 |
* unsupported by default, override this otherwise
|
346 |
*
|
347 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#endAppend()
|
348 |
*/
|
349 |
public void endAppend() throws DataException { |
350 |
// FIXME exception
|
351 |
throw new UnsupportedOperationException(); |
352 |
} |
353 |
|
354 |
/**
|
355 |
* unsupported by default, override this otherwise
|
356 |
*
|
357 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#supportsAppendMode()
|
358 |
*/
|
359 |
public boolean supportsAppendMode() { |
360 |
return false; |
361 |
} |
362 |
|
363 |
/**
|
364 |
* unsupported by default (return null), override this otherwise
|
365 |
*
|
366 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getChilds()
|
367 |
*/
|
368 |
public Iterator getChilds() { |
369 |
return null; |
370 |
} |
371 |
|
372 |
/**
|
373 |
* unsupported by default (return null), override this otherwise
|
374 |
*
|
375 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getExplorer()
|
376 |
*/
|
377 |
public DataServerExplorer getExplorer() throws ReadException, |
378 |
ValidateDataParametersException { |
379 |
return null; |
380 |
} |
381 |
|
382 |
|
383 |
} |