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