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