svn-gvsig-desktop / tags / dal_time_support_Build_1 / libraries / libFMap_dal / libFMap_dal / src / org / gvsig / fmap / dal / impl / DefaultDataManager.java @ 36109
History | View | Annotate | Download (29.9 KB)
1 |
package org.gvsig.fmap.dal.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.lang.reflect.InvocationTargetException; |
5 |
import java.util.ArrayList; |
6 |
import java.util.HashMap; |
7 |
import java.util.List; |
8 |
import java.util.Map; |
9 |
|
10 |
import org.gvsig.fmap.dal.DALLocator; |
11 |
import org.gvsig.fmap.dal.DataManager; |
12 |
import org.gvsig.fmap.dal.DataServerExplorer; |
13 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
14 |
import org.gvsig.fmap.dal.DataStore; |
15 |
import org.gvsig.fmap.dal.DataStoreFactory; |
16 |
import org.gvsig.fmap.dal.DataStoreParameters; |
17 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
18 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
19 |
import org.gvsig.fmap.dal.exception.DataException; |
20 |
import org.gvsig.fmap.dal.exception.InitializeException; |
21 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
22 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
23 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
24 |
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
25 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
26 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
27 |
import org.gvsig.fmap.dal.feature.FeatureType; |
28 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
29 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
30 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
31 |
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
32 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
33 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
34 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
35 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
36 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
37 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
38 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
39 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
40 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
41 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
42 |
import org.gvsig.fmap.dal.spi.DataStoreInitializer; |
43 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
44 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
45 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
46 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
47 |
import org.gvsig.tools.ToolsLocator; |
48 |
import org.gvsig.tools.dynobject.DynObject; |
49 |
import org.gvsig.tools.evaluator.Evaluator; |
50 |
import org.gvsig.tools.exception.BaseException; |
51 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
52 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
53 |
import org.gvsig.tools.operations.OperationManager; |
54 |
|
55 |
public class DefaultDataManager implements DataManager, |
56 |
DataManagerProviderServices { |
57 |
|
58 |
final static private String DATA_MANAGER_STORE = "Data.manager.stores"; |
59 |
final static private String DATA_MANAGER_STORE_DESCRIPTION = "DAL stores providers"; |
60 |
|
61 |
final static private String DATA_MANAGER_STORE_PARAMS = "Data.manager.stores.params"; |
62 |
final static private String DATA_MANAGER_STORE_PARAMS_DESCRIPTION = "DAL stores providers parameters"; |
63 |
|
64 |
final static private String DATA_MANAGER_EXPLORER = "Data.manager.explorers"; |
65 |
final static private String DATA_MANAGER_EXPLORER_DESCRIPTION = "DAL explorers providers"; |
66 |
|
67 |
final static private String DATA_MANAGER_EXPLORER_PARAMS = "Data.manager.explorers.params"; |
68 |
final static private String DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION = "DAL explorer providers parameters"; |
69 |
|
70 |
final static private String DATA_MANAGER_INDEX = "Data.manager.indexes"; |
71 |
final static private String DATA_MANAGER_INDEX_DESCRIPTION = "DAL index providers"; |
72 |
|
73 |
final static private String DATA_MANAGER_CACHE = "Data.manager.caches"; |
74 |
final static private String DATA_MANAGER_CACHE_DESCRIPTION = "DAL cache providers"; |
75 |
|
76 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR = "Data.manager.expresion.evaluator"; |
77 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT = "default"; |
78 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION = "DAL expresion evaluators."; |
79 |
|
80 |
final static private String DATA_MANAGER_STORE_FACTORY = "Data.manager.stores.factory"; |
81 |
final static private String DATA_MANAGER_STORE_FACTORY_DESCRIPTION = "DAL stores factories"; |
82 |
|
83 |
final static private String DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER = "Data.manager.feature.attribute.getter"; |
84 |
final static private String DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER_DESCRIPTION = "DAL feature attribute getters"; |
85 |
|
86 |
/** This map contains the name of the default provider for each data type */
|
87 |
private Map defaultDataIndexProviders; |
88 |
|
89 |
private OpenErrorHandler openErrorHandler;
|
90 |
|
91 |
public DefaultDataManager() {
|
92 |
/*
|
93 |
* Create te extensions point in te registry.
|
94 |
*/
|
95 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE, |
96 |
DATA_MANAGER_STORE_DESCRIPTION); |
97 |
|
98 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS, |
99 |
DATA_MANAGER_STORE_PARAMS_DESCRIPTION); |
100 |
|
101 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER, |
102 |
DATA_MANAGER_EXPLORER_DESCRIPTION); |
103 |
|
104 |
ToolsLocator.getExtensionPointManager().add( |
105 |
DATA_MANAGER_EXPLORER_PARAMS, |
106 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION); |
107 |
|
108 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX, |
109 |
DATA_MANAGER_INDEX_DESCRIPTION); |
110 |
|
111 |
ToolsLocator.getExtensionPointManager().add( |
112 |
DATA_MANAGER_EXPRESION_EVALUATOR, |
113 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION); |
114 |
|
115 |
initializeIndexes(); |
116 |
} |
117 |
|
118 |
/**
|
119 |
*
|
120 |
* @return ResourceManager
|
121 |
*/
|
122 |
|
123 |
public ResourceManager getResourceManager() {
|
124 |
return DALLocator.getResourceManager();
|
125 |
} |
126 |
|
127 |
public OperationManager getOperationManager() {
|
128 |
return ToolsLocator.getOperationManager();
|
129 |
} |
130 |
|
131 |
public String getTemporaryDirectory() { |
132 |
// FIXME Define a better tempdir solution
|
133 |
String tmp = System.getProperty("TMP"); |
134 |
if (tmp == null) { |
135 |
tmp = System.getProperty("TEMP"); |
136 |
} |
137 |
if (tmp == null) { |
138 |
File tmp_file = new File(System.getProperty("HOME"), "_daltmp_"); |
139 |
int i = 1; |
140 |
while (!tmp_file.exists() || !tmp_file.isDirectory()) {
|
141 |
tmp_file = new File(tmp_file.getAbsolutePath() + i); |
142 |
i++; |
143 |
} |
144 |
if (!tmp_file.exists()) {
|
145 |
tmp_file.mkdir(); |
146 |
} |
147 |
tmp = tmp_file.getAbsolutePath(); |
148 |
} |
149 |
return tmp;
|
150 |
} |
151 |
|
152 |
/*
|
153 |
* ====================================================================
|
154 |
*
|
155 |
* Store related services
|
156 |
*/
|
157 |
public void registerStoreProvider(String name, Class storeProviderClass, |
158 |
Class parametersClass) {
|
159 |
if (name == null || storeProviderClass == null |
160 |
|| parametersClass == null) {
|
161 |
// FIXME Exception
|
162 |
throw new IllegalArgumentException("Any parameters can be null"); |
163 |
} |
164 |
|
165 |
if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) {
|
166 |
// FIXME Exception
|
167 |
throw new IllegalArgumentException(parametersClass.getName() |
168 |
+ " must implement org.gvsig.fmap.dal.DataStoreParameters");
|
169 |
} |
170 |
|
171 |
if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
172 |
|
173 |
} else if (FeatureStoreProvider.class |
174 |
.isAssignableFrom(storeProviderClass)) { |
175 |
|
176 |
} else {
|
177 |
// FIXME Exception
|
178 |
throw new IllegalArgumentException( |
179 |
"Not supported implemtation: name=" + name
|
180 |
+ " provider class=" + storeProviderClass.getName());
|
181 |
} |
182 |
|
183 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE, |
184 |
DATA_MANAGER_STORE_DESCRIPTION).append(name, null,
|
185 |
storeProviderClass); |
186 |
|
187 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS, |
188 |
DATA_MANAGER_STORE_PARAMS_DESCRIPTION).append(name, null,
|
189 |
parametersClass); |
190 |
} |
191 |
|
192 |
/*
|
193 |
* (non-Javadoc)
|
194 |
* @see org.gvsig.fmap.dal.spi.DataManagerProviderServices#registerStoreFactory(java.lang.String, java.lang.Class)
|
195 |
*/
|
196 |
public void registerStoreFactory(String name, Class storeProviderClass) { |
197 |
if (name == null || storeProviderClass == null) { |
198 |
// FIXME Exception
|
199 |
throw new IllegalArgumentException("Any parameters can be null"); |
200 |
} |
201 |
|
202 |
if(!(DataStoreFactory.class.isAssignableFrom(storeProviderClass))) {
|
203 |
// FIXME Exception
|
204 |
throw new IllegalArgumentException( |
205 |
"Not supported implemtation: name=" + name
|
206 |
+ " provider class=" + storeProviderClass.getName());
|
207 |
} |
208 |
|
209 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_FACTORY, |
210 |
DATA_MANAGER_STORE_FACTORY_DESCRIPTION).append(name, null,
|
211 |
storeProviderClass); |
212 |
} |
213 |
|
214 |
public DataStoreParameters createStoreParameters(String name) |
215 |
throws InitializeException, ProviderNotRegisteredException {
|
216 |
try {
|
217 |
DataStoreParameters params = (DataStoreParameters) ToolsLocator |
218 |
.getExtensionPointManager().get(DATA_MANAGER_STORE_PARAMS) |
219 |
.create(name); |
220 |
if (params == null) { |
221 |
throw new ProviderNotRegisteredException(name); |
222 |
} |
223 |
return params;
|
224 |
} catch (InstantiationException e) { |
225 |
throw new InitializeException(e); |
226 |
} catch (IllegalAccessException e) { |
227 |
throw new InitializeException(e); |
228 |
} catch (SecurityException e) { |
229 |
throw new InitializeException(e); |
230 |
} catch (IllegalArgumentException e) { |
231 |
throw new InitializeException(e); |
232 |
} |
233 |
} |
234 |
|
235 |
public DataStore localOpenStore(String provider, DataStoreParameters parameters) |
236 |
throws InitializeException, ProviderNotRegisteredException,
|
237 |
ValidateDataParametersException { |
238 |
String name = provider; //parameters.getDataStoreName(); |
239 |
|
240 |
parameters.validate(); |
241 |
|
242 |
DataStore store; |
243 |
Extension storeProviderExtension = ToolsLocator |
244 |
.getExtensionPointManager().get(DATA_MANAGER_STORE).get(name); |
245 |
|
246 |
if (storeProviderExtension == null) { |
247 |
throw new ProviderNotRegisteredException(name); |
248 |
} |
249 |
|
250 |
Class providerClass = storeProviderExtension.getExtension();
|
251 |
if (providerClass == null) { |
252 |
throw new ProviderNotRegisteredException(name); |
253 |
} |
254 |
|
255 |
if (CoverageStoreProvider.class.isAssignableFrom(providerClass)) {
|
256 |
ExtensionPoint.Extension point = ToolsLocator.getExtensionPointManager(). |
257 |
get(DATA_MANAGER_STORE_FACTORY).get(name); |
258 |
DataStoreFactory factory = null;
|
259 |
try {
|
260 |
factory = (DataStoreFactory)point.create(); |
261 |
} catch (InstantiationException e) { |
262 |
throw new InitializeException(e); |
263 |
} catch (IllegalAccessException e) { |
264 |
throw new InitializeException(e); |
265 |
} |
266 |
factory.setParameters(parameters); |
267 |
store = factory.createStore(); |
268 |
} else if (FeatureStoreProvider.class.isAssignableFrom(providerClass)) { |
269 |
|
270 |
store = new DefaultFeatureStore();
|
271 |
|
272 |
} else {
|
273 |
// FIXME Exception
|
274 |
throw new InitializeException(name, new RuntimeException( |
275 |
"Not supported implemtation: name=" + name
|
276 |
+ " provider class=" + providerClass.getName()));
|
277 |
} |
278 |
|
279 |
this.intializeDataStore(store, parameters);
|
280 |
|
281 |
return store;
|
282 |
} |
283 |
|
284 |
public DataStore openStore(String provider, DataStoreParameters parameters) |
285 |
throws InitializeException, ProviderNotRegisteredException,
|
286 |
ValidateDataParametersException { |
287 |
|
288 |
// try {
|
289 |
return localOpenStore(provider, parameters);
|
290 |
// } catch (Exception e) {
|
291 |
// // TODO: handle exception
|
292 |
// }
|
293 |
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* @deprecated see openStore
|
298 |
*/
|
299 |
public DataStore createStore(DataStoreParameters parameters)
|
300 |
throws InitializeException, ProviderNotRegisteredException,
|
301 |
ValidateDataParametersException { |
302 |
return openStore(parameters.getDataStoreName(), parameters);
|
303 |
} |
304 |
|
305 |
public List getStoreProviders() { |
306 |
return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_STORE)
|
307 |
.getNames(); |
308 |
} |
309 |
|
310 |
public List getStoreProviders(String name) { |
311 |
return getStoreProviders(); // FIXME: need filter from the name of |
312 |
// the explorer
|
313 |
} |
314 |
|
315 |
public NewDataStoreParameters createNewStoreParameters(String explorer, |
316 |
String provider) throws InitializeException, |
317 |
ProviderNotRegisteredException { |
318 |
|
319 |
DataServerExplorerParameters parameters; |
320 |
DataServerExplorer server; |
321 |
try {
|
322 |
parameters = this.createServerExplorerParameters(explorer);
|
323 |
server = this.openServerExplorerWithoutValidate(explorer, parameters);
|
324 |
return server.getAddParameters(provider);
|
325 |
} catch (ValidateDataParametersException e) {
|
326 |
throw new InitializeException(e); |
327 |
} catch (DataException e) {
|
328 |
throw new InitializeException(e); |
329 |
} |
330 |
} |
331 |
|
332 |
public void newStore(String explorer, String provider, NewDataStoreParameters parameters, boolean overwrite) |
333 |
throws InitializeException, ProviderNotRegisteredException,
|
334 |
ValidateDataParametersException { |
335 |
|
336 |
parameters.validate(); |
337 |
|
338 |
DataServerExplorerParameters explorerParameters; |
339 |
DataServerExplorer server; |
340 |
explorerParameters = this.createServerExplorerParameters(explorer);
|
341 |
server = this.openServerExplorerWithoutValidate(explorer, explorerParameters);
|
342 |
try {
|
343 |
server.add(provider, parameters, overwrite); |
344 |
} catch (DataException e) {
|
345 |
throw new InitializeException(e); |
346 |
} |
347 |
} |
348 |
|
349 |
/*
|
350 |
* ====================================================================
|
351 |
*
|
352 |
* Explorer related services
|
353 |
*/
|
354 |
public void registerExplorerProvider(String name, Class explorerClass, |
355 |
Class parametersClass) {
|
356 |
|
357 |
if (name == null || explorerClass == null || parametersClass == null) { |
358 |
// FIXME Exception
|
359 |
throw new IllegalArgumentException("Any parameters can be null"); |
360 |
} |
361 |
|
362 |
if (!DataServerExplorerParameters.class
|
363 |
.isAssignableFrom(parametersClass)) { |
364 |
// FIXME Exception
|
365 |
throw new IllegalArgumentException( |
366 |
parametersClass.getName() |
367 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorerParameters");
|
368 |
} |
369 |
|
370 |
if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) {
|
371 |
// FIXME Exception
|
372 |
throw new IllegalArgumentException(explorerClass.getName() |
373 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorer");
|
374 |
} |
375 |
|
376 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER, |
377 |
DATA_MANAGER_EXPLORER_DESCRIPTION).append(name, null,
|
378 |
explorerClass); |
379 |
|
380 |
ToolsLocator.getExtensionPointManager().add( |
381 |
DATA_MANAGER_EXPLORER_PARAMS, |
382 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION).append(name, null,
|
383 |
parametersClass); |
384 |
} |
385 |
|
386 |
public DataServerExplorerParameters createServerExplorerParameters(
|
387 |
String name) throws InitializeException, |
388 |
ProviderNotRegisteredException { |
389 |
try {
|
390 |
DataServerExplorerParameters params = (DataServerExplorerParameters) ToolsLocator |
391 |
.getExtensionPointManager().get( |
392 |
DATA_MANAGER_EXPLORER_PARAMS).create(name); |
393 |
if (params == null) { |
394 |
throw new ProviderNotRegisteredException(name); |
395 |
} |
396 |
return params;
|
397 |
} catch (InstantiationException e) { |
398 |
throw new InitializeException(e); |
399 |
} catch (IllegalAccessException e) { |
400 |
throw new InitializeException(e); |
401 |
} catch (SecurityException e) { |
402 |
throw new InitializeException(e); |
403 |
} catch (IllegalArgumentException e) { |
404 |
throw new InitializeException(e); |
405 |
} |
406 |
} |
407 |
|
408 |
public DataServerExplorer openServerExplorer(
|
409 |
String explorer,
|
410 |
DataServerExplorerParameters parameters) |
411 |
throws InitializeException, ProviderNotRegisteredException,
|
412 |
ValidateDataParametersException { |
413 |
|
414 |
if( parameters != null ) { |
415 |
parameters.validate(); |
416 |
} |
417 |
return this.openServerExplorerWithoutValidate(explorer, parameters); |
418 |
} |
419 |
|
420 |
private DataServerExplorer openServerExplorerWithoutValidate(
|
421 |
String explorerName,
|
422 |
DataServerExplorerParameters parameters) |
423 |
throws InitializeException, ProviderNotRegisteredException,
|
424 |
ValidateDataParametersException { |
425 |
|
426 |
String name = explorerName; //parameters.getExplorerName(); |
427 |
|
428 |
try {
|
429 |
DataServerExplorerProvider server = (DataServerExplorerProvider) ToolsLocator |
430 |
.getExtensionPointManager() |
431 |
.get(DATA_MANAGER_EXPLORER) |
432 |
.create( |
433 |
name, |
434 |
new Object[] { |
435 |
parameters, |
436 |
new DefaultDataServerExplorerProviderServices() });
|
437 |
if (server == null) { |
438 |
throw new ProviderNotRegisteredException(name); |
439 |
} |
440 |
return server;
|
441 |
} catch (InstantiationException e) { |
442 |
throw new InitializeException(e); |
443 |
} catch (IllegalAccessException e) { |
444 |
throw new InitializeException(e); |
445 |
} catch (SecurityException e) { |
446 |
throw new InitializeException(e); |
447 |
} catch (IllegalArgumentException e) { |
448 |
throw new InitializeException(e); |
449 |
} catch (NoSuchMethodException e) { |
450 |
throw new InitializeException(e); |
451 |
} catch (InvocationTargetException e) { |
452 |
throw new InitializeException(e); |
453 |
} |
454 |
} |
455 |
|
456 |
/**
|
457 |
* @deprecated see openServerExplorer
|
458 |
*/
|
459 |
public DataServerExplorer createServerExplorer(
|
460 |
DataServerExplorerParameters parameters) |
461 |
throws InitializeException, ProviderNotRegisteredException,
|
462 |
ValidateDataParametersException { |
463 |
return openServerExplorer(parameters.getExplorerName(), parameters);
|
464 |
} |
465 |
|
466 |
public List getExplorerProviders() { |
467 |
return ToolsLocator.getExtensionPointManager().get(
|
468 |
DATA_MANAGER_EXPLORER).getNames(); |
469 |
} |
470 |
|
471 |
/*
|
472 |
* ====================================================================
|
473 |
*
|
474 |
* Expresion evaluation related services
|
475 |
*/
|
476 |
public Evaluator createExpresion(String expresion) |
477 |
throws InitializeException {
|
478 |
try {
|
479 |
return (Evaluator) ToolsLocator.getExtensionPointManager().get(
|
480 |
DATA_MANAGER_EXPRESION_EVALUATOR).create( |
481 |
DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
482 |
new Object[] { expresion }); |
483 |
} catch (SecurityException e) { |
484 |
throw new InitializeException(e); |
485 |
} catch (IllegalArgumentException e) { |
486 |
throw new InitializeException(e); |
487 |
} catch (NoSuchMethodException e) { |
488 |
throw new InitializeException(e); |
489 |
} catch (InstantiationException e) { |
490 |
throw new InitializeException(e); |
491 |
} catch (IllegalAccessException e) { |
492 |
throw new InitializeException(e); |
493 |
} catch (InvocationTargetException e) { |
494 |
throw new InitializeException(e); |
495 |
} |
496 |
} |
497 |
|
498 |
public void registerDefaultEvaluator(Class evaluatorClass) { |
499 |
if (!Evaluator.class.isAssignableFrom(evaluatorClass)) {
|
500 |
throw new ClassCastException(); |
501 |
} |
502 |
ToolsLocator.getExtensionPointManager().add( |
503 |
DATA_MANAGER_EXPRESION_EVALUATOR, |
504 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION).append( |
505 |
DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
506 |
"Default expresion evaluator for use in DAL", evaluatorClass);
|
507 |
} |
508 |
|
509 |
/*
|
510 |
* ====================================================================
|
511 |
*
|
512 |
* Index related services
|
513 |
*/
|
514 |
|
515 |
public List getFeatureIndexProviders() { |
516 |
return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_INDEX)
|
517 |
.getNames(); |
518 |
} |
519 |
|
520 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
521 |
defaultDataIndexProviders.put(new Integer(dataType), name); |
522 |
} |
523 |
|
524 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
525 |
return (String) defaultDataIndexProviders.get(new Integer(dataType)); |
526 |
} |
527 |
|
528 |
public FeatureIndexProviderServices createFeatureIndexProvider(String name, |
529 |
FeatureStore store, FeatureType type, String indexName,
|
530 |
FeatureAttributeDescriptor attr) throws InitializeException,
|
531 |
ProviderNotRegisteredException { |
532 |
|
533 |
if (name == null) { |
534 |
name = getDefaultFeatureIndexProviderName(attr.getType()); |
535 |
} |
536 |
|
537 |
if (name == null) { |
538 |
throw new InitializeException( |
539 |
"There not any index provider registered.", null); |
540 |
} |
541 |
|
542 |
try {
|
543 |
FeatureIndexProvider provider = (FeatureIndexProvider) ToolsLocator |
544 |
.getExtensionPointManager().get(DATA_MANAGER_INDEX).create( |
545 |
name); |
546 |
if (provider == null) { |
547 |
throw new ProviderNotRegisteredException(name); |
548 |
} |
549 |
FeatureIndexProviderServices services = new DefaultFeatureIndex(
|
550 |
(FeatureStoreProviderServices) store, type, provider, attr |
551 |
.getName(), indexName); |
552 |
services.initialize(); |
553 |
return services;
|
554 |
} catch (InstantiationException e) { |
555 |
throw new InitializeException(e); |
556 |
} catch (IllegalAccessException e) { |
557 |
throw new InitializeException(e); |
558 |
} catch (SecurityException e) { |
559 |
throw new InitializeException(e); |
560 |
} catch (IllegalArgumentException e) { |
561 |
throw new InitializeException(e); |
562 |
} |
563 |
} |
564 |
|
565 |
public void registerFeatureIndexProvider(String name, String description, |
566 |
Class clazz, int dataType) { |
567 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX, |
568 |
DATA_MANAGER_INDEX_DESCRIPTION).append(name, null, clazz);
|
569 |
|
570 |
if (getDefaultFeatureIndexProviderName(dataType) == null) { |
571 |
setDefaultFeatureIndexProviderName(dataType, name); |
572 |
} |
573 |
} |
574 |
|
575 |
private void initializeIndexes() { |
576 |
this.defaultDataIndexProviders = new HashMap(); |
577 |
} |
578 |
|
579 |
public void intializeDataStore(DataStore store, |
580 |
DataStoreParameters parameters) throws InitializeException,
|
581 |
ProviderNotRegisteredException { |
582 |
|
583 |
((DataStoreInitializer)store).intializePhase1(this, parameters);
|
584 |
DataStoreProvider provider = this.createProvider((DataStoreProviderServices) store, parameters);
|
585 |
((DataStoreInitializer)store).intializePhase2(provider); |
586 |
|
587 |
} |
588 |
|
589 |
public DataStoreProvider createProvider(DataStoreProviderServices providerServices, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException { |
590 |
String name = parameters.getDataStoreName();
|
591 |
DataStoreProvider provider = null;
|
592 |
boolean retry = true; |
593 |
while (retry){
|
594 |
try {
|
595 |
provider = (DataStoreProvider) ToolsLocator |
596 |
.getExtensionPointManager().get(DATA_MANAGER_STORE).create( |
597 |
name, |
598 |
new Object[] { parameters, providerServices }); |
599 |
retry = false;
|
600 |
} catch (Exception e) { |
601 |
if (openErrorHandler != null){ |
602 |
retry = openErrorHandler.canRetryOpen(e, parameters); |
603 |
} else {
|
604 |
retry = false;
|
605 |
} |
606 |
if (!retry){
|
607 |
throw new InitializeException(parameters.getDataStoreName(), e); |
608 |
} |
609 |
} |
610 |
} |
611 |
if (provider == null) { |
612 |
throw new ProviderNotRegisteredException(name); |
613 |
} |
614 |
return provider;
|
615 |
} |
616 |
|
617 |
public void registerFeatureCacheProvider( |
618 |
FeatureCacheProviderFactory providerFactory) { |
619 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_CACHE, |
620 |
DATA_MANAGER_CACHE_DESCRIPTION).append( |
621 |
providerFactory.getName(), "",
|
622 |
providerFactory); |
623 |
} |
624 |
|
625 |
public FeatureCacheProvider createFeatureCacheProvider(String name, |
626 |
DynObject parameters) throws DataException {
|
627 |
if (name == null) { |
628 |
throw new InitializeException("It is necessary to provide a cache name", null); |
629 |
} |
630 |
if (parameters == null){ |
631 |
throw new InitializeException("It is necessary to provide parameters to create the explorer", null); |
632 |
} |
633 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
634 |
try {
|
635 |
featureCacheProviderFactory = (FeatureCacheProviderFactory) ToolsLocator |
636 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE).create(name); |
637 |
if (featureCacheProviderFactory == null) { |
638 |
throw new ProviderNotRegisteredException(name); |
639 |
} |
640 |
return featureCacheProviderFactory.createCacheProvider(parameters);
|
641 |
} catch (InstantiationException e) { |
642 |
throw new InitializeException(e); |
643 |
} catch (IllegalAccessException e) { |
644 |
throw new InitializeException(e); |
645 |
} |
646 |
} |
647 |
|
648 |
public List getFeatureCacheProviders() { |
649 |
ExtensionPoint extensionPoint = ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_CACHE); |
650 |
if (extensionPoint != null){ |
651 |
return ToolsLocator.getExtensionPointManager().get(
|
652 |
DATA_MANAGER_CACHE).getNames(); |
653 |
}else{
|
654 |
return new ArrayList(); |
655 |
} |
656 |
} |
657 |
|
658 |
public DynObject createCacheParameters(String name) |
659 |
throws InitializeException, ProviderNotRegisteredException {
|
660 |
if (name == null) { |
661 |
throw new InitializeException("It is necessary to provide a cache name", null); |
662 |
} |
663 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
664 |
try {
|
665 |
featureCacheProviderFactory = (FeatureCacheProviderFactory) ToolsLocator |
666 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE).create(name); |
667 |
if (featureCacheProviderFactory == null) { |
668 |
throw new ProviderNotRegisteredException(name); |
669 |
} |
670 |
return featureCacheProviderFactory.createParameters();
|
671 |
} catch (InstantiationException e) { |
672 |
throw new InitializeException(e); |
673 |
} catch (IllegalAccessException e) { |
674 |
throw new InitializeException(e); |
675 |
} |
676 |
} |
677 |
|
678 |
public DataStoreParameters createMemoryStoreParameters(
|
679 |
String autoOrderAttributeName) throws InitializeException { |
680 |
|
681 |
DataStoreParameters parameters; |
682 |
try {
|
683 |
parameters = createStoreParameters(MemoryStoreProvider.NAME); |
684 |
if (autoOrderAttributeName != null) { |
685 |
parameters.setDynValue( |
686 |
MemoryStoreParameters.ORDER_PARAMETER_NAME, |
687 |
autoOrderAttributeName); |
688 |
} |
689 |
return parameters;
|
690 |
} catch (ProviderNotRegisteredException e) {
|
691 |
throw new InitializeException("MemoryStoreProvider", e); |
692 |
} |
693 |
} |
694 |
|
695 |
public FeatureStore createMemoryStore(String autoOrderAttributeName) |
696 |
throws InitializeException {
|
697 |
|
698 |
DataStoreParameters parameters = createMemoryStoreParameters(autoOrderAttributeName); |
699 |
try {
|
700 |
return (FeatureStore) createStore(parameters);
|
701 |
} catch (ValidateDataParametersException e) {
|
702 |
throw new InitializeException("MemoryStoreProvider", e); |
703 |
} catch (ProviderNotRegisteredException e) {
|
704 |
throw new InitializeException("MemoryStoreProvider", e); |
705 |
} |
706 |
} |
707 |
|
708 |
public FeaturePagingHelper createFeaturePagingHelper(
|
709 |
FeatureStore featureStore, int pageSize) throws BaseException { |
710 |
return new FeaturePagingHelperImpl(featureStore, pageSize); |
711 |
} |
712 |
|
713 |
public FeaturePagingHelper createFeaturePagingHelper(
|
714 |
FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
|
715 |
throws BaseException {
|
716 |
return new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize); |
717 |
} |
718 |
|
719 |
public void registerFeatureAttributeGetter(String name, Class clazz) { |
720 |
if (name == null || clazz == null) { |
721 |
throw new IllegalArgumentException("Any parameters can be null"); |
722 |
} |
723 |
|
724 |
if(!(FeatureAttributeGetter.class.isAssignableFrom(clazz))) {
|
725 |
throw new IllegalArgumentException( |
726 |
"Not supported implemtation: name=" + name
|
727 |
+ " class=" + clazz.getName());
|
728 |
} |
729 |
|
730 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER, |
731 |
DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER_DESCRIPTION).append(name, null,
|
732 |
clazz); |
733 |
|
734 |
} |
735 |
|
736 |
public FeatureAttributeGetter createFeatureAttributeGetter(String name) throws InitializeException { |
737 |
if (name == null) { |
738 |
throw new IllegalArgumentException("The parameter can not be null"); |
739 |
} |
740 |
|
741 |
try{
|
742 |
return (FeatureAttributeGetter) ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER).create(name);
|
743 |
} catch (InstantiationException e) { |
744 |
throw new InitializeException("FeatureAttributeGetter", e); |
745 |
} catch (IllegalAccessException e) { |
746 |
throw new InitializeException("FeatureAttributeGetter", e); |
747 |
} |
748 |
} |
749 |
|
750 |
public void setOpenErrorHandler(OpenErrorHandler handler) { |
751 |
openErrorHandler = handler; |
752 |
|
753 |
} |
754 |
|
755 |
} |