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