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