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