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