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 @ 44259
History | View | Annotate | Download (39.2 KB)
1 |
package org.gvsig.fmap.dal.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.InputStream; |
5 |
import java.net.URL; |
6 |
import java.net.URLClassLoader; |
7 |
import java.util.ArrayList; |
8 |
import java.util.Collections; |
9 |
import java.util.HashMap; |
10 |
import java.util.List; |
11 |
import java.util.Map; |
12 |
import org.apache.commons.lang3.StringUtils; |
13 |
import org.gvsig.expressionevaluator.Expression; |
14 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
15 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
16 |
|
17 |
import org.gvsig.fmap.dal.DataFactory; |
18 |
import org.gvsig.fmap.dal.DataManager; |
19 |
import org.gvsig.fmap.dal.DataServerExplorer; |
20 |
import org.gvsig.fmap.dal.DataServerExplorerFactory; |
21 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
22 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
23 |
import org.gvsig.fmap.dal.DataStore; |
24 |
import org.gvsig.fmap.dal.DataStoreFactory_v2_4; |
25 |
import org.gvsig.fmap.dal.DataStoreParameters; |
26 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
27 |
import org.gvsig.fmap.dal.DataTypes; |
28 |
|
29 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
30 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
31 |
import org.gvsig.fmap.dal.Register; |
32 |
import org.gvsig.fmap.dal.StoresRepository; |
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.exception.InitializeException; |
35 |
import org.gvsig.fmap.dal.exception.OpenException; |
36 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
37 |
import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
38 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
39 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
40 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
41 |
import org.gvsig.fmap.dal.feature.DataProfile; |
42 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
43 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
44 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
46 |
import org.gvsig.fmap.dal.feature.FeatureType; |
47 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
48 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
49 |
import org.gvsig.fmap.dal.feature.impl.FeatureStoreFactory; |
50 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
51 |
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
52 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
53 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
54 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
55 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
56 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
57 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
58 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultExpressionEvaluator; |
59 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
60 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureSymbolTable; |
61 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
62 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
63 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
64 |
import org.gvsig.fmap.dal.spi.DALSPILocator; |
65 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
66 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
67 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
68 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
69 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
70 |
import org.gvsig.tools.ToolsLocator; |
71 |
import org.gvsig.tools.dataTypes.DataType; |
72 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
73 |
import org.gvsig.tools.dynobject.DynObject; |
74 |
import org.gvsig.tools.dynobject.DynStruct; |
75 |
import org.gvsig.tools.dynobject.DynStruct_v2; |
76 |
import org.gvsig.tools.dynobject.Tags; |
77 |
import org.gvsig.tools.evaluator.Evaluator; |
78 |
import org.gvsig.tools.exception.BaseException; |
79 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
80 |
import org.gvsig.tools.folders.FoldersManager; |
81 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
82 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
83 |
import org.gvsig.tools.service.spi.Services; |
84 |
import org.gvsig.tools.util.GetItemByKey; |
85 |
import org.slf4j.Logger; |
86 |
import org.slf4j.LoggerFactory; |
87 |
|
88 |
public class DefaultDataManager |
89 |
implements DataManager, DataManagerProviderServices, Services {
|
90 |
|
91 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataManager.class); |
92 |
|
93 |
final static private String DATA_MANAGER_CACHE = "Data.manager.caches"; |
94 |
final static private String DATA_MANAGER_CACHE_DESCRIPTION = |
95 |
"DAL cache providers";
|
96 |
|
97 |
public static final String FILESYSTEM_EXPLORER_NAME = "FilesystemExplorer"; |
98 |
|
99 |
|
100 |
private class Registers { |
101 |
|
102 |
private final Register store; |
103 |
private final Register storeProvider; |
104 |
private final Register serverExplorer; |
105 |
private final Register featureIndexProvider; |
106 |
|
107 |
public Registers() {
|
108 |
this.store = new RegisterImpl( |
109 |
"Data.manager.stores.factory",
|
110 |
"DAL store factories"
|
111 |
); |
112 |
this.storeProvider = new RegisterImpl( |
113 |
"Data.manager.providers.factory",
|
114 |
"DAL store provider factories"
|
115 |
); |
116 |
this.serverExplorer = new RegisterImpl( |
117 |
"Data.manager.servereexplorer.factory",
|
118 |
"DAL server explorer factories"
|
119 |
); |
120 |
this.featureIndexProvider = new RegisterImpl( |
121 |
"Data.manager.feature.index.factory",
|
122 |
"DAL feature index factories"
|
123 |
); |
124 |
|
125 |
this.store.register(new FeatureStoreFactory()); |
126 |
} |
127 |
} |
128 |
private static final String TAG_DAL_OPENSTORE = "dal.openstore."; |
129 |
|
130 |
private final Registers registers; |
131 |
|
132 |
private final Map<Integer, String> defaultDataIndexProviders; |
133 |
|
134 |
private OpenErrorHandler openErrorHandler = null; |
135 |
|
136 |
private DataServerExplorerPool dataServerExplorerPool = null; |
137 |
|
138 |
private List<DataType> dataTypes = null; |
139 |
|
140 |
private ClassLoader resourcesLoader = null; |
141 |
|
142 |
private List<DataProfile> dataProfiles; |
143 |
|
144 |
public DefaultDataManager() {
|
145 |
this.registers = new Registers(); |
146 |
this.defaultDataIndexProviders = new HashMap<>(); |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public Register getStoreRegister() {
|
151 |
return this.registers.store; |
152 |
} |
153 |
|
154 |
@Override
|
155 |
public Register getStoreProviderRegister() {
|
156 |
return this.registers.storeProvider; |
157 |
} |
158 |
|
159 |
@Override
|
160 |
public Register getServerExplorerRegister() {
|
161 |
return this.registers.serverExplorer; |
162 |
} |
163 |
|
164 |
@Override
|
165 |
public Register getFeatureIndexRegister() {
|
166 |
return this.registers.featureIndexProvider; |
167 |
} |
168 |
|
169 |
private String getStoreName(DataStoreParameters parameters) { |
170 |
for (DataFactory factory : this.getStoreRegister()) { |
171 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) factory; |
172 |
if (storeFactory.canUse(parameters)) {
|
173 |
return storeFactory.getName();
|
174 |
} |
175 |
} |
176 |
return null; |
177 |
} |
178 |
|
179 |
/**
|
180 |
* @deprecated
|
181 |
*/
|
182 |
@Override
|
183 |
public void registerDefaultRasterStore(Class rasterStoreClass) { |
184 |
// Metodo usado por el raster nuevo para regstrar su factoria de store
|
185 |
this.getStoreRegister().register(new RasterStoreFactory(rasterStoreClass)); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* @deprecated
|
190 |
*/
|
191 |
@Override
|
192 |
public void registerStoreFactory(String name, Class storeFactoryClass) { |
193 |
// Metodo usado por el raster viejo para registrar las factorias de sus stores
|
194 |
this.getStoreRegister().register(new RasterStoreOldFactory(name, storeFactoryClass)); |
195 |
} |
196 |
|
197 |
/**
|
198 |
* @param name
|
199 |
* @param storeProviderClass
|
200 |
* @param parametersClass
|
201 |
* @deprecated use registerStoreProviderFactory
|
202 |
*/
|
203 |
@Override
|
204 |
public void registerStoreProvider(String name, Class storeProviderClass, |
205 |
Class parametersClass) {
|
206 |
if (name == null || storeProviderClass == null || parametersClass == null) { |
207 |
throw new IllegalArgumentException("Any parameters can be null"); |
208 |
} |
209 |
|
210 |
if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) {
|
211 |
throw new IllegalArgumentException(parametersClass.getName() |
212 |
+ " must implement org.gvsig.fmap.dal.DataStoreParameters");
|
213 |
} |
214 |
|
215 |
if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
216 |
// Envuelve al proveedor en una factoria por defecto.
|
217 |
this.registerStoreProviderFactory(new DataStoreProviderToCoverageProviderFactoryWrapper( |
218 |
name, "", storeProviderClass, parametersClass));
|
219 |
return;
|
220 |
} |
221 |
|
222 |
if (FeatureStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
223 |
// Envuelve al proveedor en una factoria por defecto.
|
224 |
this.registerStoreProviderFactory(new DataStoreProviderToFeatureStoreProviderFactoryWrapper( |
225 |
name, "", storeProviderClass, parametersClass));
|
226 |
return;
|
227 |
} |
228 |
|
229 |
throw new IllegalArgumentException("Not supported implemtation: name=" |
230 |
+ name + " provider class=" + storeProviderClass.getName());
|
231 |
|
232 |
} |
233 |
|
234 |
@Override
|
235 |
public void registerExplorerProvider(String name, Class explorerClass, Class parametersClass) { |
236 |
if (name == null || explorerClass == null || parametersClass == null) { |
237 |
// FIXME Exception
|
238 |
throw new IllegalArgumentException("Any parameters can be null"); |
239 |
} |
240 |
|
241 |
if (!DataServerExplorerParameters.class
|
242 |
.isAssignableFrom(parametersClass)) { |
243 |
// FIXME Exception
|
244 |
throw new IllegalArgumentException( |
245 |
parametersClass.getName() |
246 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorerParameters");
|
247 |
} |
248 |
|
249 |
if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) {
|
250 |
// FIXME Exception
|
251 |
throw new IllegalArgumentException(explorerClass.getName() |
252 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorer");
|
253 |
} |
254 |
|
255 |
// Envuelve al proveedor en una factoria por defecto.
|
256 |
this.registerServerExplorerFactory(
|
257 |
new DataServerExplorerToDataExplorerFactoryWrapper(
|
258 |
name, "", explorerClass, parametersClass
|
259 |
) |
260 |
); |
261 |
|
262 |
} |
263 |
|
264 |
@Override
|
265 |
public void registerStoreFactory(DataStoreFactory_v2_4 factory) { |
266 |
this.getStoreRegister().register(factory);
|
267 |
} |
268 |
|
269 |
@Override
|
270 |
public void registerStoreProviderFactory(DataStoreProviderFactory factory) { |
271 |
this.getStoreProviderRegister().register(factory);
|
272 |
} |
273 |
|
274 |
@Override
|
275 |
public void registerServerExplorerFactory(DataServerExplorerFactory factory) { |
276 |
this.getServerExplorerRegister().register(factory);
|
277 |
} |
278 |
|
279 |
@Override
|
280 |
public DataStoreParameters createStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
281 |
if( providerName == null ) { |
282 |
String msg = "Provider name can't be null."; |
283 |
LOGGER.warn(msg); |
284 |
throw new IllegalArgumentException(msg); |
285 |
} |
286 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
287 |
if( providerFactory == null ) { |
288 |
String msg = "Can't locate provider factory for '"+providerName+"'."; |
289 |
LOGGER.warn(msg); |
290 |
throw new IllegalArgumentException(msg); |
291 |
} |
292 |
return (DataStoreParameters) providerFactory.createParameters();
|
293 |
} |
294 |
|
295 |
@Override
|
296 |
public NewDataStoreParameters createNewStoreParameters(String explorerName, String providerName) throws InitializeException, ProviderNotRegisteredException { |
297 |
try {
|
298 |
DataServerExplorer explorer = this.openServerExplorer(explorerName, (DataServerExplorerParameters)null); |
299 |
return explorer.getAddParameters(providerName);
|
300 |
} catch (Exception ex) { |
301 |
throw new InitializeException(ex); |
302 |
} |
303 |
} |
304 |
|
305 |
@Override
|
306 |
public DataServerExplorerParameters createServerExplorerParameters(String explorerName) throws InitializeException, ProviderNotRegisteredException { |
307 |
if( explorerName == null ) { |
308 |
String msg = "Explorer name can't be null."; |
309 |
LOGGER.warn(msg); |
310 |
throw new IllegalArgumentException(msg); |
311 |
} |
312 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
313 |
if( explorerFactory == null ) { |
314 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
315 |
LOGGER.warn(msg); |
316 |
throw new IllegalArgumentException(msg); |
317 |
} |
318 |
DataServerExplorerParameters params = (DataServerExplorerParameters) explorerFactory.createParameters(); |
319 |
return params;
|
320 |
} |
321 |
|
322 |
@Override
|
323 |
public DataStoreParameters createMemoryStoreParameters(String autoOrderAttributeName) throws InitializeException { |
324 |
try {
|
325 |
DataStoreParameters parameters = createStoreParameters(MemoryStoreProvider.NAME); |
326 |
if (autoOrderAttributeName != null) { |
327 |
parameters.setDynValue( |
328 |
MemoryStoreParameters.ORDER_PARAMETER_NAME, |
329 |
autoOrderAttributeName); |
330 |
} |
331 |
return parameters;
|
332 |
} catch (Exception ex) { |
333 |
throw new InitializeException(ex); |
334 |
} |
335 |
} |
336 |
|
337 |
@Override
|
338 |
public DataServerExplorer openServerExplorer(String explorerName, DataServerExplorerParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
339 |
if( explorerName == null ) { |
340 |
String msg = "Explorer name can't be null."; |
341 |
LOGGER.warn(msg); |
342 |
throw new IllegalArgumentException(msg); |
343 |
} |
344 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
345 |
if( explorerFactory == null ) { |
346 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
347 |
LOGGER.warn(msg); |
348 |
throw new IllegalArgumentException(msg); |
349 |
} |
350 |
if (parameters == null) { |
351 |
parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
352 |
} |
353 |
DataServerExplorer explorer = (DataServerExplorer) explorerFactory.create( |
354 |
parameters, |
355 |
new DefaultDataServerExplorerProviderServices()
|
356 |
); |
357 |
return explorer;
|
358 |
} |
359 |
|
360 |
@Override
|
361 |
public DataServerExplorer openServerExplorer(String explorerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
362 |
if( arguments.length==1 && arguments[0] instanceof DataServerExplorerParameters ) { |
363 |
// Esto hace falta ya que desde scripting si se invoca a openServerExplorercon solo
|
364 |
// un parametro de tipo DataServerExplorerParameters llama ha este metodo en lugar de
|
365 |
// llamar al que toca.
|
366 |
return openServerExplorer(explorerName, (DataServerExplorerParameters)(arguments[0])); |
367 |
} |
368 |
if( explorerName == null ) { |
369 |
String msg = "Explorer name can't be null."; |
370 |
LOGGER.warn(msg); |
371 |
throw new IllegalArgumentException(msg); |
372 |
} |
373 |
if( (arguments.length % 2)!= 0 ) { |
374 |
throw new ValidateDataParametersException(); |
375 |
} |
376 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
377 |
DataServerExplorerParameters parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
378 |
for( int i=0; i<arguments.length; i+=2 ) { |
379 |
String name = (String) arguments[i]; |
380 |
Object value = arguments[i+1]; |
381 |
parameters.setDynValue(name, value); |
382 |
} |
383 |
return this.openServerExplorer(explorerName, parameters); |
384 |
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* @param parameters
|
389 |
* @return
|
390 |
* @throws org.gvsig.fmap.dal.exception.InitializeException
|
391 |
* @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
|
392 |
* @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
|
393 |
* @deprecated see openServerExplorer
|
394 |
*/
|
395 |
@Override
|
396 |
public DataServerExplorer createServerExplorer(
|
397 |
DataServerExplorerParameters parameters) throws InitializeException,
|
398 |
ProviderNotRegisteredException, ValidateDataParametersException { |
399 |
return openServerExplorer(parameters.getExplorerName(), parameters);
|
400 |
} |
401 |
|
402 |
/**
|
403 |
* @deprecated use openStore
|
404 |
* @param parameters
|
405 |
* @return
|
406 |
* @throws InitializeException
|
407 |
* @throws ProviderNotRegisteredException
|
408 |
* @throws ValidateDataParametersException
|
409 |
*/
|
410 |
@Override
|
411 |
public DataStore createStore(DataStoreParameters parameters)
|
412 |
throws InitializeException, ProviderNotRegisteredException,
|
413 |
ValidateDataParametersException { |
414 |
return openStore(parameters.getDataStoreName(), parameters);
|
415 |
} |
416 |
|
417 |
@Override
|
418 |
public DataStore openStore(String providerName, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
419 |
if( providerName == null ) { |
420 |
String msg = "Provider name can't be null."; |
421 |
LOGGER.warn(msg); |
422 |
throw new IllegalArgumentException(msg); |
423 |
} |
424 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
425 |
if (!identityManager.getCurrentIdentity().isAuthorized(READ_STORE_AUTHORIZATION, parameters, providerName)) {
|
426 |
throw new UnauthorizedException(READ_STORE_AUTHORIZATION, parameters, providerName); |
427 |
} |
428 |
|
429 |
parameters.validate(); |
430 |
|
431 |
String storeName = this.getStoreName(parameters); |
432 |
if( StringUtils.isEmpty(storeName) ) {
|
433 |
String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
434 |
LOGGER.warn(msg); |
435 |
throw new IllegalArgumentException(msg); |
436 |
} |
437 |
|
438 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
439 |
if( storeFactory == null ) { |
440 |
String msg = "Can't locate store factory for '"+storeName+"'."; |
441 |
LOGGER.warn(msg); |
442 |
throw new IllegalArgumentException(msg); |
443 |
} |
444 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
445 |
if( providerFactory == null ) { |
446 |
String msg = "Can't locate provider factory for '"+providerName+"'."; |
447 |
LOGGER.warn(msg); |
448 |
throw new IllegalArgumentException(msg); |
449 |
} |
450 |
|
451 |
DataStore store = (DataStore) storeFactory.create(parameters, this);
|
452 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create(parameters, store); |
453 |
|
454 |
storeFactory.setProvider(store, provider); |
455 |
return store;
|
456 |
} |
457 |
|
458 |
public DataStore openStore(DataStoreParameters parameters, DataStoreProvider provider) {
|
459 |
String storeName = this.getStoreName(parameters); |
460 |
if( StringUtils.isEmpty(storeName) ) {
|
461 |
String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
462 |
LOGGER.warn(msg); |
463 |
throw new IllegalArgumentException(msg); |
464 |
} |
465 |
|
466 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
467 |
if( storeFactory == null ) { |
468 |
String msg = "Can't locate store factory for '"+storeName+"'."; |
469 |
LOGGER.warn(msg); |
470 |
throw new IllegalArgumentException(msg); |
471 |
} |
472 |
DataStore store = (DataStore) storeFactory.create(parameters, this);
|
473 |
storeFactory.setProvider(store, provider); |
474 |
return store;
|
475 |
} |
476 |
|
477 |
@Override
|
478 |
public DataStore openStore(String provider, DynObject parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
479 |
DataStoreParameters params = toDataStoreParameters(provider, parameters); |
480 |
DataStore store = openStore(params.getDataStoreName(), params); |
481 |
return store;
|
482 |
} |
483 |
|
484 |
@Override
|
485 |
public DataStore openStore(String providerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
486 |
if( arguments.length == 1 ) { |
487 |
// Desde jython entra por este metodo en lugar de los especificos
|
488 |
// de DataStoreParameters o DynObject
|
489 |
if( arguments[0] instanceof DataStoreParameters ) { |
490 |
return this.openStore(providerName, (DataStoreParameters)(arguments[0])); |
491 |
} else if( arguments[0] instanceof DynObject ) { |
492 |
return this.openStore(providerName, (DynObject)(arguments[0])); |
493 |
} |
494 |
} |
495 |
if( (arguments.length % 2)!= 0 ) { |
496 |
throw new ValidateDataParametersException(); |
497 |
} |
498 |
if( providerName == null ) { |
499 |
String msg = "Provider name can't be null."; |
500 |
LOGGER.warn(msg); |
501 |
throw new IllegalArgumentException(msg); |
502 |
} |
503 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
504 |
DataStoreParameters parameters = (DataStoreParameters) providerFactory.createParameters(); |
505 |
for( int i=0; i<arguments.length; i+=2 ) { |
506 |
String name = (String) arguments[i]; |
507 |
Object value = arguments[i+1]; |
508 |
parameters.setDynValue(name, value); |
509 |
} |
510 |
return this.openStore(providerName, parameters); |
511 |
} |
512 |
|
513 |
@Override
|
514 |
public FeatureStore createMemoryStore(String autoOrderAttributeName) throws InitializeException { |
515 |
try {
|
516 |
DataStoreParameters parameters = createMemoryStoreParameters(autoOrderAttributeName); |
517 |
DataStore store = openStore(MemoryStoreProvider.NAME, parameters); |
518 |
return (FeatureStore) store;
|
519 |
} catch (Exception ex) { |
520 |
throw new InitializeException(ex); |
521 |
} |
522 |
} |
523 |
|
524 |
@Override
|
525 |
public DataStoreProviderFactory getStoreProviderFactory(String providerName) { |
526 |
if( providerName == null ) { |
527 |
String msg = "Provider name can't be null."; |
528 |
LOGGER.warn(msg); |
529 |
throw new IllegalArgumentException(msg); |
530 |
} |
531 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
532 |
return (DataStoreProviderFactory) providerFactory;
|
533 |
} |
534 |
|
535 |
@Override
|
536 |
public List<String> getStoreProviders() { |
537 |
return this.getStoreProviderRegister().getFactoryNames(); |
538 |
} |
539 |
|
540 |
@Override
|
541 |
public List<String> getStoreProviders(String explorerName) { |
542 |
if( explorerName == null ) { |
543 |
String msg = "Explorer name can't be null."; |
544 |
LOGGER.warn(msg); |
545 |
throw new IllegalArgumentException(msg); |
546 |
} |
547 |
try {
|
548 |
DataServerExplorer explorer = openServerExplorer(explorerName, (DataServerExplorerParameters)null);
|
549 |
List names = explorer.getDataStoreProviderNames();
|
550 |
return names;
|
551 |
} catch (Exception ex) { |
552 |
throw new RuntimeException("Can't get stores availables for explorer '" + explorerName + "'.", ex); |
553 |
} |
554 |
} |
555 |
|
556 |
@Override
|
557 |
public List<String> getExplorerProviders() { |
558 |
List<String> names = this.getServerExplorerRegister().getFactoryNames(); |
559 |
return names;
|
560 |
} |
561 |
|
562 |
@Override
|
563 |
public DataStoreProvider createProvider(DataStoreProviderServices providerServices, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException { |
564 |
|
565 |
String providerName = parameters.getDataStoreName();
|
566 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
567 |
if (providerFactory == null) { |
568 |
throw new ProviderNotRegisteredException(providerName); |
569 |
} |
570 |
while (true) { |
571 |
try {
|
572 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create( |
573 |
parameters, providerServices |
574 |
); |
575 |
return provider;
|
576 |
} catch (Exception e) { |
577 |
if (openErrorHandler == null) { |
578 |
throw new InitializeException(providerName, e); |
579 |
} |
580 |
boolean retry = openErrorHandler.canRetryOpen(e, parameters);
|
581 |
if (!retry) {
|
582 |
throw new InitializeException(providerName, e); |
583 |
} |
584 |
} |
585 |
} |
586 |
} |
587 |
|
588 |
@Override
|
589 |
public List<String> getFeatureIndexProviders() { |
590 |
List<String> names = this.getFeatureIndexRegister().getFactoryNames(); |
591 |
return names;
|
592 |
} |
593 |
|
594 |
@Override
|
595 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
596 |
this.defaultDataIndexProviders.put(dataType, name);
|
597 |
} |
598 |
|
599 |
@Override
|
600 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
601 |
return this.defaultDataIndexProviders.get(dataType); |
602 |
} |
603 |
|
604 |
@Override
|
605 |
public FeatureIndexProviderServices createFeatureIndexProvider(
|
606 |
String name,
|
607 |
FeatureStore store, |
608 |
FeatureType type, |
609 |
String indexName,
|
610 |
FeatureAttributeDescriptor attr |
611 |
) throws InitializeException, ProviderNotRegisteredException {
|
612 |
|
613 |
if (name == null) { |
614 |
name = getDefaultFeatureIndexProviderName(attr.getType()); |
615 |
} |
616 |
|
617 |
if (name == null) { |
618 |
throw new InitializeException( |
619 |
"There not any index provider registered.", null); |
620 |
} |
621 |
DataFactory indexfactory = this.getFeatureIndexRegister().getFactory(name);
|
622 |
if (indexfactory == null) { |
623 |
throw new InitializeException( |
624 |
"There not any index provider registered with name '" + name + "'.", null); |
625 |
|
626 |
} |
627 |
FeatureIndexProvider provider = (FeatureIndexProvider) indexfactory.create(null, null); |
628 |
|
629 |
FeatureIndexProviderServices services = new DefaultFeatureIndex(
|
630 |
(FeatureStoreProviderServices) store, |
631 |
type, |
632 |
provider, |
633 |
attr.getName(), |
634 |
indexName |
635 |
); |
636 |
services.initialize(); |
637 |
return services;
|
638 |
|
639 |
} |
640 |
|
641 |
@Override
|
642 |
public String getTemporaryDirectory() { |
643 |
FoldersManager manager = ToolsLocator.getFoldersManager(); |
644 |
File folder = manager.getUniqueTemporaryFile("_daltmp_"); |
645 |
return folder.getAbsolutePath();
|
646 |
} |
647 |
|
648 |
@Override
|
649 |
public DataStoreParameters createStoreParameters(DynStruct struct) throws InitializeException, ProviderNotRegisteredException { |
650 |
if (!(struct instanceof DynStruct_v2)) { |
651 |
throw new IllegalArgumentException("A DynStruct_v2 is required."); |
652 |
} |
653 |
Tags tags = ((DynStruct_v2) struct).getTags(); |
654 |
return this.createStoreParameters(tags); |
655 |
} |
656 |
|
657 |
@Override
|
658 |
public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException { |
659 |
String providerName = (String) tags.get(TAG_DAL_OPENSTORE + "provider"); |
660 |
if (providerName == null) { |
661 |
throw new IllegalArgumentException("Tag DAL.OpenStore.provider is missing in struct."); |
662 |
} |
663 |
int prefixlen = TAG_DAL_OPENSTORE.length();
|
664 |
DataStoreParameters parameters = this.createStoreParameters(providerName);
|
665 |
for (String key : tags) { |
666 |
if (key.startsWith(TAG_DAL_OPENSTORE)) {
|
667 |
parameters.setDynValue(key.substring(prefixlen), tags.get(key)); |
668 |
} |
669 |
} |
670 |
return parameters;
|
671 |
} |
672 |
|
673 |
@Override
|
674 |
public DataStore openStore(DynStruct struct) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
675 |
DataStoreParameters paramters = this.createStoreParameters(struct);
|
676 |
DataStore store = this.openStore(paramters.getDataStoreName(), paramters);
|
677 |
return store;
|
678 |
} |
679 |
|
680 |
@Override
|
681 |
public void newStore(String explorerName, String providerName, NewDataStoreParameters parameters, boolean overwrite) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
682 |
if( explorerName == null ) { |
683 |
String msg = "Explorer name can't be null."; |
684 |
LOGGER.warn(msg); |
685 |
throw new IllegalArgumentException(msg); |
686 |
} |
687 |
if( providerName == null ) { |
688 |
String msg = "Provider name can't be null."; |
689 |
LOGGER.warn(msg); |
690 |
throw new IllegalArgumentException(msg); |
691 |
} |
692 |
|
693 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
694 |
if (!identityManager.getCurrentIdentity().isAuthorized(CREATE_STORE_AUTHORIZATION, parameters, providerName)) {
|
695 |
throw new UnauthorizedException(CREATE_STORE_AUTHORIZATION, parameters, providerName); |
696 |
} |
697 |
parameters.validate(); |
698 |
try {
|
699 |
DataServerExplorerParameters explorerParameters = this.createServerExplorerParameters(explorerName);
|
700 |
DataServerExplorer server = this.openServerExplorer(explorerName, explorerParameters);
|
701 |
server.add(providerName, parameters, overwrite); |
702 |
} catch (Exception e) { |
703 |
throw new InitializeException(e); |
704 |
} |
705 |
} |
706 |
|
707 |
@Override
|
708 |
@Deprecated
|
709 |
public Evaluator createExpresion(String expression) throws InitializeException { |
710 |
Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
711 |
exp.setPhrase(expression); |
712 |
return this.createExpresion(exp); |
713 |
} |
714 |
|
715 |
@Override
|
716 |
@Deprecated
|
717 |
public Evaluator createExpresion(Expression expression) throws InitializeException { |
718 |
DefaultExpressionEvaluator exp = new DefaultExpressionEvaluator(expression);
|
719 |
return exp;
|
720 |
} |
721 |
|
722 |
|
723 |
@Override
|
724 |
public Evaluator createFilter(String expression) throws InitializeException { |
725 |
Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
726 |
exp.setPhrase(expression); |
727 |
return this.createFilter(exp); |
728 |
} |
729 |
|
730 |
@Override
|
731 |
public Evaluator createFilter(Expression expression) throws InitializeException { |
732 |
DefaultExpressionEvaluator exp = new DefaultExpressionEvaluator(expression);
|
733 |
return exp;
|
734 |
} |
735 |
|
736 |
@Override
|
737 |
public FeaturePagingHelper createFeaturePagingHelper(
|
738 |
FeatureStore featureStore, int pageSize) throws BaseException { |
739 |
return new FeaturePagingHelperImpl(featureStore, pageSize); |
740 |
} |
741 |
|
742 |
@Override
|
743 |
public FeaturePagingHelper createFeaturePagingHelper(
|
744 |
FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
|
745 |
throws BaseException {
|
746 |
return new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize); |
747 |
} |
748 |
|
749 |
@Override
|
750 |
public void setOpenErrorHandler(OpenErrorHandler handler) { |
751 |
openErrorHandler = handler; |
752 |
} |
753 |
|
754 |
@Override
|
755 |
public OpenErrorHandler getOpenErrorHandler() {
|
756 |
return this.openErrorHandler; |
757 |
} |
758 |
|
759 |
@Override
|
760 |
public EditableFeatureType createFeatureType() {
|
761 |
return new DefaultEditableFeatureType(null); |
762 |
} |
763 |
|
764 |
@Override
|
765 |
public DataServerExplorerPool getDataServerExplorerPool() {
|
766 |
if (this.dataServerExplorerPool == null) { |
767 |
this.dataServerExplorerPool = new DefaultDataServerExplorerPool(); |
768 |
} |
769 |
return this.dataServerExplorerPool; |
770 |
} |
771 |
|
772 |
@Override
|
773 |
public void setDataServerExplorerPool(DataServerExplorerPool pool) { |
774 |
this.dataServerExplorerPool = pool;
|
775 |
} |
776 |
|
777 |
public DataStoreParameters toDataStoreParameters(String provider, DynObject params) throws InitializeException, ProviderNotRegisteredException { |
778 |
if (params instanceof DataStoreParameters) { |
779 |
return (DataStoreParameters) params;
|
780 |
} |
781 |
String providerName;
|
782 |
try {
|
783 |
providerName = (String) params.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
|
784 |
} catch (Exception ex) { |
785 |
providerName = provider; |
786 |
} |
787 |
DataStoreParameters parameters = this.createStoreParameters(providerName);
|
788 |
ToolsLocator.getDynObjectManager().copy(params, parameters); |
789 |
return parameters;
|
790 |
} |
791 |
|
792 |
@Override
|
793 |
public List<DataType> getDataTypes() { |
794 |
if (dataTypes == null) { |
795 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
796 |
dataTypes = new ArrayList<>(); |
797 |
dataTypes.add(manager.get(DataTypes.STRING)); |
798 |
dataTypes.add(manager.get(DataTypes.BOOLEAN)); |
799 |
dataTypes.add(manager.get(DataTypes.INT)); |
800 |
dataTypes.add(manager.get(DataTypes.DOUBLE)); |
801 |
dataTypes.add(manager.get(DataTypes.DATE)); |
802 |
dataTypes.add(manager.get(DataTypes.GEOMETRY)); |
803 |
} |
804 |
return dataTypes;
|
805 |
} |
806 |
|
807 |
@Override
|
808 |
public void setResourcesLoader(ClassLoader loader) { |
809 |
this.resourcesLoader = loader;
|
810 |
} |
811 |
|
812 |
@Override
|
813 |
public void setResourcesLoader(File folder) { |
814 |
if (folder == null) { |
815 |
this.resourcesLoader = null; |
816 |
return;
|
817 |
} |
818 |
try {
|
819 |
URL[] urls = new URL[]{folder.toURI().toURL()}; |
820 |
this.resourcesLoader = new URLClassLoader(urls); |
821 |
} catch (Exception ex) { |
822 |
throw new IllegalArgumentException("Can't create a ClassLoader from '" + folder.toString() + "'.", ex); |
823 |
} |
824 |
} |
825 |
|
826 |
@Override
|
827 |
public URL getResource(Object reourceLoader, String name) { |
828 |
URL x;
|
829 |
if (this.resourcesLoader != null) { |
830 |
x = this.resourcesLoader.getResource(name);
|
831 |
if (x != null) { |
832 |
return x;
|
833 |
} |
834 |
} |
835 |
x = reourceLoader.getClass().getResource(name); |
836 |
return x;
|
837 |
} |
838 |
|
839 |
@Override
|
840 |
public InputStream getResourceAsStream(Object reourceLoader, String name) { |
841 |
InputStream x;
|
842 |
if (this.resourcesLoader != null) { |
843 |
x = this.resourcesLoader.getResourceAsStream(name);
|
844 |
if (x != null) { |
845 |
return x;
|
846 |
} |
847 |
} |
848 |
x = reourceLoader.getClass().getResourceAsStream(name); |
849 |
return x;
|
850 |
} |
851 |
|
852 |
@Override
|
853 |
public ExpressionBuilder createExpressionBuilder() {
|
854 |
return ExpressionEvaluatorLocator.getManager().createExpressionBuilder();
|
855 |
} |
856 |
|
857 |
public void registerFeatureCacheProvider( |
858 |
FeatureCacheProviderFactory providerFactory) { |
859 |
ToolsLocator.getExtensionPointManager() |
860 |
.add(DATA_MANAGER_CACHE, DATA_MANAGER_CACHE_DESCRIPTION) |
861 |
.append(providerFactory.getName(), "", providerFactory);
|
862 |
} |
863 |
|
864 |
public FeatureCacheProvider createFeatureCacheProvider(String name, |
865 |
DynObject parameters) throws DataException {
|
866 |
if (name == null) { |
867 |
throw new InitializeException( |
868 |
"It is necessary to provide a cache name", null); |
869 |
} |
870 |
if (parameters == null) { |
871 |
throw new InitializeException( |
872 |
"It is necessary to provide parameters to create the explorer",
|
873 |
null);
|
874 |
} |
875 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
876 |
try {
|
877 |
featureCacheProviderFactory = |
878 |
(FeatureCacheProviderFactory) ToolsLocator |
879 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
880 |
.create(name); |
881 |
if (featureCacheProviderFactory == null) { |
882 |
throw new ProviderNotRegisteredException(name); |
883 |
} |
884 |
return featureCacheProviderFactory.createCacheProvider(parameters);
|
885 |
} catch (InstantiationException e) { |
886 |
throw new InitializeException(e); |
887 |
} catch (IllegalAccessException e) { |
888 |
throw new InitializeException(e); |
889 |
} |
890 |
} |
891 |
|
892 |
@Override
|
893 |
public List getFeatureCacheProviders() { |
894 |
ExtensionPoint extensionPoint = |
895 |
ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_CACHE); |
896 |
if (extensionPoint != null) { |
897 |
return ToolsLocator.getExtensionPointManager()
|
898 |
.get(DATA_MANAGER_CACHE).getNames(); |
899 |
} else {
|
900 |
return new ArrayList(); |
901 |
} |
902 |
} |
903 |
|
904 |
@Override
|
905 |
public DynObject createCacheParameters(String name) |
906 |
throws InitializeException, ProviderNotRegisteredException {
|
907 |
if (name == null) { |
908 |
throw new InitializeException( |
909 |
"It is necessary to provide a cache name", null); |
910 |
} |
911 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
912 |
try {
|
913 |
featureCacheProviderFactory = |
914 |
(FeatureCacheProviderFactory) ToolsLocator |
915 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
916 |
.create(name); |
917 |
if (featureCacheProviderFactory == null) { |
918 |
throw new ProviderNotRegisteredException(name); |
919 |
} |
920 |
return featureCacheProviderFactory.createParameters();
|
921 |
} catch (InstantiationException e) { |
922 |
throw new InitializeException(e); |
923 |
} catch (IllegalAccessException e) { |
924 |
throw new InitializeException(e); |
925 |
} |
926 |
} |
927 |
|
928 |
@Override
|
929 |
public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException { |
930 |
DataManagerProviderServices dataManager = DALSPILocator.getDataManagerProviderServices(); |
931 |
DataServerExplorerParameters eparams = null;
|
932 |
DataServerExplorer serverExplorer; |
933 |
try {
|
934 |
serverExplorer = dataManager.openServerExplorer(FILESYSTEM_EXPLORER_NAME, eparams); |
935 |
} catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
936 |
throw new OpenException(FILESYSTEM_EXPLORER_NAME, e); |
937 |
} |
938 |
|
939 |
try {
|
940 |
serverExplorer.add(providerName, params, overwrite); |
941 |
} catch (DataException e) {
|
942 |
throw new CreateFileStoreException(e, providerName); |
943 |
} |
944 |
} |
945 |
|
946 |
@Override
|
947 |
public FeatureSymbolTable createFeatureSymbolTable() {
|
948 |
FeatureSymbolTable symbolTable = new DefaultFeatureSymbolTable();
|
949 |
return symbolTable;
|
950 |
} |
951 |
|
952 |
@Override
|
953 |
public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression) { |
954 |
FeatureAttributeEmulatorExpression emulator = new DefaultFeatureAttributeEmulatorExpression(type, expression);
|
955 |
return emulator;
|
956 |
} |
957 |
|
958 |
@Override
|
959 |
public void registerDataProfile(DataProfile profile) { |
960 |
if( profile==null ) { |
961 |
return;
|
962 |
} |
963 |
if( this.dataProfiles==null ) { |
964 |
this.dataProfiles = new ArrayList<>(); |
965 |
this.dataProfiles.add(profile);
|
966 |
return;
|
967 |
} |
968 |
for (DataProfile theProfile : this.dataProfiles) { |
969 |
if( theProfile.getID().equalsIgnoreCase(profile.getID()) ) {
|
970 |
return;
|
971 |
} |
972 |
} |
973 |
this.dataProfiles.add(profile);
|
974 |
} |
975 |
|
976 |
@Override
|
977 |
public List<DataProfile> getDataProfiles() { |
978 |
if( this.dataProfiles==null ) { |
979 |
return null; |
980 |
} |
981 |
return Collections.unmodifiableList(this.dataProfiles); |
982 |
} |
983 |
|
984 |
@Override
|
985 |
public DataProfile getDataProfile(String name) { |
986 |
if( StringUtils.isBlank(name) ) {
|
987 |
return null; |
988 |
} |
989 |
for (DataProfile theProfile : this.dataProfiles) { |
990 |
if( name.equalsIgnoreCase(theProfile.getName()) ) {
|
991 |
return theProfile;
|
992 |
} |
993 |
} |
994 |
return null; |
995 |
} |
996 |
|
997 |
private StoresRepository storesRepository;
|
998 |
|
999 |
@Override
|
1000 |
public StoresRepository getStoresRepository() {
|
1001 |
if( this.storesRepository==null ) { |
1002 |
this.storesRepository = new DefaultStoresRepository(); |
1003 |
} |
1004 |
return this.storesRepository; |
1005 |
} |
1006 |
|
1007 |
@Override
|
1008 |
public void addStoresRepository(String name, GetItemByKey<String,DataStoreParameters> repository) { |
1009 |
((DefaultStoresRepository)this.getStoresRepository()).add(name, repository);
|
1010 |
} |
1011 |
|
1012 |
} |