svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / impl / DefaultDataManager.java @ 40435
History | View | Annotate | Download (36 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.fmap.dal.impl; |
23 |
|
24 |
import java.io.File; |
25 |
import java.lang.reflect.InvocationTargetException; |
26 |
import java.util.ArrayList; |
27 |
import java.util.HashMap; |
28 |
import java.util.List; |
29 |
import java.util.Map; |
30 |
|
31 |
import org.gvsig.fmap.dal.DALLocator; |
32 |
import org.gvsig.fmap.dal.DataManager; |
33 |
import org.gvsig.fmap.dal.DataServerExplorer; |
34 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
35 |
import org.gvsig.fmap.dal.DataStore; |
36 |
import org.gvsig.fmap.dal.DataStoreFactory; |
37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
38 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
39 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
40 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
43 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
44 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
45 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
46 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
48 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
50 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
51 |
import org.gvsig.fmap.dal.feature.FeatureType; |
52 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
53 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
54 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
55 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
56 |
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
57 |
import org.gvsig.fmap.dal.feature.spi.DataStoreProviderToFeatureStoreProviderFactoryWrapper; |
58 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
59 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
60 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
61 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
62 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
63 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
64 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
65 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
66 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
67 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
68 |
import org.gvsig.fmap.dal.spi.DataStoreInitializer; |
69 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
70 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
71 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
72 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
73 |
import org.gvsig.fmap.geom.DataTypes; |
74 |
import org.gvsig.tools.ToolsLocator; |
75 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
76 |
import org.gvsig.tools.dynobject.DynObject; |
77 |
import org.gvsig.tools.evaluator.Evaluator; |
78 |
import org.gvsig.tools.exception.BaseException; |
79 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
80 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
81 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
82 |
import org.gvsig.tools.operations.OperationManager; |
83 |
|
84 |
public class DefaultDataManager implements DataManager, |
85 |
DataManagerProviderServices { |
86 |
|
87 |
final static private String DATA_MANAGER_STORE = "Data.manager.stores"; |
88 |
final static private String DATA_MANAGER_STORE_DESCRIPTION = |
89 |
"DAL stores providers";
|
90 |
|
91 |
final static private String DATA_MANAGER_STORE_PARAMS = |
92 |
"Data.manager.stores.params";
|
93 |
final static private String DATA_MANAGER_STORE_PARAMS_DESCRIPTION = |
94 |
"DAL stores providers parameters";
|
95 |
|
96 |
final static private String DATA_MANAGER_EXPLORER = |
97 |
"Data.manager.explorers";
|
98 |
final static private String DATA_MANAGER_EXPLORER_DESCRIPTION = |
99 |
"DAL explorers providers";
|
100 |
|
101 |
final static private String DATA_MANAGER_EXPLORER_PARAMS = |
102 |
"Data.manager.explorers.params";
|
103 |
final static private String DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION = |
104 |
"DAL explorer providers parameters";
|
105 |
|
106 |
final static private String DATA_MANAGER_INDEX = "Data.manager.indexes"; |
107 |
final static private String DATA_MANAGER_INDEX_DESCRIPTION = |
108 |
"DAL index providers";
|
109 |
|
110 |
final static private String DATA_MANAGER_CACHE = "Data.manager.caches"; |
111 |
final static private String DATA_MANAGER_CACHE_DESCRIPTION = |
112 |
"DAL cache providers";
|
113 |
|
114 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR = |
115 |
"Data.manager.expresion.evaluator";
|
116 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT = |
117 |
"default";
|
118 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION = |
119 |
"DAL expresion evaluators.";
|
120 |
|
121 |
final static private String DATA_MANAGER_STORE_FACTORY = |
122 |
"Data.manager.stores.factory";
|
123 |
final static private String DATA_MANAGER_STORE_FACTORY_DESCRIPTION = |
124 |
"DAL stores factories";
|
125 |
|
126 |
final static private String DATA_MANAGER_STORE_PROVIDER_FACTORY = |
127 |
"Data.manager.providers.factory";
|
128 |
final static private String DATA_MANAGER_STORE_PROVIDER_FACTORY_DESCRIPTION = |
129 |
"DAL store provider factories";
|
130 |
|
131 |
final static private String DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER = |
132 |
"Data.manager.feature.attribute.getter";
|
133 |
final static private String DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER_DESCRIPTION = |
134 |
"DAL feature attribute getters";
|
135 |
|
136 |
/** This map contains the name of the default provider for each data type */
|
137 |
private Map defaultDataIndexProviders; |
138 |
|
139 |
private OpenErrorHandler openErrorHandler;
|
140 |
|
141 |
private ArrayList dataTypes; |
142 |
|
143 |
public DefaultDataManager() {
|
144 |
/*
|
145 |
* Create te extensions point in te registry.
|
146 |
*/
|
147 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE, |
148 |
DATA_MANAGER_STORE_DESCRIPTION); |
149 |
|
150 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS, |
151 |
DATA_MANAGER_STORE_PARAMS_DESCRIPTION); |
152 |
|
153 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER, |
154 |
DATA_MANAGER_EXPLORER_DESCRIPTION); |
155 |
|
156 |
ToolsLocator.getExtensionPointManager().add( |
157 |
DATA_MANAGER_EXPLORER_PARAMS, |
158 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION); |
159 |
|
160 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX, |
161 |
DATA_MANAGER_INDEX_DESCRIPTION); |
162 |
|
163 |
ToolsLocator.getExtensionPointManager().add( |
164 |
DATA_MANAGER_EXPRESION_EVALUATOR, |
165 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION); |
166 |
|
167 |
ToolsLocator.getExtensionPointManager().add( |
168 |
DATA_MANAGER_STORE_PROVIDER_FACTORY, |
169 |
DATA_MANAGER_STORE_PROVIDER_FACTORY_DESCRIPTION); |
170 |
|
171 |
initializeIndexes(); |
172 |
} |
173 |
|
174 |
/**
|
175 |
*
|
176 |
* @return ResourceManager
|
177 |
*/
|
178 |
|
179 |
public ResourceManager getResourceManager() {
|
180 |
return DALLocator.getResourceManager();
|
181 |
} |
182 |
|
183 |
public OperationManager getOperationManager() {
|
184 |
return ToolsLocator.getOperationManager();
|
185 |
} |
186 |
|
187 |
public String getTemporaryDirectory() { |
188 |
// FIXME Define a better tempdir solution
|
189 |
String tmp = System.getProperty("TMP"); |
190 |
if (tmp == null) { |
191 |
tmp = System.getProperty("TEMP"); |
192 |
} |
193 |
if (tmp == null) { |
194 |
File tmp_file = new File(System.getProperty("HOME"), "_daltmp_"); |
195 |
int i = 1; |
196 |
while (!tmp_file.exists() || !tmp_file.isDirectory()) {
|
197 |
tmp_file = new File(tmp_file.getAbsolutePath() + i); |
198 |
i++; |
199 |
} |
200 |
if (!tmp_file.exists()) {
|
201 |
tmp_file.mkdir(); |
202 |
} |
203 |
tmp = tmp_file.getAbsolutePath(); |
204 |
} |
205 |
return tmp;
|
206 |
} |
207 |
|
208 |
/*
|
209 |
* ====================================================================
|
210 |
*
|
211 |
* Store related services
|
212 |
*/
|
213 |
public void registerStoreProvider(String name, Class storeProviderClass, |
214 |
Class parametersClass) {
|
215 |
if (name == null || storeProviderClass == null |
216 |
|| parametersClass == null) {
|
217 |
// FIXME Exception
|
218 |
throw new IllegalArgumentException("Any parameters can be null"); |
219 |
} |
220 |
|
221 |
if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) {
|
222 |
// FIXME Exception
|
223 |
throw new IllegalArgumentException(parametersClass.getName() |
224 |
+ " must implement org.gvsig.fmap.dal.DataStoreParameters");
|
225 |
} |
226 |
|
227 |
if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
228 |
ToolsLocator.getExtensionPointManager() |
229 |
.add(DATA_MANAGER_STORE, DATA_MANAGER_STORE_DESCRIPTION) |
230 |
.append(name, null, storeProviderClass);
|
231 |
|
232 |
ToolsLocator |
233 |
.getExtensionPointManager() |
234 |
.add(DATA_MANAGER_STORE_PARAMS, |
235 |
DATA_MANAGER_STORE_PARAMS_DESCRIPTION) |
236 |
.append(name, null, parametersClass);
|
237 |
return;
|
238 |
} |
239 |
|
240 |
if (FeatureStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
241 |
// Envuelve al proveedor en una factoria por defecto.
|
242 |
this.registerStoreProviderFactory(new DataStoreProviderToFeatureStoreProviderFactoryWrapper( |
243 |
name, "", storeProviderClass, parametersClass));
|
244 |
return;
|
245 |
} |
246 |
|
247 |
throw new IllegalArgumentException("Not supported implemtation: name=" |
248 |
+ name + " provider class=" + storeProviderClass.getName());
|
249 |
|
250 |
} |
251 |
|
252 |
public void registerStoreProviderFactory(DataStoreProviderFactory factory) { |
253 |
ExtensionPoint factories = |
254 |
ToolsLocator.getExtensionPointManager().add( |
255 |
DATA_MANAGER_STORE_PROVIDER_FACTORY, |
256 |
DATA_MANAGER_STORE_PROVIDER_FACTORY_DESCRIPTION); |
257 |
factories.append(factory.getName(), factory.getDescription(), factory); |
258 |
|
259 |
} |
260 |
|
261 |
public void registerStoreFactory(String name, Class storeProviderClass) { |
262 |
if (name == null || storeProviderClass == null) { |
263 |
// FIXME Exception
|
264 |
throw new IllegalArgumentException("Any parameters can be null"); |
265 |
} |
266 |
|
267 |
if (!(DataStoreFactory.class.isAssignableFrom(storeProviderClass))) {
|
268 |
// FIXME Exception
|
269 |
throw new IllegalArgumentException( |
270 |
"Not supported implemtation: name=" + name + " provider class=" |
271 |
+ storeProviderClass.getName()); |
272 |
} |
273 |
|
274 |
ToolsLocator |
275 |
.getExtensionPointManager() |
276 |
.add(DATA_MANAGER_STORE_FACTORY, |
277 |
DATA_MANAGER_STORE_FACTORY_DESCRIPTION) |
278 |
.append(name, null, storeProviderClass);
|
279 |
} |
280 |
|
281 |
public DataStoreParameters createStoreParameters(String name) |
282 |
throws InitializeException, ProviderNotRegisteredException {
|
283 |
try {
|
284 |
|
285 |
// Si hay una factoria para ese proveedor se los pedimos a la
|
286 |
// factoria
|
287 |
DataStoreProviderFactory providerFactory = |
288 |
(DataStoreProviderFactory) ToolsLocator |
289 |
.getExtensionPointManager() |
290 |
.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name); |
291 |
if (providerFactory != null) { |
292 |
return (DataStoreParameters) providerFactory.createParameters();
|
293 |
} |
294 |
|
295 |
// Si no hay factoria lo hacemos como se hacia antes por mantener
|
296 |
// compatibilidad.
|
297 |
DataStoreParameters params = |
298 |
(DataStoreParameters) ToolsLocator.getExtensionPointManager() |
299 |
.get(DATA_MANAGER_STORE_PARAMS).create(name); |
300 |
if (params == null) { |
301 |
throw new ProviderNotRegisteredException(name); |
302 |
} |
303 |
return params;
|
304 |
} catch (InstantiationException e) { |
305 |
throw new InitializeException(e); |
306 |
} catch (IllegalAccessException e) { |
307 |
throw new InitializeException(e); |
308 |
} catch (SecurityException e) { |
309 |
throw new InitializeException(e); |
310 |
} catch (IllegalArgumentException e) { |
311 |
throw new InitializeException(e); |
312 |
} |
313 |
} |
314 |
|
315 |
private DataStore localOpenStore(String provider, |
316 |
DataStoreParameters parameters) throws InitializeException,
|
317 |
ProviderNotRegisteredException, ValidateDataParametersException { |
318 |
String name = provider; // parameters.getDataStoreName(); |
319 |
|
320 |
parameters.validate(); |
321 |
|
322 |
DataStore store; |
323 |
try {
|
324 |
DataStoreProviderFactory providerFactory; |
325 |
providerFactory = |
326 |
(DataStoreProviderFactory) ToolsLocator |
327 |
.getExtensionPointManager() |
328 |
.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name); |
329 |
if (providerFactory != null) { |
330 |
if (FeatureStoreProviderFactory.class
|
331 |
.isAssignableFrom(providerFactory.getClass())) { |
332 |
store = new DefaultFeatureStore();
|
333 |
this.intializeDataStore(store, parameters);
|
334 |
return store;
|
335 |
} |
336 |
} |
337 |
} catch (InstantiationException e1) { |
338 |
// ignore
|
339 |
} catch (IllegalAccessException e1) { |
340 |
// ignore
|
341 |
} |
342 |
|
343 |
Extension storeProviderExtension = |
344 |
ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_STORE) |
345 |
.get(name); |
346 |
|
347 |
if (storeProviderExtension == null) { |
348 |
throw new ProviderNotRegisteredException(name); |
349 |
} |
350 |
|
351 |
Class providerClass = storeProviderExtension.getExtension();
|
352 |
if (providerClass == null) { |
353 |
throw new ProviderNotRegisteredException(name); |
354 |
} |
355 |
|
356 |
if (CoverageStoreProvider.class.isAssignableFrom(providerClass)) {
|
357 |
ExtensionPoint.Extension point = |
358 |
ToolsLocator.getExtensionPointManager() |
359 |
.get(DATA_MANAGER_STORE_FACTORY).get(name); |
360 |
DataStoreFactory factory = null;
|
361 |
try {
|
362 |
factory = (DataStoreFactory) point.create(); |
363 |
} catch (InstantiationException e) { |
364 |
throw new InitializeException(e); |
365 |
} catch (IllegalAccessException e) { |
366 |
throw new InitializeException(e); |
367 |
} |
368 |
factory.setParameters(parameters); |
369 |
store = factory.createStore(); |
370 |
} else
|
371 |
if (FeatureStoreProvider.class.isAssignableFrom(providerClass)) {
|
372 |
|
373 |
store = new DefaultFeatureStore();
|
374 |
|
375 |
} else {
|
376 |
// FIXME Exception
|
377 |
throw new InitializeException(name, new RuntimeException( |
378 |
"Not supported implemtation: name=" + name
|
379 |
+ " provider class=" + providerClass.getName()));
|
380 |
} |
381 |
|
382 |
this.intializeDataStore(store, parameters);
|
383 |
|
384 |
return store;
|
385 |
} |
386 |
|
387 |
public DataStore openStore(String provider, DataStoreParameters parameters) |
388 |
throws InitializeException, ProviderNotRegisteredException,
|
389 |
ValidateDataParametersException { |
390 |
|
391 |
return localOpenStore(provider, parameters);
|
392 |
} |
393 |
|
394 |
/**
|
395 |
* @deprecated see openStore
|
396 |
*/
|
397 |
public DataStore createStore(DataStoreParameters parameters)
|
398 |
throws InitializeException, ProviderNotRegisteredException,
|
399 |
ValidateDataParametersException { |
400 |
return openStore(parameters.getDataStoreName(), parameters);
|
401 |
} |
402 |
|
403 |
public List getStoreProviders() { |
404 |
ExtensionPointManager epmanager = |
405 |
ToolsLocator.getExtensionPointManager(); |
406 |
List names1 = epmanager.get(DATA_MANAGER_STORE).getNames();
|
407 |
List names2 =
|
408 |
epmanager.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).getNames(); |
409 |
List names3 = new ArrayList(); |
410 |
names3.addAll(names1); |
411 |
names3.addAll(names2); |
412 |
return names3;
|
413 |
} |
414 |
|
415 |
public DataStoreProviderFactory getStoreProviderFactory(String name) { |
416 |
try {
|
417 |
return (DataStoreProviderFactory) ToolsLocator
|
418 |
.getExtensionPointManager() |
419 |
.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name); |
420 |
} catch (InstantiationException e) { |
421 |
return null; |
422 |
} catch (IllegalAccessException e) { |
423 |
return null; |
424 |
} |
425 |
} |
426 |
|
427 |
public List getStoreProviders(String name) { |
428 |
return getStoreProviders(); // FIXME: need filter from the name of |
429 |
// the explorer
|
430 |
} |
431 |
|
432 |
public NewDataStoreParameters createNewStoreParameters(String explorer, |
433 |
String provider) throws InitializeException, |
434 |
ProviderNotRegisteredException { |
435 |
|
436 |
DataServerExplorerParameters parameters; |
437 |
DataServerExplorer server; |
438 |
try {
|
439 |
parameters = this.createServerExplorerParameters(explorer);
|
440 |
server = |
441 |
this.openServerExplorerWithoutValidate(explorer, parameters);
|
442 |
return server.getAddParameters(provider);
|
443 |
} catch (ValidateDataParametersException e) {
|
444 |
throw new InitializeException(e); |
445 |
} catch (DataException e) {
|
446 |
throw new InitializeException(e); |
447 |
} |
448 |
} |
449 |
|
450 |
public void newStore(String explorer, String provider, |
451 |
NewDataStoreParameters parameters, boolean overwrite)
|
452 |
throws InitializeException, ProviderNotRegisteredException,
|
453 |
ValidateDataParametersException { |
454 |
|
455 |
parameters.validate(); |
456 |
|
457 |
DataServerExplorerParameters explorerParameters; |
458 |
DataServerExplorer server; |
459 |
explorerParameters = this.createServerExplorerParameters(explorer);
|
460 |
server = |
461 |
this.openServerExplorerWithoutValidate(explorer, explorerParameters);
|
462 |
try {
|
463 |
server.add(provider, parameters, overwrite); |
464 |
} catch (DataException e) {
|
465 |
throw new InitializeException(e); |
466 |
} |
467 |
} |
468 |
|
469 |
/*
|
470 |
* ====================================================================
|
471 |
*
|
472 |
* Explorer related services
|
473 |
*/
|
474 |
public void registerExplorerProvider(String name, Class explorerClass, |
475 |
Class parametersClass) {
|
476 |
|
477 |
if (name == null || explorerClass == null || parametersClass == null) { |
478 |
// FIXME Exception
|
479 |
throw new IllegalArgumentException("Any parameters can be null"); |
480 |
} |
481 |
|
482 |
if (!DataServerExplorerParameters.class
|
483 |
.isAssignableFrom(parametersClass)) { |
484 |
// FIXME Exception
|
485 |
throw new IllegalArgumentException( |
486 |
parametersClass.getName() |
487 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorerParameters");
|
488 |
} |
489 |
|
490 |
if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) {
|
491 |
// FIXME Exception
|
492 |
throw new IllegalArgumentException(explorerClass.getName() |
493 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorer");
|
494 |
} |
495 |
|
496 |
ToolsLocator.getExtensionPointManager() |
497 |
.add(DATA_MANAGER_EXPLORER, DATA_MANAGER_EXPLORER_DESCRIPTION) |
498 |
.append(name, null, explorerClass);
|
499 |
|
500 |
ToolsLocator |
501 |
.getExtensionPointManager() |
502 |
.add(DATA_MANAGER_EXPLORER_PARAMS, |
503 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION) |
504 |
.append(name, null, parametersClass);
|
505 |
} |
506 |
|
507 |
public DataServerExplorerParameters createServerExplorerParameters(
|
508 |
String name) throws InitializeException, ProviderNotRegisteredException { |
509 |
try {
|
510 |
DataServerExplorerParameters params = |
511 |
(DataServerExplorerParameters) ToolsLocator |
512 |
.getExtensionPointManager() |
513 |
.get(DATA_MANAGER_EXPLORER_PARAMS).create(name); |
514 |
if (params == null) { |
515 |
throw new ProviderNotRegisteredException(name); |
516 |
} |
517 |
return params;
|
518 |
} catch (InstantiationException e) { |
519 |
throw new InitializeException(e); |
520 |
} catch (IllegalAccessException e) { |
521 |
throw new InitializeException(e); |
522 |
} catch (SecurityException e) { |
523 |
throw new InitializeException(e); |
524 |
} catch (IllegalArgumentException e) { |
525 |
throw new InitializeException(e); |
526 |
} |
527 |
} |
528 |
|
529 |
public DataServerExplorer openServerExplorer(String explorer, |
530 |
DataServerExplorerParameters parameters) throws InitializeException,
|
531 |
ProviderNotRegisteredException, ValidateDataParametersException { |
532 |
|
533 |
if (parameters != null) { |
534 |
parameters.validate(); |
535 |
} |
536 |
return this.openServerExplorerWithoutValidate(explorer, parameters); |
537 |
} |
538 |
|
539 |
private DataServerExplorer openServerExplorerWithoutValidate(
|
540 |
String explorerName, DataServerExplorerParameters parameters)
|
541 |
throws InitializeException, ProviderNotRegisteredException,
|
542 |
ValidateDataParametersException { |
543 |
|
544 |
String name = explorerName; // parameters.getExplorerName(); |
545 |
|
546 |
try {
|
547 |
DataServerExplorerProvider server = |
548 |
(DataServerExplorerProvider) ToolsLocator |
549 |
.getExtensionPointManager() |
550 |
.get(DATA_MANAGER_EXPLORER) |
551 |
.create( |
552 |
name, |
553 |
new Object[] { parameters, |
554 |
new DefaultDataServerExplorerProviderServices() });
|
555 |
if (server == null) { |
556 |
throw new ProviderNotRegisteredException(name); |
557 |
} |
558 |
return server;
|
559 |
} catch (InstantiationException e) { |
560 |
throw new InitializeException(e); |
561 |
} catch (IllegalAccessException e) { |
562 |
throw new InitializeException(e); |
563 |
} catch (SecurityException e) { |
564 |
throw new InitializeException(e); |
565 |
} catch (IllegalArgumentException e) { |
566 |
throw new InitializeException(e); |
567 |
} catch (NoSuchMethodException e) { |
568 |
throw new InitializeException(e); |
569 |
} catch (InvocationTargetException e) { |
570 |
throw new InitializeException(e); |
571 |
} |
572 |
} |
573 |
|
574 |
/**
|
575 |
* @deprecated see openServerExplorer
|
576 |
*/
|
577 |
public DataServerExplorer createServerExplorer(
|
578 |
DataServerExplorerParameters parameters) throws InitializeException,
|
579 |
ProviderNotRegisteredException, ValidateDataParametersException { |
580 |
return openServerExplorer(parameters.getExplorerName(), parameters);
|
581 |
} |
582 |
|
583 |
public List getExplorerProviders() { |
584 |
return ToolsLocator.getExtensionPointManager()
|
585 |
.get(DATA_MANAGER_EXPLORER).getNames(); |
586 |
} |
587 |
|
588 |
/*
|
589 |
* ====================================================================
|
590 |
*
|
591 |
* Expresion evaluation related services
|
592 |
*/
|
593 |
public Evaluator createExpresion(String expresion) |
594 |
throws InitializeException {
|
595 |
try {
|
596 |
return (Evaluator) ToolsLocator
|
597 |
.getExtensionPointManager() |
598 |
.get(DATA_MANAGER_EXPRESION_EVALUATOR) |
599 |
.create(DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
600 |
new Object[] { expresion }); |
601 |
} catch (SecurityException e) { |
602 |
throw new InitializeException(e); |
603 |
} catch (IllegalArgumentException e) { |
604 |
throw new InitializeException(e); |
605 |
} catch (NoSuchMethodException e) { |
606 |
throw new InitializeException(e); |
607 |
} catch (InstantiationException e) { |
608 |
throw new InitializeException(e); |
609 |
} catch (IllegalAccessException e) { |
610 |
throw new InitializeException(e); |
611 |
} catch (InvocationTargetException e) { |
612 |
throw new InitializeException(e); |
613 |
} |
614 |
} |
615 |
|
616 |
public void registerDefaultEvaluator(Class evaluatorClass) { |
617 |
if (!Evaluator.class.isAssignableFrom(evaluatorClass)) {
|
618 |
throw new ClassCastException(); |
619 |
} |
620 |
ToolsLocator |
621 |
.getExtensionPointManager() |
622 |
.add(DATA_MANAGER_EXPRESION_EVALUATOR, |
623 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION) |
624 |
.append(DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
625 |
"Default expresion evaluator for use in DAL", evaluatorClass);
|
626 |
} |
627 |
|
628 |
/*
|
629 |
* ====================================================================
|
630 |
*
|
631 |
* Index related services
|
632 |
*/
|
633 |
|
634 |
public List getFeatureIndexProviders() { |
635 |
return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_INDEX)
|
636 |
.getNames(); |
637 |
} |
638 |
|
639 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
640 |
defaultDataIndexProviders.put(new Integer(dataType), name); |
641 |
} |
642 |
|
643 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
644 |
return (String) defaultDataIndexProviders.get(new Integer(dataType)); |
645 |
} |
646 |
|
647 |
public FeatureIndexProviderServices createFeatureIndexProvider(String name, |
648 |
FeatureStore store, FeatureType type, String indexName,
|
649 |
FeatureAttributeDescriptor attr) throws InitializeException,
|
650 |
ProviderNotRegisteredException { |
651 |
|
652 |
if (name == null) { |
653 |
name = getDefaultFeatureIndexProviderName(attr.getType()); |
654 |
} |
655 |
|
656 |
if (name == null) { |
657 |
throw new InitializeException( |
658 |
"There not any index provider registered.", null); |
659 |
} |
660 |
|
661 |
try {
|
662 |
FeatureIndexProvider provider = |
663 |
(FeatureIndexProvider) ToolsLocator.getExtensionPointManager() |
664 |
.get(DATA_MANAGER_INDEX).create(name); |
665 |
if (provider == null) { |
666 |
throw new ProviderNotRegisteredException(name); |
667 |
} |
668 |
FeatureIndexProviderServices services = |
669 |
new DefaultFeatureIndex((FeatureStoreProviderServices) store,
|
670 |
type, provider, attr.getName(), indexName); |
671 |
services.initialize(); |
672 |
return services;
|
673 |
} catch (InstantiationException e) { |
674 |
throw new InitializeException(e); |
675 |
} catch (IllegalAccessException e) { |
676 |
throw new InitializeException(e); |
677 |
} catch (SecurityException e) { |
678 |
throw new InitializeException(e); |
679 |
} catch (IllegalArgumentException e) { |
680 |
throw new InitializeException(e); |
681 |
} |
682 |
} |
683 |
|
684 |
public void registerFeatureIndexProvider(String name, String description, |
685 |
Class clazz, int dataType) { |
686 |
ToolsLocator.getExtensionPointManager() |
687 |
.add(DATA_MANAGER_INDEX, DATA_MANAGER_INDEX_DESCRIPTION) |
688 |
.append(name, null, clazz);
|
689 |
|
690 |
if (getDefaultFeatureIndexProviderName(dataType) == null) { |
691 |
setDefaultFeatureIndexProviderName(dataType, name); |
692 |
} |
693 |
} |
694 |
|
695 |
private void initializeIndexes() { |
696 |
this.defaultDataIndexProviders = new HashMap(); |
697 |
} |
698 |
|
699 |
public void intializeDataStore(DataStore store, |
700 |
DataStoreParameters parameters) throws InitializeException,
|
701 |
ProviderNotRegisteredException { |
702 |
|
703 |
((DataStoreInitializer) store).intializePhase1(this, parameters);
|
704 |
DataStoreProvider provider = |
705 |
this.createProvider((DataStoreProviderServices) store, parameters);
|
706 |
((DataStoreInitializer) store).intializePhase2(provider); |
707 |
|
708 |
} |
709 |
|
710 |
public DataStoreProvider createProvider(
|
711 |
DataStoreProviderServices providerServices, |
712 |
DataStoreParameters parameters) throws InitializeException,
|
713 |
ProviderNotRegisteredException { |
714 |
String name = parameters.getDataStoreName();
|
715 |
DataStoreProvider provider = null;
|
716 |
boolean retry = true; |
717 |
while (retry) {
|
718 |
try {
|
719 |
DataStoreProviderFactory providerFactory = |
720 |
(DataStoreProviderFactory) ToolsLocator |
721 |
.getExtensionPointManager() |
722 |
.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name); |
723 |
if (providerFactory != null) { |
724 |
provider = |
725 |
(DataStoreProvider) providerFactory.createProvider( |
726 |
parameters, providerServices); |
727 |
} else {
|
728 |
provider = |
729 |
(DataStoreProvider) ToolsLocator |
730 |
.getExtensionPointManager() |
731 |
.get(DATA_MANAGER_STORE) |
732 |
.create(name, |
733 |
new Object[] { parameters, providerServices }); |
734 |
} |
735 |
retry = false;
|
736 |
} catch (Exception e) { |
737 |
if (openErrorHandler != null) { |
738 |
retry = openErrorHandler.canRetryOpen(e, parameters); |
739 |
} else {
|
740 |
retry = false;
|
741 |
} |
742 |
if (!retry) {
|
743 |
throw new InitializeException( |
744 |
parameters.getDataStoreName(), e); |
745 |
} |
746 |
} |
747 |
} |
748 |
if (provider == null) { |
749 |
throw new ProviderNotRegisteredException(name); |
750 |
} |
751 |
return provider;
|
752 |
} |
753 |
|
754 |
public void registerFeatureCacheProvider( |
755 |
FeatureCacheProviderFactory providerFactory) { |
756 |
ToolsLocator.getExtensionPointManager() |
757 |
.add(DATA_MANAGER_CACHE, DATA_MANAGER_CACHE_DESCRIPTION) |
758 |
.append(providerFactory.getName(), "", providerFactory);
|
759 |
} |
760 |
|
761 |
public FeatureCacheProvider createFeatureCacheProvider(String name, |
762 |
DynObject parameters) throws DataException {
|
763 |
if (name == null) { |
764 |
throw new InitializeException( |
765 |
"It is necessary to provide a cache name", null); |
766 |
} |
767 |
if (parameters == null) { |
768 |
throw new InitializeException( |
769 |
"It is necessary to provide parameters to create the explorer",
|
770 |
null);
|
771 |
} |
772 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
773 |
try {
|
774 |
featureCacheProviderFactory = |
775 |
(FeatureCacheProviderFactory) ToolsLocator |
776 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
777 |
.create(name); |
778 |
if (featureCacheProviderFactory == null) { |
779 |
throw new ProviderNotRegisteredException(name); |
780 |
} |
781 |
return featureCacheProviderFactory.createCacheProvider(parameters);
|
782 |
} catch (InstantiationException e) { |
783 |
throw new InitializeException(e); |
784 |
} catch (IllegalAccessException e) { |
785 |
throw new InitializeException(e); |
786 |
} |
787 |
} |
788 |
|
789 |
public List getFeatureCacheProviders() { |
790 |
ExtensionPoint extensionPoint = |
791 |
ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_CACHE); |
792 |
if (extensionPoint != null) { |
793 |
return ToolsLocator.getExtensionPointManager()
|
794 |
.get(DATA_MANAGER_CACHE).getNames(); |
795 |
} else {
|
796 |
return new ArrayList(); |
797 |
} |
798 |
} |
799 |
|
800 |
public DynObject createCacheParameters(String name) |
801 |
throws InitializeException, ProviderNotRegisteredException {
|
802 |
if (name == null) { |
803 |
throw new InitializeException( |
804 |
"It is necessary to provide a cache name", null); |
805 |
} |
806 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
807 |
try {
|
808 |
featureCacheProviderFactory = |
809 |
(FeatureCacheProviderFactory) ToolsLocator |
810 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
811 |
.create(name); |
812 |
if (featureCacheProviderFactory == null) { |
813 |
throw new ProviderNotRegisteredException(name); |
814 |
} |
815 |
return featureCacheProviderFactory.createParameters();
|
816 |
} catch (InstantiationException e) { |
817 |
throw new InitializeException(e); |
818 |
} catch (IllegalAccessException e) { |
819 |
throw new InitializeException(e); |
820 |
} |
821 |
} |
822 |
|
823 |
public DataStoreParameters createMemoryStoreParameters(
|
824 |
String autoOrderAttributeName) throws InitializeException { |
825 |
|
826 |
DataStoreParameters parameters; |
827 |
try {
|
828 |
parameters = createStoreParameters(MemoryStoreProvider.NAME); |
829 |
if (autoOrderAttributeName != null) { |
830 |
parameters.setDynValue( |
831 |
MemoryStoreParameters.ORDER_PARAMETER_NAME, |
832 |
autoOrderAttributeName); |
833 |
} |
834 |
return parameters;
|
835 |
} catch (ProviderNotRegisteredException e) {
|
836 |
throw new InitializeException("MemoryStoreProvider", e); |
837 |
} |
838 |
} |
839 |
|
840 |
public FeatureStore createMemoryStore(String autoOrderAttributeName) |
841 |
throws InitializeException {
|
842 |
|
843 |
DataStoreParameters parameters = |
844 |
createMemoryStoreParameters(autoOrderAttributeName); |
845 |
try {
|
846 |
return (FeatureStore) createStore(parameters);
|
847 |
} catch (ValidateDataParametersException e) {
|
848 |
throw new InitializeException("MemoryStoreProvider", e); |
849 |
} catch (ProviderNotRegisteredException e) {
|
850 |
throw new InitializeException("MemoryStoreProvider", e); |
851 |
} |
852 |
} |
853 |
|
854 |
public FeaturePagingHelper createFeaturePagingHelper(
|
855 |
FeatureStore featureStore, int pageSize) throws BaseException { |
856 |
return new FeaturePagingHelperImpl(featureStore, pageSize); |
857 |
} |
858 |
|
859 |
public FeaturePagingHelper createFeaturePagingHelper(
|
860 |
FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
|
861 |
throws BaseException {
|
862 |
return new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize); |
863 |
} |
864 |
|
865 |
public void setOpenErrorHandler(OpenErrorHandler handler) { |
866 |
openErrorHandler = handler; |
867 |
|
868 |
} |
869 |
|
870 |
public EditableFeatureType createFeatureType() {
|
871 |
return new DefaultEditableFeatureType(); |
872 |
} |
873 |
|
874 |
public List getDataTypes() { |
875 |
if (dataTypes == null) { |
876 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
877 |
dataTypes = new ArrayList(); |
878 |
dataTypes.add(manager.get(DataTypes.STRING)); |
879 |
dataTypes.add(manager.get(DataTypes.BOOLEAN)); |
880 |
dataTypes.add(manager.get(DataTypes.INT)); |
881 |
dataTypes.add(manager.get(DataTypes.DOUBLE)); |
882 |
dataTypes.add(manager.get(DataTypes.DATE)); |
883 |
dataTypes.add(manager.get(DataTypes.GEOMETRY)); |
884 |
} |
885 |
return dataTypes;
|
886 |
} |
887 |
|
888 |
public void registerFeatureAttributeGetter(String name, Class clazz) { |
889 |
if (name == null || clazz == null) { |
890 |
throw new IllegalArgumentException("Any parameters can be null"); |
891 |
} |
892 |
if(!(FeatureAttributeGetter.class.isAssignableFrom(clazz))) {
|
893 |
throw new IllegalArgumentException( |
894 |
"Not supported implemtation: name=" + name
|
895 |
+ " class=" + clazz.getName());
|
896 |
} |
897 |
} |
898 |
|
899 |
public FeatureAttributeGetter createFeatureAttributeGetter(String name) throws InitializeException { |
900 |
if (name == null) { |
901 |
throw new IllegalArgumentException("The parameter can not be null"); |
902 |
} |
903 |
|
904 |
try{
|
905 |
return (FeatureAttributeGetter) ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER).create(name);
|
906 |
} catch (InstantiationException e) { |
907 |
throw new InitializeException("FeatureAttributeGetter", e); |
908 |
} catch (IllegalAccessException e) { |
909 |
throw new InitializeException("FeatureAttributeGetter", e); |
910 |
} |
911 |
} |
912 |
} |