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