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