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