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 @ 45696
History | View | Annotate | Download (57.9 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.HashSet; |
11 |
import java.util.List; |
12 |
import java.util.Map; |
13 |
import java.util.Objects; |
14 |
import java.util.Set; |
15 |
import java.util.UUID; |
16 |
import java.util.function.Predicate; |
17 |
import javax.json.JsonArray; |
18 |
import javax.json.JsonObject; |
19 |
import javax.json.JsonValue; |
20 |
import org.apache.commons.io.IOUtils; |
21 |
import org.apache.commons.lang3.StringUtils; |
22 |
import org.gvsig.expressionevaluator.Expression; |
23 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
24 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
25 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
26 |
import org.gvsig.expressionevaluator.impl.DefaultDALExpressionBuilder; |
27 |
import org.gvsig.expressionevaluator.impl.symboltable.FeatureSymbolTableImpl; |
28 |
import org.gvsig.fmap.dal.BaseStoresRepository; |
29 |
import org.gvsig.fmap.dal.DALLocator; |
30 |
import org.gvsig.fmap.dal.DataFactory; |
31 |
import org.gvsig.fmap.dal.DataManager; |
32 |
import org.gvsig.fmap.dal.DataServerExplorer; |
33 |
import org.gvsig.fmap.dal.DataServerExplorerFactory; |
34 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
35 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
36 |
import org.gvsig.fmap.dal.DataStore; |
37 |
import org.gvsig.fmap.dal.DataStoreFactory_v2_4; |
38 |
import org.gvsig.fmap.dal.DataStoreNotification; |
39 |
import org.gvsig.fmap.dal.DataStoreParameters; |
40 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
41 |
import org.gvsig.fmap.dal.DataTransaction; |
42 |
import org.gvsig.fmap.dal.DataTypes; |
43 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
44 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager.DatabaseWorkspaceListener; |
45 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
46 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
47 |
import org.gvsig.fmap.dal.Register; |
48 |
import org.gvsig.fmap.dal.StoresRepository; |
49 |
import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
50 |
import org.gvsig.fmap.dal.exception.DataException; |
51 |
import org.gvsig.fmap.dal.exception.InitializeException; |
52 |
import org.gvsig.fmap.dal.exception.OpenException; |
53 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
54 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
55 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
56 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
57 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
58 |
import org.gvsig.fmap.dal.feature.DataProfile; |
59 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
60 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
61 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
62 |
import org.gvsig.fmap.dal.feature.Feature; |
63 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
64 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
65 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
66 |
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable; |
67 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
68 |
import org.gvsig.fmap.dal.feature.FeatureType; |
69 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
70 |
import static org.gvsig.fmap.dal.feature.ForeingKey.MAX_AVAILABLE_VALUES; |
71 |
import org.gvsig.fmap.dal.feature.impl.DALFile; |
72 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureAttributeDescriptor; |
73 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
74 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
75 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
76 |
import org.gvsig.fmap.dal.feature.impl.FeatureStoreFactory; |
77 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
78 |
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
79 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
80 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
81 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
82 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
83 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
84 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
85 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
86 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureExpressionEvaluator; |
87 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
88 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
89 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
90 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
91 |
import org.gvsig.fmap.dal.spi.DALSPILocator; |
92 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
93 |
import org.gvsig.fmap.dal.spi.DataServerExplorerPoolImpl; |
94 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
95 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
96 |
import static org.gvsig.fmap.dal.spi.DataStoreProviderServices.PROVIDER_PARAMTER_NAME; |
97 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
98 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
99 |
import org.gvsig.json.Json; |
100 |
import org.gvsig.tools.ToolsLocator; |
101 |
import org.gvsig.tools.dataTypes.DataType; |
102 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
103 |
import org.gvsig.tools.dispose.DisposeUtils; |
104 |
import org.gvsig.tools.dynobject.DynObject; |
105 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
106 |
import org.gvsig.tools.dynobject.DynStruct; |
107 |
import org.gvsig.tools.dynobject.DynStruct_v2; |
108 |
import org.gvsig.tools.dynobject.Tags; |
109 |
import org.gvsig.tools.evaluator.Evaluator; |
110 |
import org.gvsig.tools.exception.BaseException; |
111 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
112 |
import org.gvsig.tools.folders.FoldersManager; |
113 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
114 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
115 |
import org.gvsig.tools.observer.Observer; |
116 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
117 |
import org.gvsig.tools.script.Script; |
118 |
import org.gvsig.tools.script.ScriptManager; |
119 |
import org.gvsig.tools.service.spi.Services; |
120 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
121 |
import org.gvsig.tools.util.Factory; |
122 |
import org.slf4j.Logger; |
123 |
import org.slf4j.LoggerFactory; |
124 |
|
125 |
@SuppressWarnings("UseSpecificCatch") |
126 |
public class DefaultDataManager |
127 |
implements DataManager, DataManagerProviderServices, Services {
|
128 |
|
129 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataManager.class); |
130 |
|
131 |
final static private String DATA_MANAGER_CACHE = "Data.manager.caches"; |
132 |
final static private String DATA_MANAGER_CACHE_DESCRIPTION = |
133 |
"DAL cache providers";
|
134 |
|
135 |
public static final String FILESYSTEM_EXPLORER_NAME = "FilesystemExplorer"; |
136 |
|
137 |
public static final long DEFAULT_MAX_SIZE_FOR_SMALL_FEATURE_SELECTION = 2000000000; |
138 |
|
139 |
private class Registers { |
140 |
|
141 |
private final Register store; |
142 |
private final Register storeProvider; |
143 |
private final Register serverExplorer; |
144 |
private final Register featureIndexProvider; |
145 |
|
146 |
public Registers() {
|
147 |
this.store = new RegisterImpl( |
148 |
"Data.manager.stores.factory",
|
149 |
"DAL store factories"
|
150 |
); |
151 |
this.storeProvider = new RegisterImpl( |
152 |
"Data.manager.providers.factory",
|
153 |
"DAL store provider factories"
|
154 |
); |
155 |
this.serverExplorer = new RegisterImpl( |
156 |
"Data.manager.servereexplorer.factory",
|
157 |
"DAL server explorer factories"
|
158 |
); |
159 |
this.featureIndexProvider = new RegisterImpl( |
160 |
"Data.manager.feature.index.factory",
|
161 |
"DAL feature index factories"
|
162 |
); |
163 |
|
164 |
this.store.register(new FeatureStoreFactory()); |
165 |
} |
166 |
} |
167 |
private static final String TAG_DAL_OPENSTORE = "dal.openstore."; |
168 |
|
169 |
private final Registers registers; |
170 |
|
171 |
private final Map<Integer, String> defaultDataIndexProviders; |
172 |
|
173 |
private OpenErrorHandler openErrorHandler = null; |
174 |
|
175 |
private DataServerExplorerPool dataServerExplorerPool = null; |
176 |
|
177 |
private List<DataType> dataTypes = null; |
178 |
|
179 |
private ClassLoader resourcesLoader = null; |
180 |
|
181 |
private List<DataProfile> dataProfiles; |
182 |
|
183 |
private final Map<String, DatabaseWorkspaceManager> databaseWorkspaces = new HashMap<>(); |
184 |
|
185 |
private final Map<String,DatabaseWorkspaceListener> addDatabaseWorkspaceListeners = new HashMap<>(); |
186 |
|
187 |
private final Set<Observer>storeObservers = new HashSet<>(); |
188 |
|
189 |
private long maxSizeForSmallFeatureSelection; |
190 |
|
191 |
private Factory largeMapFactory;
|
192 |
private Factory largeSetFactory;
|
193 |
|
194 |
public DefaultDataManager() {
|
195 |
this.registers = new Registers(); |
196 |
this.defaultDataIndexProviders = new HashMap<>(); |
197 |
this.maxSizeForSmallFeatureSelection = DEFAULT_MAX_SIZE_FOR_SMALL_FEATURE_SELECTION;
|
198 |
this.largeMapFactory = new Factory() { |
199 |
@Override
|
200 |
public String getName() { |
201 |
return "HashMapFactory"; |
202 |
} |
203 |
|
204 |
@Override
|
205 |
public Object create(Object... parameters) { |
206 |
return new HashMap(); |
207 |
} |
208 |
}; |
209 |
this.largeSetFactory = new Factory() { |
210 |
@Override
|
211 |
public String getName() { |
212 |
return "HashSetFactory"; |
213 |
} |
214 |
|
215 |
@Override
|
216 |
public Object create(Object... parameters) { |
217 |
return new HashSet(); |
218 |
} |
219 |
}; |
220 |
} |
221 |
|
222 |
@Override
|
223 |
public Register getStoreRegister() {
|
224 |
return this.registers.store; |
225 |
} |
226 |
|
227 |
@Override
|
228 |
public Register getStoreProviderRegister() {
|
229 |
return this.registers.storeProvider; |
230 |
} |
231 |
|
232 |
@Override
|
233 |
public Register getServerExplorerRegister() {
|
234 |
return this.registers.serverExplorer; |
235 |
} |
236 |
|
237 |
@Override
|
238 |
public Register getFeatureIndexRegister() {
|
239 |
return this.registers.featureIndexProvider; |
240 |
} |
241 |
|
242 |
private String getStoreName(DataStoreParameters parameters) { |
243 |
for (DataFactory factory : this.getStoreRegister()) { |
244 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) factory; |
245 |
if (storeFactory.canUse(parameters)) {
|
246 |
return storeFactory.getName();
|
247 |
} |
248 |
} |
249 |
return null; |
250 |
} |
251 |
|
252 |
/**
|
253 |
* @deprecated
|
254 |
*/
|
255 |
@Override
|
256 |
public void registerDefaultRasterStore(Class rasterStoreClass) { |
257 |
// Metodo usado por el raster nuevo para regstrar su factoria de store
|
258 |
this.getStoreRegister().register(new RasterStoreFactory(rasterStoreClass)); |
259 |
} |
260 |
|
261 |
|
262 |
private boolean oldRasterRegistered = false; |
263 |
/**
|
264 |
* @deprecated
|
265 |
*/
|
266 |
@Override
|
267 |
public void registerStoreFactory(String name, Class storeFactoryClass) { |
268 |
// Metodo usado por el raster viejo para registrar las factorias de sus stores
|
269 |
this.getStoreRegister().register(new RasterStoreOldFactory(name, storeFactoryClass)); |
270 |
this.oldRasterRegistered = true; |
271 |
} |
272 |
|
273 |
@Override
|
274 |
public boolean isTheOldRasterRegistered() { |
275 |
return this.oldRasterRegistered; |
276 |
} |
277 |
|
278 |
/**
|
279 |
* @param name
|
280 |
* @param storeProviderClass
|
281 |
* @param parametersClass
|
282 |
* @deprecated use registerStoreProviderFactory
|
283 |
*/
|
284 |
@Override
|
285 |
public void registerStoreProvider(String name, Class storeProviderClass, |
286 |
Class parametersClass) {
|
287 |
if (name == null || storeProviderClass == null || parametersClass == null) { |
288 |
throw new IllegalArgumentException("Any parameters can be null"); |
289 |
} |
290 |
|
291 |
if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) {
|
292 |
throw new IllegalArgumentException(parametersClass.getName() |
293 |
+ " must implement org.gvsig.fmap.dal.DataStoreParameters");
|
294 |
} |
295 |
|
296 |
if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
297 |
// Envuelve al proveedor en una factoria por defecto.
|
298 |
this.registerStoreProviderFactory(new DataStoreProviderToCoverageProviderFactoryWrapper( |
299 |
name, "", storeProviderClass, parametersClass));
|
300 |
return;
|
301 |
} |
302 |
|
303 |
if (FeatureStoreProvider.class.isAssignableFrom(storeProviderClass)) {
|
304 |
// Envuelve al proveedor en una factoria por defecto.
|
305 |
this.registerStoreProviderFactory(new DataStoreProviderToFeatureStoreProviderFactoryWrapper( |
306 |
name, "", storeProviderClass, parametersClass));
|
307 |
return;
|
308 |
} |
309 |
|
310 |
throw new IllegalArgumentException("Not supported implemtation: name=" |
311 |
+ name + " provider class=" + storeProviderClass.getName());
|
312 |
|
313 |
} |
314 |
|
315 |
@Override
|
316 |
public void registerExplorerProvider(String name, Class explorerClass, Class parametersClass) { |
317 |
if (name == null || explorerClass == null || parametersClass == null) { |
318 |
// FIXME Exception
|
319 |
throw new IllegalArgumentException("Any parameters can be null"); |
320 |
} |
321 |
|
322 |
if (!DataServerExplorerParameters.class
|
323 |
.isAssignableFrom(parametersClass)) { |
324 |
// FIXME Exception
|
325 |
throw new IllegalArgumentException( |
326 |
parametersClass.getName() |
327 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorerParameters");
|
328 |
} |
329 |
|
330 |
if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) {
|
331 |
// FIXME Exception
|
332 |
throw new IllegalArgumentException(explorerClass.getName() |
333 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorer");
|
334 |
} |
335 |
|
336 |
// Envuelve al proveedor en una factoria por defecto.
|
337 |
this.registerServerExplorerFactory(
|
338 |
new DataServerExplorerToDataExplorerFactoryWrapper(
|
339 |
name, "", explorerClass, parametersClass
|
340 |
) |
341 |
); |
342 |
|
343 |
} |
344 |
|
345 |
@Override
|
346 |
public void registerStoreFactory(DataStoreFactory_v2_4 factory) { |
347 |
this.getStoreRegister().register(factory);
|
348 |
} |
349 |
|
350 |
@Override
|
351 |
public void registerStoreProviderFactory(DataStoreProviderFactory factory) { |
352 |
this.getStoreProviderRegister().register(factory);
|
353 |
} |
354 |
|
355 |
@Override
|
356 |
public void registerServerExplorerFactory(DataServerExplorerFactory factory) { |
357 |
this.getServerExplorerRegister().register(factory);
|
358 |
} |
359 |
|
360 |
@Override
|
361 |
public DataStoreParameters createStoreParameters(byte[] data) { |
362 |
DataStoreParameters parameters = (DataStoreParameters) AbstractDataParameters.fromByteArray(data); |
363 |
return parameters;
|
364 |
} |
365 |
|
366 |
public DataStoreParameters createStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
367 |
// Cuando desde python se llama a createStoreParameters con solo un argumento
|
368 |
// acaba entrando por aqui en lugar de por
|
369 |
// createStoreParameters(String providerName, Object... arguments)
|
370 |
return this.createStoreParameters(providerName, (Object[]) null); |
371 |
} |
372 |
|
373 |
@Override
|
374 |
public DataStoreParameters createStoreParameters(String providerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException { |
375 |
if( providerName == null ) { |
376 |
String msg = "Provider name can't be null."; |
377 |
LOGGER.warn(msg); |
378 |
throw new IllegalArgumentException(msg); |
379 |
} |
380 |
if( arguments!=null && arguments.length>0 ) { |
381 |
if( arguments.length == 1 ) { |
382 |
// Desde jython entra por este metodo en lugar de los especificos
|
383 |
// de DataStoreParameters o DynObject
|
384 |
if( arguments[0] instanceof DataStoreParameters ) { |
385 |
return this.createStoreParameters(providerName, (DataStoreParameters)(arguments[0])); |
386 |
} else if( arguments[0] instanceof DynObject ) { |
387 |
return this.createStoreParameters(providerName, (DynObject)(arguments[0])); |
388 |
} |
389 |
} |
390 |
if( (arguments.length % 2)!= 0 ) { |
391 |
throw new IllegalArgumentException("The number of arguments must be even."); |
392 |
} |
393 |
} |
394 |
if( providerName == null ) { |
395 |
String msg = "Provider name can't be null."; |
396 |
LOGGER.warn(msg); |
397 |
throw new IllegalArgumentException(msg); |
398 |
} |
399 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
400 |
if( providerFactory == null ) { |
401 |
String msg = "Can't locate provider factory for '"+providerName+"'."; |
402 |
LOGGER.warn(msg); |
403 |
throw new IllegalArgumentException(msg); |
404 |
} |
405 |
DataStoreParameters parameters = (DataStoreParameters) providerFactory.createParameters(); |
406 |
if( arguments!=null && arguments.length>0 ) { |
407 |
for( int i=0; i<arguments.length; i+=2 ) { |
408 |
String name = (String) arguments[i]; |
409 |
if( name.endsWith("=") ) { |
410 |
name = name.substring(0, name.length()-1); |
411 |
} |
412 |
Object value = arguments[i+1]; |
413 |
parameters.setDynValue(name, value); |
414 |
} |
415 |
} |
416 |
return parameters;
|
417 |
} |
418 |
|
419 |
@Override
|
420 |
public NewDataStoreParameters createNewStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
421 |
String explorerName = this.getServerExplorerFromStore(providerName); |
422 |
return createNewStoreParameters(explorerName, providerName);
|
423 |
} |
424 |
|
425 |
@Override
|
426 |
public NewDataStoreParameters createNewStoreParameters(String explorerName, String providerName) throws InitializeException, ProviderNotRegisteredException { |
427 |
try {
|
428 |
DataServerExplorer explorer = this.openServerExplorer(explorerName, (DataServerExplorerParameters)null); |
429 |
return explorer.getAddParameters(providerName);
|
430 |
} catch (Exception ex) { |
431 |
throw new InitializeException(ex); |
432 |
} |
433 |
} |
434 |
|
435 |
@Override
|
436 |
public DataServerExplorerParameters createServerExplorerParameters(String explorerName) throws InitializeException, ProviderNotRegisteredException { |
437 |
if( explorerName == null ) { |
438 |
String msg = "Explorer name can't be null."; |
439 |
LOGGER.warn(msg); |
440 |
throw new IllegalArgumentException(msg); |
441 |
} |
442 |
JsonObject parameters_json = null;
|
443 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
444 |
if( explorerFactory == null ) { |
445 |
parameters_json = Json.createObject(explorerName); |
446 |
if( parameters_json==null || |
447 |
!parameters_json.containsKey(PROVIDER_PARAMTER_NAME) ) { |
448 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
449 |
LOGGER.warn(msg); |
450 |
throw new IllegalArgumentException(msg); |
451 |
} |
452 |
explorerName = parameters_json.getString(PROVIDER_PARAMTER_NAME); |
453 |
explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
454 |
if( explorerFactory == null ) { |
455 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
456 |
LOGGER.warn(msg); |
457 |
throw new IllegalArgumentException(msg); |
458 |
} |
459 |
} |
460 |
DataServerExplorerParameters params = (DataServerExplorerParameters) explorerFactory.createParameters(); |
461 |
if( parameters_json!=null ) { |
462 |
Json.addAll(params, parameters_json); |
463 |
} |
464 |
return params;
|
465 |
} |
466 |
|
467 |
@Override
|
468 |
public DataStoreParameters createMemoryStoreParameters(String autoOrderAttributeName) throws InitializeException { |
469 |
try {
|
470 |
DataStoreParameters parameters = createStoreParameters(MemoryStoreProvider.NAME); |
471 |
if (autoOrderAttributeName != null) { |
472 |
parameters.setDynValue( |
473 |
MemoryStoreParameters.ORDER_PARAMETER_NAME, |
474 |
autoOrderAttributeName); |
475 |
} |
476 |
return parameters;
|
477 |
} catch (Exception ex) { |
478 |
throw new InitializeException(ex); |
479 |
} |
480 |
} |
481 |
|
482 |
@Override
|
483 |
public DataServerExplorer openServerExplorer(String explorerName, DataServerExplorerParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
484 |
if( explorerName == null ) { |
485 |
String msg = "Explorer name can't be null."; |
486 |
LOGGER.warn(msg); |
487 |
throw new IllegalArgumentException(msg); |
488 |
} |
489 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
490 |
if( explorerFactory == null ) { |
491 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
492 |
LOGGER.warn(msg); |
493 |
throw new IllegalArgumentException(msg); |
494 |
} |
495 |
if (parameters == null) { |
496 |
parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
497 |
} |
498 |
DataServerExplorer explorer = (DataServerExplorer) explorerFactory.create( |
499 |
parameters, |
500 |
new DefaultDataServerExplorerProviderServices()
|
501 |
); |
502 |
return explorer;
|
503 |
} |
504 |
|
505 |
@Override
|
506 |
public DataServerExplorer openServerExplorer(String explorerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
507 |
if( arguments.length==1 && arguments[0] instanceof DataServerExplorerParameters ) { |
508 |
// Esto hace falta ya que desde scripting si se invoca a openServerExplorer con solo
|
509 |
// un parametro de tipo DataServerExplorerParameters llama ha este metodo en lugar de
|
510 |
// llamar al que toca.
|
511 |
return openServerExplorer(explorerName, (DataServerExplorerParameters)(arguments[0])); |
512 |
} |
513 |
if( explorerName == null ) { |
514 |
String msg = "Explorer name can't be null."; |
515 |
LOGGER.warn(msg); |
516 |
throw new IllegalArgumentException(msg); |
517 |
} |
518 |
if( (arguments.length % 2)!= 0 ) { |
519 |
throw new ValidateDataParametersException(); |
520 |
} |
521 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName);
|
522 |
DataServerExplorerParameters parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
523 |
for( int i=0; i<arguments.length; i+=2 ) { |
524 |
String name = (String) arguments[i]; |
525 |
if( name.endsWith("=") ) { |
526 |
name = name.substring(0, name.length()-1); |
527 |
} |
528 |
Object value = arguments[i+1]; |
529 |
parameters.setDynValue(name, value); |
530 |
} |
531 |
return this.openServerExplorer(explorerName, parameters); |
532 |
|
533 |
} |
534 |
|
535 |
/**
|
536 |
* @param parameters
|
537 |
* @return
|
538 |
* @throws org.gvsig.fmap.dal.exception.InitializeException
|
539 |
* @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
|
540 |
* @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException
|
541 |
* @deprecated see openServerExplorer
|
542 |
*/
|
543 |
@Override
|
544 |
public DataServerExplorer createServerExplorer(
|
545 |
DataServerExplorerParameters parameters) throws InitializeException,
|
546 |
ProviderNotRegisteredException, ValidateDataParametersException { |
547 |
return openServerExplorer(parameters.getExplorerName(), parameters);
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* @deprecated use openStore
|
552 |
* @param parameters
|
553 |
* @return
|
554 |
* @throws InitializeException
|
555 |
* @throws ProviderNotRegisteredException
|
556 |
* @throws ValidateDataParametersException
|
557 |
*/
|
558 |
@Override
|
559 |
public DataStore createStore(DataStoreParameters parameters)
|
560 |
throws InitializeException, ProviderNotRegisteredException,
|
561 |
ValidateDataParametersException { |
562 |
return openStore(parameters.getDataStoreName(), parameters);
|
563 |
} |
564 |
|
565 |
@Override
|
566 |
public DataStore openStore(String providerName, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
567 |
if( providerName == null ) { |
568 |
String msg = "Provider name can't be null."; |
569 |
LOGGER.warn(msg); |
570 |
throw new IllegalArgumentException(msg); |
571 |
} |
572 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
573 |
if (!identityManager.getCurrentIdentity().isAuthorized(READ_STORE_AUTHORIZATION, parameters, providerName)) {
|
574 |
throw new UnauthorizedException(READ_STORE_AUTHORIZATION, parameters, providerName); |
575 |
} |
576 |
|
577 |
parameters.validate(); |
578 |
|
579 |
String storeName = this.getStoreName(parameters); |
580 |
if( StringUtils.isEmpty(storeName) ) {
|
581 |
String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
582 |
LOGGER.warn(msg); |
583 |
throw new IllegalArgumentException(msg); |
584 |
} |
585 |
|
586 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
587 |
if( storeFactory == null ) { |
588 |
String msg = "Can't locate store factory for '"+storeName+"'."; |
589 |
LOGGER.warn(msg); |
590 |
throw new IllegalArgumentException(msg); |
591 |
} |
592 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
593 |
if( providerFactory == null ) { |
594 |
String msg = "Can't locate provider factory for '"+providerName+"'."; |
595 |
LOGGER.warn(msg); |
596 |
throw new IllegalArgumentException(msg); |
597 |
} |
598 |
|
599 |
DataStore store = (DataStore) storeFactory.create(parameters, this);
|
600 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create(parameters, store); |
601 |
|
602 |
if( provider == null ) { |
603 |
String msg = "Can't create provider for '"+providerName+"'."; |
604 |
LOGGER.trace(msg); |
605 |
throw new IllegalArgumentException(msg); |
606 |
} |
607 |
|
608 |
storeFactory.setProvider(store, provider); |
609 |
|
610 |
addObservers(store); |
611 |
if( store instanceof FeatureStoreProviderServices ) { |
612 |
((FeatureStoreProviderServices) store).notifyChange(DataStoreNotification.AFTER_OPEN); |
613 |
} |
614 |
return store;
|
615 |
} |
616 |
|
617 |
public void addObservers(DataStore store){ |
618 |
for (Observer storeObserver : storeObservers) { |
619 |
if( storeObserver!=null) { |
620 |
store.addObserver(storeObserver); |
621 |
} |
622 |
} |
623 |
} |
624 |
|
625 |
@Override
|
626 |
public DataStore openStore(DataStoreParameters parameters, DataStoreProvider provider) {
|
627 |
String storeName = this.getStoreName(parameters); |
628 |
if( StringUtils.isEmpty(storeName) ) {
|
629 |
String msg = "Can't locate the store name from the parameters. parameters=" + parameters.toString(); |
630 |
LOGGER.warn(msg); |
631 |
throw new IllegalArgumentException(msg); |
632 |
} |
633 |
|
634 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName);
|
635 |
if( storeFactory == null ) { |
636 |
String msg = "Can't locate store factory for '"+storeName+"'."; |
637 |
LOGGER.warn(msg); |
638 |
throw new IllegalArgumentException(msg); |
639 |
} |
640 |
DataStore store = (DataStore) storeFactory.create(parameters, this);
|
641 |
storeFactory.setProvider(store, provider); |
642 |
for (Observer storeObserver : storeObservers) { |
643 |
if( storeObserver!=null) { |
644 |
store.addObserver(storeObserver); |
645 |
} |
646 |
} |
647 |
if( store instanceof FeatureStoreProviderServices ) { |
648 |
((FeatureStoreProviderServices) store).notifyChange(DataStoreNotification.AFTER_OPEN); |
649 |
} |
650 |
return store;
|
651 |
} |
652 |
|
653 |
@Override
|
654 |
public DataStore openStore(String provider, DynObject parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
655 |
DataStoreParameters params = toDataStoreParameters(provider, parameters); |
656 |
DataStore store = openStore(params.getDataStoreName(), params); |
657 |
return store;
|
658 |
} |
659 |
|
660 |
@Override
|
661 |
public DataStore openStore(String providerName, Object... arguments) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
662 |
if( arguments.length == 1 ) { |
663 |
// Desde jython entra por este metodo en lugar de los especificos
|
664 |
// de DataStoreParameters o DynObject
|
665 |
if( arguments[0] instanceof DataStoreParameters ) { |
666 |
return this.openStore(providerName, (DataStoreParameters)(arguments[0])); |
667 |
} else if( arguments[0] instanceof DynObject ) { |
668 |
return this.openStore(providerName, (DynObject)(arguments[0])); |
669 |
} |
670 |
} |
671 |
if( (arguments.length % 2)!= 0 ) { |
672 |
throw new ValidateDataParametersException(); |
673 |
} |
674 |
if( providerName == null ) { |
675 |
String msg = "Provider name can't be null."; |
676 |
LOGGER.warn(msg); |
677 |
throw new IllegalArgumentException(msg); |
678 |
} |
679 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
680 |
DataStoreParameters parameters = (DataStoreParameters) providerFactory.createParameters(); |
681 |
for( int i=0; i<arguments.length; i+=2 ) { |
682 |
String name = (String) arguments[i]; |
683 |
if( name.endsWith("=") ) { |
684 |
name = name.substring(0, name.length()-1); |
685 |
} |
686 |
Object value = arguments[i+1]; |
687 |
parameters.setDynValue(name, value); |
688 |
} |
689 |
return this.openStore(providerName, parameters); |
690 |
} |
691 |
|
692 |
@Override
|
693 |
public FeatureStore createMemoryStore(String autoOrderAttributeName) throws InitializeException { |
694 |
try {
|
695 |
DataStoreParameters parameters = createMemoryStoreParameters(autoOrderAttributeName); |
696 |
DataStore store = openStore(MemoryStoreProvider.NAME, parameters); |
697 |
return (FeatureStore) store;
|
698 |
} catch (Exception ex) { |
699 |
throw new InitializeException(ex); |
700 |
} |
701 |
} |
702 |
|
703 |
@Override
|
704 |
public DataStoreProviderFactory getStoreProviderFactory(String providerName) { |
705 |
if( providerName == null ) { |
706 |
String msg = "Provider name can't be null."; |
707 |
LOGGER.warn(msg); |
708 |
throw new IllegalArgumentException(msg); |
709 |
} |
710 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
711 |
return (DataStoreProviderFactory) providerFactory;
|
712 |
} |
713 |
|
714 |
@Override
|
715 |
public List<String> getStoreProviders() { |
716 |
return this.getStoreProviderRegister().getFactoryNames(); |
717 |
} |
718 |
|
719 |
@Override
|
720 |
public List<String> getStoreProviders(String explorerName) { |
721 |
if( explorerName == null ) { |
722 |
String msg = "Explorer name can't be null."; |
723 |
LOGGER.warn(msg); |
724 |
throw new IllegalArgumentException(msg); |
725 |
} |
726 |
try {
|
727 |
DataServerExplorer explorer = openServerExplorer(explorerName, (DataServerExplorerParameters)null);
|
728 |
List names = explorer.getDataStoreProviderNames();
|
729 |
return names;
|
730 |
} catch (Exception ex) { |
731 |
throw new RuntimeException("Can't get stores availables for explorer '" + explorerName + "'.", ex); |
732 |
} |
733 |
} |
734 |
|
735 |
@Override
|
736 |
public List<String> getExplorerProviders() { |
737 |
List<String> names = this.getServerExplorerRegister().getFactoryNames(); |
738 |
return names;
|
739 |
} |
740 |
|
741 |
@Override
|
742 |
public DataStoreProvider createProvider(DataStoreProviderServices providerServices, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException { |
743 |
|
744 |
String providerName = parameters.getDataStoreName();
|
745 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName);
|
746 |
if (providerFactory == null) { |
747 |
throw new ProviderNotRegisteredException(providerName); |
748 |
} |
749 |
while (true) { |
750 |
try {
|
751 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create( |
752 |
parameters, providerServices |
753 |
); |
754 |
return provider;
|
755 |
} catch (Exception e) { |
756 |
if (openErrorHandler == null) { |
757 |
throw new InitializeException(providerName, e); |
758 |
} |
759 |
boolean retry = openErrorHandler.canRetryOpen(e, parameters);
|
760 |
if (!retry) {
|
761 |
throw new InitializeException(providerName, e); |
762 |
} |
763 |
} |
764 |
} |
765 |
} |
766 |
|
767 |
@Override
|
768 |
public List<String> getFeatureIndexProviders() { |
769 |
List<String> names = this.getFeatureIndexRegister().getFactoryNames(); |
770 |
return names;
|
771 |
} |
772 |
|
773 |
@Override
|
774 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
775 |
this.defaultDataIndexProviders.put(dataType, name);
|
776 |
} |
777 |
|
778 |
@Override
|
779 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
780 |
return this.defaultDataIndexProviders.get(dataType); |
781 |
} |
782 |
|
783 |
@Override
|
784 |
public FeatureIndexProviderServices createFeatureIndexProvider(
|
785 |
String name,
|
786 |
FeatureStore store, |
787 |
FeatureType type, |
788 |
String indexName,
|
789 |
FeatureAttributeDescriptor attr |
790 |
) throws InitializeException, ProviderNotRegisteredException {
|
791 |
|
792 |
if (name == null) { |
793 |
name = getDefaultFeatureIndexProviderName(attr.getType()); |
794 |
} |
795 |
|
796 |
if (name == null) { |
797 |
throw new InitializeException( |
798 |
"There not any index provider registered.", null); |
799 |
} |
800 |
DataFactory indexfactory = this.getFeatureIndexRegister().getFactory(name);
|
801 |
if (indexfactory == null) { |
802 |
throw new InitializeException( |
803 |
"There not any index provider registered with name '" + name + "'.", null); |
804 |
|
805 |
} |
806 |
FeatureIndexProvider provider = (FeatureIndexProvider) indexfactory.create(null, null); |
807 |
|
808 |
FeatureIndexProviderServices services = new DefaultFeatureIndex(
|
809 |
(FeatureStoreProviderServices) store, |
810 |
type, |
811 |
provider, |
812 |
attr.getName(), |
813 |
indexName |
814 |
); |
815 |
services.initialize(); |
816 |
return services;
|
817 |
|
818 |
} |
819 |
|
820 |
@Override
|
821 |
public String getTemporaryDirectory() { |
822 |
FoldersManager manager = ToolsLocator.getFoldersManager(); |
823 |
File folder = manager.getUniqueTemporaryFile("_daltmp_"); |
824 |
return folder.getAbsolutePath();
|
825 |
} |
826 |
|
827 |
@Override
|
828 |
public DataStoreParameters createStoreParameters(DynStruct struct) throws InitializeException, ProviderNotRegisteredException { |
829 |
if (!(struct instanceof DynStruct_v2)) { |
830 |
throw new IllegalArgumentException("A DynStruct_v2 is required."); |
831 |
} |
832 |
Tags tags = ((DynStruct_v2) struct).getTags(); |
833 |
return this.createStoreParameters(tags); |
834 |
} |
835 |
|
836 |
@Override
|
837 |
public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException { |
838 |
String providerName = (String) tags.get(TAG_DAL_OPENSTORE + "provider"); |
839 |
if (providerName == null) { |
840 |
throw new IllegalArgumentException("Tag DAL.OpenStore.provider is missing in struct."); |
841 |
} |
842 |
int prefixlen = TAG_DAL_OPENSTORE.length();
|
843 |
DataStoreParameters parameters = this.createStoreParameters(providerName);
|
844 |
for (String key : tags) { |
845 |
if (key.startsWith(TAG_DAL_OPENSTORE)) {
|
846 |
parameters.setDynValue(key.substring(prefixlen), tags.get(key)); |
847 |
} |
848 |
} |
849 |
return parameters;
|
850 |
} |
851 |
|
852 |
@Override
|
853 |
public DataStore openStore(DynStruct struct) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
854 |
DataStoreParameters paramters = this.createStoreParameters(struct);
|
855 |
DataStore store = this.openStore(paramters.getDataStoreName(), paramters);
|
856 |
return store;
|
857 |
} |
858 |
|
859 |
@Override
|
860 |
public void newStore(String providerName, NewDataStoreParameters parameters, boolean overwrite) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
861 |
String explorerName = this.getServerExplorerFromStore(providerName); |
862 |
newStore(explorerName, providerName, parameters, overwrite); |
863 |
} |
864 |
|
865 |
@Override
|
866 |
public void newStore(String explorerName, String providerName, NewDataStoreParameters parameters, boolean overwrite) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
867 |
if( explorerName == null ) { |
868 |
String msg = "Explorer name can't be null."; |
869 |
LOGGER.warn(msg); |
870 |
throw new IllegalArgumentException(msg); |
871 |
} |
872 |
if( providerName == null ) { |
873 |
String msg = "Provider name can't be null."; |
874 |
LOGGER.warn(msg); |
875 |
throw new IllegalArgumentException(msg); |
876 |
} |
877 |
|
878 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
879 |
if (!identityManager.getCurrentIdentity().isAuthorized(CREATE_STORE_AUTHORIZATION, parameters, providerName)) {
|
880 |
throw new UnauthorizedException(CREATE_STORE_AUTHORIZATION, parameters, providerName); |
881 |
} |
882 |
parameters.validate(); |
883 |
try {
|
884 |
DataServerExplorerParameters explorerParameters = this.createServerExplorerParameters(explorerName);
|
885 |
DataServerExplorer server = this.openServerExplorer(explorerName, explorerParameters);
|
886 |
server.add(providerName, parameters, overwrite); |
887 |
} catch (Exception e) { |
888 |
throw new InitializeException(e); |
889 |
} |
890 |
} |
891 |
|
892 |
@Override
|
893 |
@Deprecated
|
894 |
public Evaluator createExpresion(String expression) throws InitializeException { |
895 |
Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
896 |
exp.setPhrase(expression); |
897 |
return this.createExpresion(exp); |
898 |
} |
899 |
|
900 |
@Override
|
901 |
@Deprecated
|
902 |
public Evaluator createExpresion(Expression expression) throws InitializeException { |
903 |
DefaultFeatureExpressionEvaluator exp = new DefaultFeatureExpressionEvaluator(expression);
|
904 |
return exp;
|
905 |
} |
906 |
|
907 |
|
908 |
@Override
|
909 |
public Evaluator createFilter(String expression) throws InitializeException { |
910 |
Expression exp = ExpressionEvaluatorLocator.getManager().createExpression();
|
911 |
exp.setPhrase(expression); |
912 |
return this.createFilter(exp); |
913 |
} |
914 |
|
915 |
@Override
|
916 |
public Evaluator createFilter(Expression expression) throws InitializeException { |
917 |
DefaultFeatureExpressionEvaluator exp = new DefaultFeatureExpressionEvaluator(expression);
|
918 |
return exp;
|
919 |
} |
920 |
|
921 |
@Override
|
922 |
public FeaturePagingHelper createFeaturePagingHelper(
|
923 |
FeatureStore featureStore, int pageSize) throws BaseException { |
924 |
return new FeaturePagingHelperImpl(featureStore, pageSize); |
925 |
} |
926 |
|
927 |
@Override
|
928 |
public FeaturePagingHelper createFeaturePagingHelper(
|
929 |
FeatureStore featureStore, FeatureQuery featureQuery, int pageSize)
|
930 |
throws BaseException {
|
931 |
return new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize); |
932 |
} |
933 |
|
934 |
@Override
|
935 |
public void setOpenErrorHandler(OpenErrorHandler handler) { |
936 |
openErrorHandler = handler; |
937 |
} |
938 |
|
939 |
@Override
|
940 |
public OpenErrorHandler getOpenErrorHandler() {
|
941 |
return this.openErrorHandler; |
942 |
} |
943 |
|
944 |
@Override
|
945 |
public EditableFeatureType createFeatureType() {
|
946 |
return new DefaultEditableFeatureType(null); |
947 |
} |
948 |
|
949 |
@Override
|
950 |
public EditableFeatureType createFeatureType(JsonObject json) {
|
951 |
EditableFeatureType featureType = this.createFeatureType();
|
952 |
featureType.fromJson(json); |
953 |
return featureType;
|
954 |
} |
955 |
|
956 |
@Override
|
957 |
public DataServerExplorerPool getDataServerExplorerPool() {
|
958 |
if (this.dataServerExplorerPool == null) { |
959 |
this.dataServerExplorerPool = new DataServerExplorerPoolImpl(); |
960 |
} |
961 |
return this.dataServerExplorerPool; |
962 |
} |
963 |
|
964 |
@Override
|
965 |
public void setDataServerExplorerPool(DataServerExplorerPool pool) { |
966 |
this.dataServerExplorerPool = pool;
|
967 |
} |
968 |
|
969 |
public DataStoreParameters toDataStoreParameters(String provider, DynObject params) throws InitializeException, ProviderNotRegisteredException { |
970 |
if (params instanceof DataStoreParameters) { |
971 |
return (DataStoreParameters) params;
|
972 |
} |
973 |
String providerName;
|
974 |
try {
|
975 |
providerName = (String) params.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
|
976 |
} catch (Exception ex) { |
977 |
providerName = provider; |
978 |
} |
979 |
DataStoreParameters parameters = this.createStoreParameters(providerName);
|
980 |
ToolsLocator.getDynObjectManager().copy(params, parameters); |
981 |
return parameters;
|
982 |
} |
983 |
|
984 |
@Override
|
985 |
public List<DataType> getDataTypes() { |
986 |
if (dataTypes == null) { |
987 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
988 |
dataTypes = new ArrayList<>(); |
989 |
dataTypes.add(manager.get(DataTypes.STRING)); |
990 |
dataTypes.add(manager.get(DataTypes.BOOLEAN)); |
991 |
dataTypes.add(manager.get(DataTypes.INT)); |
992 |
dataTypes.add(manager.get(DataTypes.DOUBLE)); |
993 |
dataTypes.add(manager.get(DataTypes.DATE)); |
994 |
dataTypes.add(manager.get(DataTypes.GEOMETRY)); |
995 |
} |
996 |
return dataTypes;
|
997 |
} |
998 |
|
999 |
@Override
|
1000 |
public void setResourcesLoader(ClassLoader loader) { |
1001 |
this.resourcesLoader = loader;
|
1002 |
} |
1003 |
|
1004 |
@Override
|
1005 |
public void setResourcesLoader(File folder) { |
1006 |
if (folder == null) { |
1007 |
this.resourcesLoader = null; |
1008 |
return;
|
1009 |
} |
1010 |
try {
|
1011 |
URL[] urls = new URL[]{folder.toURI().toURL()}; |
1012 |
this.resourcesLoader = new URLClassLoader(urls); |
1013 |
} catch (Exception ex) { |
1014 |
throw new IllegalArgumentException("Can't create a ClassLoader from '" + folder.toString() + "'.", ex); |
1015 |
} |
1016 |
} |
1017 |
|
1018 |
@Override
|
1019 |
public URL getResource(Object reourceLoader, String name) { |
1020 |
URL x;
|
1021 |
if (this.resourcesLoader != null) { |
1022 |
x = this.resourcesLoader.getResource(name);
|
1023 |
if (x != null) { |
1024 |
return x;
|
1025 |
} |
1026 |
} |
1027 |
x = reourceLoader.getClass().getResource(name); |
1028 |
return x;
|
1029 |
} |
1030 |
|
1031 |
@Override
|
1032 |
public InputStream getResourceAsStream(Object reourceLoader, String name) { |
1033 |
InputStream x;
|
1034 |
if (this.resourcesLoader != null) { |
1035 |
x = this.resourcesLoader.getResourceAsStream(name);
|
1036 |
if (x != null) { |
1037 |
return x;
|
1038 |
} |
1039 |
} |
1040 |
x = reourceLoader.getClass().getResourceAsStream(name); |
1041 |
return x;
|
1042 |
} |
1043 |
|
1044 |
@Override
|
1045 |
public ExpressionBuilder createExpressionBuilder() {
|
1046 |
return ExpressionEvaluatorLocator.getManager().createExpressionBuilder();
|
1047 |
} |
1048 |
|
1049 |
public void registerFeatureCacheProvider( |
1050 |
FeatureCacheProviderFactory providerFactory) { |
1051 |
ToolsLocator.getExtensionPointManager() |
1052 |
.add(DATA_MANAGER_CACHE, DATA_MANAGER_CACHE_DESCRIPTION) |
1053 |
.append(providerFactory.getName(), "", providerFactory);
|
1054 |
} |
1055 |
|
1056 |
public FeatureCacheProvider createFeatureCacheProvider(String name, |
1057 |
DynObject parameters) throws DataException {
|
1058 |
if (name == null) { |
1059 |
throw new InitializeException( |
1060 |
"It is necessary to provide a cache name", null); |
1061 |
} |
1062 |
if (parameters == null) { |
1063 |
throw new InitializeException( |
1064 |
"It is necessary to provide parameters to create the explorer",
|
1065 |
null);
|
1066 |
} |
1067 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
1068 |
try {
|
1069 |
featureCacheProviderFactory = |
1070 |
(FeatureCacheProviderFactory) ToolsLocator |
1071 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
1072 |
.create(name); |
1073 |
if (featureCacheProviderFactory == null) { |
1074 |
throw new ProviderNotRegisteredException(name); |
1075 |
} |
1076 |
return featureCacheProviderFactory.createCacheProvider(parameters);
|
1077 |
} catch (Exception e) { |
1078 |
throw new InitializeException(e); |
1079 |
} |
1080 |
} |
1081 |
|
1082 |
@Override
|
1083 |
public List getFeatureCacheProviders() { |
1084 |
ExtensionPoint extensionPoint = |
1085 |
ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_CACHE); |
1086 |
if (extensionPoint != null) { |
1087 |
return ToolsLocator.getExtensionPointManager()
|
1088 |
.get(DATA_MANAGER_CACHE).getNames(); |
1089 |
} else {
|
1090 |
return new ArrayList(); |
1091 |
} |
1092 |
} |
1093 |
|
1094 |
@Override
|
1095 |
public DynObject createCacheParameters(String name) |
1096 |
throws InitializeException, ProviderNotRegisteredException {
|
1097 |
if (name == null) { |
1098 |
throw new InitializeException( |
1099 |
"It is necessary to provide a cache name", null); |
1100 |
} |
1101 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
1102 |
try {
|
1103 |
featureCacheProviderFactory = |
1104 |
(FeatureCacheProviderFactory) ToolsLocator |
1105 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
1106 |
.create(name); |
1107 |
if (featureCacheProviderFactory == null) { |
1108 |
throw new ProviderNotRegisteredException(name); |
1109 |
} |
1110 |
return featureCacheProviderFactory.createParameters();
|
1111 |
} catch (Exception e) { |
1112 |
throw new InitializeException(e); |
1113 |
} |
1114 |
} |
1115 |
|
1116 |
@Override
|
1117 |
public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException { |
1118 |
DataManagerProviderServices dataManager = DALSPILocator.getDataManagerProviderServices(); |
1119 |
DataServerExplorerParameters eparams = null;
|
1120 |
DataServerExplorer serverExplorer; |
1121 |
try {
|
1122 |
serverExplorer = dataManager.openServerExplorer(FILESYSTEM_EXPLORER_NAME, eparams); |
1123 |
} catch (ValidateDataParametersException | InitializeException | ProviderNotRegisteredException e) {
|
1124 |
throw new OpenException(FILESYSTEM_EXPLORER_NAME, e); |
1125 |
} |
1126 |
|
1127 |
try {
|
1128 |
serverExplorer.add(providerName, params, overwrite); |
1129 |
} catch (DataException e) {
|
1130 |
throw new CreateFileStoreException(e, providerName); |
1131 |
} |
1132 |
} |
1133 |
|
1134 |
@Override
|
1135 |
public FeatureSymbolTable createFeatureSymbolTable() {
|
1136 |
FeatureSymbolTable symbolTable = new FeatureSymbolTableImpl();
|
1137 |
return symbolTable;
|
1138 |
} |
1139 |
|
1140 |
@Override
|
1141 |
public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression) { |
1142 |
FeatureAttributeEmulatorExpression emulator = new DefaultFeatureAttributeEmulatorExpression(type, expression);
|
1143 |
return emulator;
|
1144 |
} |
1145 |
|
1146 |
@Override
|
1147 |
public void registerDataProfile(DataProfile profile) { |
1148 |
if( profile==null ) { |
1149 |
return;
|
1150 |
} |
1151 |
if( this.dataProfiles==null ) { |
1152 |
this.dataProfiles = new ArrayList<>(); |
1153 |
this.dataProfiles.add(profile);
|
1154 |
return;
|
1155 |
} |
1156 |
for (DataProfile theProfile : this.dataProfiles) { |
1157 |
if( theProfile.getID().equalsIgnoreCase(profile.getID()) ) {
|
1158 |
return;
|
1159 |
} |
1160 |
} |
1161 |
this.dataProfiles.add(profile);
|
1162 |
} |
1163 |
|
1164 |
@Override
|
1165 |
public List<DataProfile> getDataProfiles() { |
1166 |
if( this.dataProfiles==null ) { |
1167 |
return null; |
1168 |
} |
1169 |
return Collections.unmodifiableList(this.dataProfiles); |
1170 |
} |
1171 |
|
1172 |
@Override
|
1173 |
public DataProfile getDataProfile(String name) { |
1174 |
if( StringUtils.isBlank(name) ) {
|
1175 |
return null; |
1176 |
} |
1177 |
for (DataProfile theProfile : this.dataProfiles) { |
1178 |
if( name.equalsIgnoreCase(theProfile.getName()) ) {
|
1179 |
return theProfile;
|
1180 |
} |
1181 |
} |
1182 |
return null; |
1183 |
} |
1184 |
|
1185 |
private StoresRepository storesRepository;
|
1186 |
|
1187 |
@Override
|
1188 |
public StoresRepository getStoresRepository() {
|
1189 |
if( this.storesRepository==null ) { |
1190 |
this.storesRepository = new BaseStoresRepository("DAL"); |
1191 |
} |
1192 |
return this.storesRepository; |
1193 |
} |
1194 |
|
1195 |
@Override
|
1196 |
public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection) {
|
1197 |
DatabaseWorkspaceManager workspace = new DefaultDatabaseWorkspaceManager(connection);
|
1198 |
return workspace;
|
1199 |
} |
1200 |
|
1201 |
@Override
|
1202 |
public void removeDatabaseWorkspace(DatabaseWorkspaceManager databaseWorkspace) { |
1203 |
this.databaseWorkspaces.remove(databaseWorkspace.getId(),databaseWorkspace);
|
1204 |
StoresRepository repo = databaseWorkspace.getStoresRepository(); |
1205 |
this.getStoresRepository().removeRepository(repo.getID());
|
1206 |
for (DatabaseWorkspaceListener listener : this.addDatabaseWorkspaceListeners.values()) { |
1207 |
if( listener!=null ) { |
1208 |
try {
|
1209 |
listener.onRemoveDatabaseWorkspace(databaseWorkspace); |
1210 |
} catch(Throwable th) { |
1211 |
LOGGER.warn("Problems calling databaseworkspace listener '"+listener.getName()+"'.",th); |
1212 |
} |
1213 |
} |
1214 |
} |
1215 |
try {
|
1216 |
ResourcesStorage resources = databaseWorkspace.getResourcesStorage(); |
1217 |
ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
1218 |
Script script = scriptManager.loadScript(resources, "OnDisconnectToWorkspace.script");
|
1219 |
if( script != null ) { |
1220 |
script.invokeFunction("main", new Object[] {databaseWorkspace}); |
1221 |
} |
1222 |
} catch(Throwable th) { |
1223 |
LOGGER.warn("Problems executing 'OnDisconnectToWorkspace.script' from workspace '"+databaseWorkspace.getId()+"'.",th); |
1224 |
} |
1225 |
} |
1226 |
|
1227 |
@Override
|
1228 |
public void addDatabaseWorkspace(DatabaseWorkspaceManager databaseWorkspace) { |
1229 |
this.databaseWorkspaces.put(databaseWorkspace.getId(),databaseWorkspace);
|
1230 |
StoresRepository repo = databaseWorkspace.getStoresRepository(); |
1231 |
this.getStoresRepository().addRepository(repo);
|
1232 |
|
1233 |
for (DatabaseWorkspaceListener listener : this.addDatabaseWorkspaceListeners.values()) { |
1234 |
if( listener!=null ) { |
1235 |
try {
|
1236 |
listener.onAddDatabaseWorkspace(databaseWorkspace); |
1237 |
} catch(Throwable th) { |
1238 |
LOGGER.warn("Problems calling databaseworkspace listener '"+listener.getName()+"'.",th); |
1239 |
} |
1240 |
} |
1241 |
} |
1242 |
try {
|
1243 |
ResourcesStorage resources = databaseWorkspace.getResourcesStorage(); |
1244 |
ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
1245 |
Script script = scriptManager.loadScript(resources, "OnConnectToWorkspace.script");
|
1246 |
if( script != null ) { |
1247 |
script.invokeFunction("main", new Object[] {databaseWorkspace}); |
1248 |
} |
1249 |
} catch(Throwable th) { |
1250 |
LOGGER.warn("Problems executing 'OnConnectToWorkspace.script' from workspace '"+databaseWorkspace.getId()+"'.",th); |
1251 |
} |
1252 |
} |
1253 |
|
1254 |
@Override
|
1255 |
public void addDatabaseWorkspaceListener(DatabaseWorkspaceListener listener) { |
1256 |
this.addDatabaseWorkspaceListeners.put(listener.getName(), listener);
|
1257 |
} |
1258 |
|
1259 |
@Override
|
1260 |
public DatabaseWorkspaceManager getDatabaseWorkspace(String name) { |
1261 |
if( StringUtils.isBlank(name) ) {
|
1262 |
return null; |
1263 |
} |
1264 |
return this.databaseWorkspaces.get(name); |
1265 |
} |
1266 |
|
1267 |
@Override
|
1268 |
public DatabaseWorkspaceManager getDatabaseWorkspace(DataStoreParameters params) {
|
1269 |
for (DatabaseWorkspaceManager databaseWorkspace : this.databaseWorkspaces.values()) { |
1270 |
if( databaseWorkspace.getStoresRepository().contains(params) ) {
|
1271 |
return databaseWorkspace;
|
1272 |
} |
1273 |
} |
1274 |
return null; |
1275 |
} |
1276 |
|
1277 |
@Override
|
1278 |
public void writeDALResource(ResourcesStorage resources, DataStore store) { |
1279 |
ResourcesStorage.Resource resource = null;
|
1280 |
try {
|
1281 |
if( resources == null || resources.isReadOnly() ) { |
1282 |
return;
|
1283 |
} |
1284 |
resource = resources.getResource("dal");
|
1285 |
if( resource == null || resource.isReadOnly() ) { |
1286 |
return;
|
1287 |
} |
1288 |
DALFile dalFile = DALFile.getDALFile(); |
1289 |
dalFile.setStore((DefaultFeatureStore) store); |
1290 |
if( !dalFile.isEmpty() ) {
|
1291 |
dalFile.write(resource); |
1292 |
} |
1293 |
} catch (Throwable ex) { |
1294 |
LOGGER.warn("Can't save DAL resource", ex);
|
1295 |
} finally {
|
1296 |
IOUtils.closeQuietly(resource); |
1297 |
} |
1298 |
|
1299 |
|
1300 |
} |
1301 |
|
1302 |
@Override
|
1303 |
public void writeDALResource(ResourcesStorage resources, FeatureType featureType) { |
1304 |
ResourcesStorage.Resource resource = null;
|
1305 |
try {
|
1306 |
if( resources == null || resources.isReadOnly() ) { |
1307 |
return;
|
1308 |
} |
1309 |
resource = resources.getResource("dal");
|
1310 |
if( resource == null || resource.isReadOnly() ) { |
1311 |
return;
|
1312 |
} |
1313 |
DALFile dalFile = DALFile.getDALFile(); |
1314 |
dalFile.setFeatureType(featureType); |
1315 |
if( !dalFile.isEmpty() ) {
|
1316 |
dalFile.write(resource); |
1317 |
} |
1318 |
} catch (Throwable ex) { |
1319 |
LOGGER.warn("Can't save DAL resource", ex);
|
1320 |
} finally {
|
1321 |
IOUtils.closeQuietly(resource); |
1322 |
} |
1323 |
} |
1324 |
|
1325 |
private Map<String,DynObjectValueItem[]> availableValues = null; |
1326 |
|
1327 |
@Override
|
1328 |
public void clearAvailableValuesCache() { |
1329 |
this.availableValues = null; |
1330 |
} |
1331 |
|
1332 |
@Override
|
1333 |
public DynObjectValueItem[] getAvailableValues(FeatureStore myStore, FeatureAttributeDescriptor descriptor) { |
1334 |
String keyName = myStore.getFullName() + ":columnName=" + descriptor.getName(); |
1335 |
if( this.availableValues==null ) { |
1336 |
this.availableValues = new HashMap<>(); |
1337 |
} |
1338 |
DynObjectValueItem[] values = this.availableValues.get(keyName); |
1339 |
if( values != null ) { |
1340 |
return values;
|
1341 |
} |
1342 |
if( !descriptor.isForeingKey() ) {
|
1343 |
return null; |
1344 |
} |
1345 |
ForeingKey foreingKey = descriptor.getForeingKey(); |
1346 |
FeatureStore foreingStore = null;
|
1347 |
DisposableFeatureSetIterable set = null;
|
1348 |
try {
|
1349 |
StoresRepository theStoresRepository; |
1350 |
FeatureStore store = descriptor.getStore(); |
1351 |
if (store == null) { |
1352 |
theStoresRepository = DALLocator.getDataManager().getStoresRepository(); |
1353 |
|
1354 |
} else {
|
1355 |
theStoresRepository = store.getStoresRepository(); |
1356 |
} |
1357 |
foreingStore = (FeatureStore) theStoresRepository.getStore( |
1358 |
foreingKey.getTableName() |
1359 |
); |
1360 |
Expression labelExpression = foreingKey.getLabelExpression(null); |
1361 |
String codeName = foreingKey.getCodeName();
|
1362 |
FeatureSymbolTable featureSymbolTable = this.createFeatureSymbolTable();
|
1363 |
MutableSymbolTable symbolTable = featureSymbolTable.createParent(); |
1364 |
|
1365 |
int count = (int) foreingStore.getFeatureCount(); |
1366 |
values = new DynObjectValueItem[Math.min(count, MAX_AVAILABLE_VALUES)]; |
1367 |
int n = 0; |
1368 |
for (Feature feature : set = foreingStore.getFeatureSet().iterable()) {
|
1369 |
Object code = feature.get(codeName);
|
1370 |
Object value;
|
1371 |
if (labelExpression == null) { |
1372 |
value = code; |
1373 |
} else {
|
1374 |
featureSymbolTable.setFeature(feature); |
1375 |
value = labelExpression.execute(symbolTable); |
1376 |
} |
1377 |
values[n++] = new DynObjectValueItem(code, Objects.toString(value, Objects.toString(code, "##ERROR##"))); |
1378 |
if( n>=MAX_AVAILABLE_VALUES ) {
|
1379 |
break;
|
1380 |
} |
1381 |
} |
1382 |
this.availableValues.put(keyName, values);
|
1383 |
return values;
|
1384 |
} catch (Exception ex) { |
1385 |
LOGGER.warn("Can't get available values for field '"+myStore.getName()+"."+descriptor.getName()+"' from table '" + foreingKey.getTableName() + "'.", ex); |
1386 |
} finally {
|
1387 |
DisposeUtils.disposeQuietly(set); |
1388 |
DisposeUtils.disposeQuietly(foreingStore); |
1389 |
} |
1390 |
return null; |
1391 |
} |
1392 |
|
1393 |
@Override
|
1394 |
public String createUniqueID() { |
1395 |
UUID x = UUID.randomUUID(); |
1396 |
String s = x.toString();
|
1397 |
return s;
|
1398 |
} |
1399 |
|
1400 |
@Override
|
1401 |
public EditableFeatureAttributeDescriptor createFeatureAttributeDescriptor() {
|
1402 |
DefaultEditableFeatureAttributeDescriptor edi = new DefaultEditableFeatureAttributeDescriptor(null, false); |
1403 |
return edi;
|
1404 |
} |
1405 |
|
1406 |
@Override
|
1407 |
public DALExpressionBuilder createDALExpressionBuilder() {
|
1408 |
return new DefaultDALExpressionBuilder(); |
1409 |
} |
1410 |
|
1411 |
@Override
|
1412 |
public void addStoreObserver(Observer observer) { |
1413 |
this.storeObservers.add(observer);
|
1414 |
} |
1415 |
|
1416 |
@Override
|
1417 |
public void removeStoreObserver(Observer observer) { |
1418 |
this.storeObservers.remove(observer);
|
1419 |
} |
1420 |
|
1421 |
@Override
|
1422 |
public String getServerExplorerFromStore(String name) { |
1423 |
Register r = this.getServerExplorerRegister();
|
1424 |
for (DataFactory factory0 : r) {
|
1425 |
DataServerExplorerFactory factory = (DataServerExplorerFactory) factory0; |
1426 |
if( factory.isStoreSupported(name) ) {
|
1427 |
return factory.getName();
|
1428 |
} |
1429 |
} |
1430 |
return null; |
1431 |
} |
1432 |
|
1433 |
@Override
|
1434 |
public void setMaxSizeForSmallFeatureSelection(long size){ |
1435 |
this.maxSizeForSmallFeatureSelection = size;
|
1436 |
} |
1437 |
|
1438 |
@Override
|
1439 |
public long getMaxSizeForSmallFeatureSelection() { |
1440 |
return this.maxSizeForSmallFeatureSelection; |
1441 |
} |
1442 |
|
1443 |
@Override
|
1444 |
public void registerLargeMap(Factory factory) { |
1445 |
this.largeMapFactory = factory;
|
1446 |
} |
1447 |
|
1448 |
@Override
|
1449 |
public void registerLargeSet(Factory factory) { |
1450 |
this.largeSetFactory = factory;
|
1451 |
} |
1452 |
|
1453 |
@Override
|
1454 |
public Map createLargeMap() { |
1455 |
return (Map) this.largeMapFactory.create(); |
1456 |
} |
1457 |
|
1458 |
@Override
|
1459 |
public Set createLargeSet() { |
1460 |
return (Set) this.largeSetFactory.create(); |
1461 |
} |
1462 |
|
1463 |
@Override
|
1464 |
public DataTransaction createTransaction() {
|
1465 |
DefaultTransaction transaction = new DefaultTransaction();
|
1466 |
return transaction;
|
1467 |
} |
1468 |
|
1469 |
@Override
|
1470 |
public void putFeaturesInClipboard(FeatureSet set) { |
1471 |
if( set==null ) { |
1472 |
return;
|
1473 |
} |
1474 |
String s = set.toJson().toString();
|
1475 |
ToolsSwingLocator.getToolsSwingManager().putInClipboard(s); |
1476 |
} |
1477 |
|
1478 |
@Override
|
1479 |
public List<EditableFeature> getFeaturesFromClipboard(FeatureStore store, Predicate<FeatureAttributeDescriptor> attrFilter) throws DataException { |
1480 |
if( store==null ) { |
1481 |
return Collections.EMPTY_LIST; |
1482 |
} |
1483 |
String clipboard = ToolsSwingLocator.getToolsSwingManager().getFromClipboard();
|
1484 |
if( StringUtils.isBlank(clipboard) ) {
|
1485 |
return Collections.EMPTY_LIST; |
1486 |
} |
1487 |
JsonArray array = Json.createArray(clipboard); |
1488 |
if (array == null) { |
1489 |
return Collections.EMPTY_LIST; |
1490 |
} |
1491 |
List<EditableFeature> features = new ArrayList<>(); |
1492 |
for (JsonValue jsonValue : array) {
|
1493 |
EditableFeature f = store.createNewFeature(); |
1494 |
f.copyFrom((JsonObject) jsonValue, attrFilter); |
1495 |
features.add(f); |
1496 |
} |
1497 |
return features;
|
1498 |
} |
1499 |
} |