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