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