Revision 43020 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
DefaultDataManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.impl; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.ExternalStoreProviderFactory; |
|
27 |
import java.io.File; |
|
28 |
import java.lang.reflect.InvocationTargetException; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.List; |
|
32 |
import java.util.Map; |
|
33 |
|
|
34 |
import org.gvsig.fmap.dal.DALLocator; |
|
35 |
import org.gvsig.fmap.dal.DataManager; |
|
36 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
37 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
38 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
|
39 |
import org.gvsig.fmap.dal.DataStore; |
|
40 |
import org.gvsig.fmap.dal.DataStoreFactory; |
|
41 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
42 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
|
43 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
44 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
|
45 |
import org.gvsig.fmap.dal.exception.DataException; |
|
46 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
47 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
48 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
49 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
51 |
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
|
52 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
53 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
54 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
55 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
56 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
57 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
|
58 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
|
59 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
|
60 |
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
|
61 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
|
62 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
|
63 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider; |
|
64 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
|
65 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
66 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
|
67 |
import org.gvsig.fmap.dal.raster.RasterStoreProviderFactory; |
|
68 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
|
69 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
|
70 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
71 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
|
72 |
import org.gvsig.fmap.dal.spi.DataStoreInitializer; |
|
73 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
|
74 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
75 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
|
76 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
|
77 |
import org.gvsig.fmap.geom.DataTypes; |
|
78 |
import org.gvsig.tools.ToolsLocator; |
|
79 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
80 |
import org.gvsig.tools.dynobject.DynObject; |
|
81 |
import org.gvsig.tools.dynobject.DynObjectEncoder; |
|
82 |
import org.gvsig.tools.dynobject.DynStruct; |
|
83 |
import org.gvsig.tools.dynobject.DynStruct_v2; |
|
84 |
import org.gvsig.tools.dynobject.Tags; |
|
85 |
import org.gvsig.tools.evaluator.Evaluator; |
|
86 |
import org.gvsig.tools.exception.BaseException; |
|
87 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
88 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
|
89 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
90 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
|
91 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
|
92 |
import org.gvsig.tools.operations.OperationManager; |
|
93 |
import org.slf4j.Logger; |
|
94 |
import org.slf4j.LoggerFactory; |
|
95 |
|
|
96 |
public class DefaultDataManager implements DataManager, |
|
97 |
DataManagerProviderServices { |
|
98 |
private static final Logger logger = LoggerFactory.getLogger(DefaultDataManager.class); |
|
99 |
|
|
100 |
final static private String DATA_MANAGER_STORE = "Data.manager.stores"; |
|
101 |
final static private String DATA_MANAGER_STORE_DESCRIPTION = |
|
102 |
"DAL stores providers"; |
|
103 |
|
|
104 |
final static private String DATA_MANAGER_STORE_PARAMS = |
|
105 |
"Data.manager.stores.params"; |
|
106 |
final static private String DATA_MANAGER_STORE_PARAMS_DESCRIPTION = |
|
107 |
"DAL stores providers parameters"; |
|
108 |
|
|
109 |
final static private String DATA_MANAGER_EXPLORER = |
|
110 |
"Data.manager.explorers"; |
|
111 |
final static private String DATA_MANAGER_EXPLORER_DESCRIPTION = |
|
112 |
"DAL explorers providers"; |
|
113 |
|
|
114 |
final static private String DATA_MANAGER_EXPLORER_PARAMS = |
|
115 |
"Data.manager.explorers.params"; |
|
116 |
final static private String DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION = |
|
117 |
"DAL explorer providers parameters"; |
|
118 |
|
|
119 |
final static private String DATA_MANAGER_INDEX = "Data.manager.indexes"; |
|
120 |
final static private String DATA_MANAGER_INDEX_DESCRIPTION = |
|
121 |
"DAL index providers"; |
|
122 |
|
|
123 |
final static private String DATA_MANAGER_CACHE = "Data.manager.caches"; |
|
124 |
final static private String DATA_MANAGER_CACHE_DESCRIPTION = |
|
125 |
"DAL cache providers"; |
|
126 |
|
|
127 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR = |
|
128 |
"Data.manager.expresion.evaluator"; |
|
129 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT = |
|
130 |
"default"; |
|
131 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION = |
|
132 |
"DAL expresion evaluators."; |
|
133 |
|
|
134 |
final static private String DATA_MANAGER_STORE_FACTORY = |
|
135 |
"Data.manager.stores.factory"; |
|
136 |
final static private String DATA_MANAGER_STORE_FACTORY_DESCRIPTION = |
|
137 |
"DAL stores factories"; |
|
138 |
|
|
139 |
final static private String DATA_MANAGER_STORE_PROVIDER_FACTORY = |
|
140 |
"Data.manager.providers.factory"; |
|
141 |
final static private String DATA_MANAGER_STORE_PROVIDER_FACTORY_DESCRIPTION = |
|
142 |
"DAL store provider factories"; |
|
143 |
|
|
144 |
final static private String DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER = |
|
145 |
"Data.manager.feature.attribute.getter"; |
|
146 |
final static private String DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER_DESCRIPTION = |
|
147 |
"DAL feature attribute getters"; |
|
148 |
|
|
149 |
/** This map contains the name of the default provider for each data type */ |
|
150 |
private Map defaultDataIndexProviders; |
|
151 |
|
|
152 |
private OpenErrorHandler openErrorHandler; |
|
153 |
|
|
154 |
private List dataTypes; |
|
155 |
|
|
156 |
private DataServerExplorerPool dataServerExplorerPool = null; |
|
157 |
|
|
158 |
|
|
159 |
public DefaultDataManager() { |
|
160 |
/* |
|
161 |
* Create te extensions point in te registry. |
|
162 |
*/ |
|
163 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE, |
|
164 |
DATA_MANAGER_STORE_DESCRIPTION); |
|
165 |
|
|
166 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS, |
|
167 |
DATA_MANAGER_STORE_PARAMS_DESCRIPTION); |
|
168 |
|
|
169 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER, |
|
170 |
DATA_MANAGER_EXPLORER_DESCRIPTION); |
|
171 |
|
|
172 |
ToolsLocator.getExtensionPointManager().add( |
|
173 |
DATA_MANAGER_EXPLORER_PARAMS, |
|
174 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION); |
|
175 |
|
|
176 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX, |
|
177 |
DATA_MANAGER_INDEX_DESCRIPTION); |
|
178 |
|
|
179 |
ToolsLocator.getExtensionPointManager().add( |
|
180 |
DATA_MANAGER_EXPRESION_EVALUATOR, |
|
181 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION); |
|
182 |
|
|
183 |
ToolsLocator.getExtensionPointManager().add( |
|
184 |
DATA_MANAGER_STORE_PROVIDER_FACTORY, |
|
185 |
DATA_MANAGER_STORE_PROVIDER_FACTORY_DESCRIPTION); |
|
186 |
|
|
187 |
initializeIndexes(); |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* |
|
192 |
* @return ResourceManager |
|
193 |
*/ |
|
194 |
|
|
195 |
public ResourceManager getResourceManager() { |
|
196 |
return DALLocator.getResourceManager(); |
|
197 |
} |
|
198 |
|
|
199 |
public OperationManager getOperationManager() { |
|
200 |
return ToolsLocator.getOperationManager(); |
|
201 |
} |
|
202 |
|
|
203 |
public String getTemporaryDirectory() { |
|
204 |
// FIXME Define a better tempdir solution |
|
205 |
String tmp = System.getProperty("TMP"); |
|
206 |
if (tmp == null) { |
|
207 |
tmp = System.getProperty("TEMP"); |
|
208 |
} |
|
209 |
if (tmp == null) { |
|
210 |
File tmp_file = new File(System.getProperty("HOME"), "_daltmp_"); |
|
211 |
int i = 1; |
|
212 |
while (!tmp_file.exists() || !tmp_file.isDirectory()) { |
|
213 |
tmp_file = new File(tmp_file.getAbsolutePath() + i); |
|
214 |
i++; |
|
215 |
} |
|
216 |
if (!tmp_file.exists()) { |
|
217 |
tmp_file.mkdir(); |
|
218 |
} |
|
219 |
tmp = tmp_file.getAbsolutePath(); |
|
220 |
} |
|
221 |
return tmp; |
|
222 |
} |
|
223 |
|
|
224 |
/* |
|
225 |
* ==================================================================== |
|
226 |
* |
|
227 |
* Store related services |
|
228 |
*/ |
|
229 |
@Override |
|
230 |
public void registerStoreProvider(String name, Class storeProviderClass, |
|
231 |
Class parametersClass) { |
|
232 |
if (name == null || storeProviderClass == null || parametersClass == null) { |
|
233 |
throw new IllegalArgumentException("Any parameters can be null"); |
|
234 |
} |
|
235 |
|
|
236 |
if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) { |
|
237 |
throw new IllegalArgumentException(parametersClass.getName() |
|
238 |
+ " must implement org.gvsig.fmap.dal.DataStoreParameters"); |
|
239 |
} |
|
240 |
|
|
241 |
if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) { |
|
242 |
// Envuelve al proveedor en una factoria por defecto. |
|
243 |
this.registerStoreProviderFactory(new DataStoreProviderToCoverageProviderFactoryWrapper( |
|
244 |
name, "", storeProviderClass, parametersClass)); |
|
245 |
return; |
|
246 |
} |
|
247 |
|
|
248 |
if (FeatureStoreProvider.class.isAssignableFrom(storeProviderClass)) { |
|
249 |
// Envuelve al proveedor en una factoria por defecto. |
|
250 |
this.registerStoreProviderFactory(new DataStoreProviderToFeatureStoreProviderFactoryWrapper( |
|
251 |
name, "", storeProviderClass, parametersClass)); |
|
252 |
return; |
|
253 |
} |
|
254 |
|
|
255 |
throw new IllegalArgumentException("Not supported implemtation: name=" |
|
256 |
+ name + " provider class=" + storeProviderClass.getName()); |
|
257 |
|
|
258 |
} |
|
259 |
|
|
260 |
public void registerStoreProviderFactory(DataStoreProviderFactory factory) { |
|
261 |
ExtensionPoint factories = |
|
262 |
ToolsLocator.getExtensionPointManager().add( |
|
263 |
DATA_MANAGER_STORE_PROVIDER_FACTORY, |
|
264 |
DATA_MANAGER_STORE_PROVIDER_FACTORY_DESCRIPTION); |
|
265 |
factories.append(factory.getName(), factory.getDescription(), factory); |
|
266 |
|
|
267 |
} |
|
268 |
|
|
269 |
public void registerStoreFactory(String name, Class storeProviderClass) { |
|
270 |
if (name == null || storeProviderClass == null) { |
|
271 |
// FIXME Exception |
|
272 |
throw new IllegalArgumentException("Any parameters can be null"); |
|
273 |
} |
|
274 |
|
|
275 |
if (!(DataStoreFactory.class.isAssignableFrom(storeProviderClass))) { |
|
276 |
// FIXME Exception |
|
277 |
throw new IllegalArgumentException( |
|
278 |
"Not supported implemtation: name=" + name + " provider class=" |
|
279 |
+ storeProviderClass.getName()); |
|
280 |
} |
|
281 |
|
|
282 |
ToolsLocator |
|
283 |
.getExtensionPointManager() |
|
284 |
.add(DATA_MANAGER_STORE_FACTORY, |
|
285 |
DATA_MANAGER_STORE_FACTORY_DESCRIPTION) |
|
286 |
.append(name, null, storeProviderClass); |
|
287 |
} |
|
288 |
|
|
289 |
public DataStoreParameters createStoreParameters(String name) |
|
290 |
throws InitializeException, ProviderNotRegisteredException { |
|
291 |
try { |
|
292 |
|
|
293 |
// Si hay una factoria para ese proveedor se los pedimos a la |
|
294 |
// factoria |
|
295 |
DataStoreProviderFactory providerFactory = |
|
296 |
(DataStoreProviderFactory) ToolsLocator |
|
297 |
.getExtensionPointManager() |
|
298 |
.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name); |
|
299 |
if (providerFactory != null) { |
|
300 |
return (DataStoreParameters) providerFactory.createParameters(); |
|
301 |
} |
|
302 |
|
|
303 |
// Si no hay factoria lo hacemos como se hacia antes por mantener |
|
304 |
// compatibilidad. |
|
305 |
DataStoreParameters params = |
|
306 |
(DataStoreParameters) ToolsLocator.getExtensionPointManager() |
|
307 |
.get(DATA_MANAGER_STORE_PARAMS).create(name); |
|
308 |
if (params == null) { |
|
309 |
throw new ProviderNotRegisteredException(name); |
|
310 |
} |
|
311 |
return params; |
|
312 |
} catch (InstantiationException e) { |
|
313 |
throw new InitializeException(e); |
|
314 |
} catch (IllegalAccessException e) { |
|
315 |
throw new InitializeException(e); |
|
316 |
} catch (SecurityException e) { |
|
317 |
throw new InitializeException(e); |
|
318 |
} catch (IllegalArgumentException e) { |
|
319 |
throw new InitializeException(e); |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
public DataStoreParameters toDataStoreParameters(String provider, DynObject doparams) throws InitializeException, ProviderNotRegisteredException { |
|
324 |
if (doparams instanceof DataStoreParameters) { |
|
325 |
return (DataStoreParameters) doparams; |
|
326 |
} |
|
327 |
String providerName; |
|
328 |
try { |
|
329 |
providerName = (String) doparams.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
|
330 |
} catch(Exception ex) { |
|
331 |
providerName = provider; |
|
332 |
} |
|
333 |
DataStoreParameters parameters = DALLocator.getDataManager().createStoreParameters(providerName); |
|
334 |
ToolsLocator.getDynObjectManager().copy(doparams, parameters); |
|
335 |
return parameters; |
|
336 |
} |
|
337 |
|
|
338 |
private DataStore localOpenStore(String provider, |
|
339 |
DynObject doparameters) throws InitializeException, |
|
340 |
ProviderNotRegisteredException, ValidateDataParametersException { |
|
341 |
|
|
342 |
DataStoreParameters parameters = toDataStoreParameters(provider, doparameters); |
|
343 |
|
|
344 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
|
345 |
if( ! identityManager.getCurrentIdentity().isAuthorized(READ_STORE_AUTHORIZATION, parameters, provider) ) { |
|
346 |
throw new UnauthorizedException(READ_STORE_AUTHORIZATION, parameters, provider); |
|
347 |
} |
|
348 |
|
|
349 |
// Usa el DynObjectEncoder y no el toString para poder ver los parametros aunque |
|
350 |
// el proveedor de datos sobreescriba el metodo toString. |
|
351 |
DynObjectEncoder encoder = ToolsLocator.getDynObjectManager().createSimpleDynObjectEncoder(); |
|
352 |
logger.info("openStore('{}','{}')", provider, encoder.encode(parameters)); |
|
353 |
|
|
354 |
String name = provider; |
|
355 |
|
|
356 |
parameters.validate(); |
|
357 |
|
|
358 |
DataStoreProviderFactory providerFactory = this.getStoreProviderFactory(name); |
|
359 |
if( providerFactory == null ) { |
|
360 |
throw new CantFindTheProviderFactoryException(name); |
|
361 |
} |
|
362 |
if( providerFactory instanceof FeatureStoreProviderFactory ) { |
|
363 |
DataStore store = this.createDefaultFeatureStore(); |
|
364 |
this.intializeDataStore(store, parameters); |
|
365 |
return store; |
|
366 |
|
|
367 |
} else if( providerFactory instanceof RasterStoreProviderFactory ) { |
|
368 |
DataStore store = this.createDefaultRasterStore(); |
|
369 |
this.intializeDataStore(store, parameters); |
|
370 |
return store; |
|
371 |
|
|
372 |
} else if( providerFactory instanceof ExternalStoreProviderFactory ) { |
|
373 |
DataStoreFactory factory = this.getStoreFactory(name); |
|
374 |
factory.setParameters(parameters); |
|
375 |
DataStore store = factory.createStore(); |
|
376 |
this.intializeDataStore(store, parameters); |
|
377 |
return store; |
|
378 |
|
|
379 |
} |
|
380 |
throw new UnsupportedProviderFactoryException(name,providerFactory); |
|
381 |
} |
|
382 |
|
|
383 |
private static class UnsupportedProviderFactoryException extends InitializeException { |
|
384 |
private static final long serialVersionUID = 2635455949723618046L; |
|
385 |
|
|
386 |
public UnsupportedProviderFactoryException(String resourceName,DataStoreProviderFactory providerFactory) { |
|
387 |
super("Error intializing resource '%(resource)'. Unsupported provider factory '%(factory).", |
|
388 |
"_UnsupportedProviderFactoryException", |
|
389 |
serialVersionUID |
|
390 |
); |
|
391 |
setValue("resource", resourceName); |
|
392 |
setValue("factory", providerFactory.getClass().getName()); |
|
393 |
} |
|
394 |
|
|
395 |
} |
|
396 |
|
|
397 |
private static class CantFindTheProviderFactoryException extends InitializeException { |
|
398 |
private static final long serialVersionUID = -2736434434177690011L; |
|
399 |
|
|
400 |
public CantFindTheProviderFactoryException(String resourceName) { |
|
401 |
super("Error intializing resource '%(resource)'. Can't find provider factory for this resource.", |
|
402 |
"_CantFindTheProviderFactoryException", |
|
403 |
serialVersionUID |
|
404 |
); |
|
405 |
setValue("resource", resourceName); |
|
406 |
} |
|
407 |
|
|
408 |
} |
|
409 |
|
|
410 |
private DataStore createDefaultFeatureStore() { |
|
411 |
return new DefaultFeatureStore(); |
|
412 |
} |
|
413 |
|
|
414 |
private DataStore createDefaultRasterStore() { |
|
415 |
try { |
|
416 |
return (DataStore) this.defaultRasterStoreClass.newInstance(); |
|
417 |
} catch (InstantiationException | IllegalAccessException ex) { |
|
418 |
throw new RuntimeException("Can't create the default RasterStore", ex); |
|
419 |
} |
|
420 |
} |
|
421 |
|
|
422 |
private Class defaultRasterStoreClass = null; |
|
423 |
public void registerDefaultRasterStore(Class rasterStoreClass) { |
|
424 |
this.defaultRasterStoreClass = rasterStoreClass; |
|
425 |
} |
|
426 |
|
|
427 |
private DataStoreFactory getStoreFactory(String name) throws InitializeException { |
|
428 |
ExtensionPoint.Extension point = |
|
429 |
ToolsLocator.getExtensionPointManager() |
|
430 |
.get(DATA_MANAGER_STORE_FACTORY).get(name); |
|
431 |
try { |
|
432 |
DataStoreFactory factory = (DataStoreFactory) point.create(); |
|
433 |
return factory; |
|
434 |
} catch (InstantiationException | IllegalAccessException e) { |
|
435 |
throw new InitializeException(e); |
|
436 |
} |
|
437 |
} |
|
438 |
|
|
439 |
public DataStore openStore(String provider, DynObject parameters) |
|
440 |
throws InitializeException, ProviderNotRegisteredException, |
|
441 |
ValidateDataParametersException { |
|
442 |
|
|
443 |
return localOpenStore(provider, parameters); |
|
444 |
} |
|
445 |
|
|
446 |
@Override |
|
447 |
public DataStore openStore(String provider, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
|
448 |
return localOpenStore(provider, parameters); |
|
449 |
} |
|
450 |
|
|
451 |
|
|
452 |
|
|
453 |
/** |
|
454 |
* @deprecated see openStore |
|
455 |
*/ |
|
456 |
public DataStore createStore(DynObject doparameters) |
|
457 |
throws InitializeException, ProviderNotRegisteredException, |
|
458 |
ValidateDataParametersException { |
|
459 |
DataStoreParameters parameters = toDataStoreParameters(null,doparameters); |
|
460 |
return openStore(parameters.getDataStoreName(), parameters); |
|
461 |
} |
|
462 |
|
|
463 |
/** |
|
464 |
* @deprecated see openStore |
|
465 |
*/ |
|
466 |
@Override |
|
467 |
public DataStore createStore(DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
|
468 |
return this.openStore(parameters.getDataStoreName(), parameters); |
|
469 |
} |
|
470 |
|
|
471 |
|
|
472 |
public List getStoreProviders() { |
|
473 |
ExtensionPointManager epmanager = |
|
474 |
ToolsLocator.getExtensionPointManager(); |
|
475 |
List names1 = epmanager.get(DATA_MANAGER_STORE).getNames(); |
|
476 |
List names2 = |
|
477 |
epmanager.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).getNames(); |
|
478 |
List names3 = new ArrayList(); |
|
479 |
names3.addAll(names1); |
|
480 |
names3.addAll(names2); |
|
481 |
return names3; |
|
482 |
} |
|
483 |
|
|
484 |
@Override |
|
485 |
public DataStoreProviderFactory getStoreProviderFactory(String name) { |
|
486 |
try { |
|
487 |
return (DataStoreProviderFactory) ToolsLocator |
|
488 |
.getExtensionPointManager() |
|
489 |
.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name); |
|
490 |
} catch (InstantiationException | IllegalAccessException e) { |
|
491 |
return null; |
|
492 |
} |
|
493 |
} |
|
494 |
|
|
495 |
public List getStoreProviders(String name) { |
|
496 |
return getStoreProviders(); // FIXME: need filter from the name of |
|
497 |
// the explorer |
|
498 |
} |
|
499 |
|
|
500 |
public NewDataStoreParameters createNewStoreParameters(String explorer, |
|
501 |
String provider) throws InitializeException, |
|
502 |
ProviderNotRegisteredException { |
|
503 |
|
|
504 |
DataServerExplorerParameters parameters; |
|
505 |
DataServerExplorer server; |
|
506 |
try { |
|
507 |
parameters = this.createServerExplorerParameters(explorer); |
|
508 |
server = |
|
509 |
this.openServerExplorerWithoutValidate(explorer, parameters); |
|
510 |
return server.getAddParameters(provider); |
|
511 |
} catch (ValidateDataParametersException e) { |
|
512 |
throw new InitializeException(e); |
|
513 |
} catch (DataException e) { |
|
514 |
throw new InitializeException(e); |
|
515 |
} |
|
516 |
} |
|
517 |
|
|
518 |
public void newStore(String explorer, String provider, |
|
519 |
NewDataStoreParameters parameters, boolean overwrite) |
|
520 |
throws InitializeException, ProviderNotRegisteredException, |
|
521 |
ValidateDataParametersException { |
|
522 |
|
|
523 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
|
524 |
if( ! identityManager.getCurrentIdentity().isAuthorized(CREATE_STORE_AUTHORIZATION, parameters, provider) ) { |
|
525 |
throw new UnauthorizedException(CREATE_STORE_AUTHORIZATION, parameters, provider); |
|
526 |
} |
|
527 |
parameters.validate(); |
|
528 |
|
|
529 |
DataServerExplorerParameters explorerParameters; |
|
530 |
DataServerExplorer server; |
|
531 |
explorerParameters = this.createServerExplorerParameters(explorer); |
|
532 |
server = |
|
533 |
this.openServerExplorerWithoutValidate(explorer, explorerParameters); |
|
534 |
try { |
|
535 |
server.add(provider, parameters, overwrite); |
|
536 |
} catch (DataException e) { |
|
537 |
throw new InitializeException(e); |
|
538 |
} |
|
539 |
} |
|
540 |
|
|
541 |
/* |
|
542 |
* ==================================================================== |
|
543 |
* |
|
544 |
* Explorer related services |
|
545 |
*/ |
|
546 |
public void registerExplorerProvider(String name, Class explorerClass, |
|
547 |
Class parametersClass) { |
|
548 |
|
|
549 |
if (name == null || explorerClass == null || parametersClass == null) { |
|
550 |
// FIXME Exception |
|
551 |
throw new IllegalArgumentException("Any parameters can be null"); |
|
552 |
} |
|
553 |
|
|
554 |
if (!DataServerExplorerParameters.class |
|
555 |
.isAssignableFrom(parametersClass)) { |
|
556 |
// FIXME Exception |
|
557 |
throw new IllegalArgumentException( |
|
558 |
parametersClass.getName() |
|
559 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorerParameters"); |
|
560 |
} |
|
561 |
|
|
562 |
if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) { |
|
563 |
// FIXME Exception |
|
564 |
throw new IllegalArgumentException(explorerClass.getName() |
|
565 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorer"); |
|
566 |
} |
|
567 |
|
|
568 |
ToolsLocator.getExtensionPointManager() |
|
569 |
.add(DATA_MANAGER_EXPLORER, DATA_MANAGER_EXPLORER_DESCRIPTION) |
|
570 |
.append(name, null, explorerClass); |
|
571 |
|
|
572 |
ToolsLocator |
|
573 |
.getExtensionPointManager() |
|
574 |
.add(DATA_MANAGER_EXPLORER_PARAMS, |
|
575 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION) |
|
576 |
.append(name, null, parametersClass); |
|
577 |
} |
|
578 |
|
|
579 |
public DataServerExplorerParameters createServerExplorerParameters( |
|
580 |
String name) throws InitializeException, ProviderNotRegisteredException { |
|
581 |
try { |
|
582 |
DataServerExplorerParameters params = |
|
583 |
(DataServerExplorerParameters) ToolsLocator |
|
584 |
.getExtensionPointManager() |
|
585 |
.get(DATA_MANAGER_EXPLORER_PARAMS).create(name); |
|
586 |
if (params == null) { |
|
587 |
throw new ProviderNotRegisteredException(name); |
|
588 |
} |
|
589 |
return params; |
|
590 |
} catch (InstantiationException e) { |
|
591 |
throw new InitializeException(e); |
|
592 |
} catch (IllegalAccessException e) { |
|
593 |
throw new InitializeException(e); |
|
594 |
} catch (SecurityException e) { |
|
595 |
throw new InitializeException(e); |
|
596 |
} catch (IllegalArgumentException e) { |
|
597 |
throw new InitializeException(e); |
|
598 |
} |
|
599 |
} |
|
600 |
|
|
601 |
public DataServerExplorer openServerExplorer(String explorer, |
|
602 |
DataServerExplorerParameters parameters) throws InitializeException, |
|
603 |
ProviderNotRegisteredException, ValidateDataParametersException { |
|
604 |
|
|
605 |
if (parameters != null) { |
|
606 |
parameters.validate(); |
|
607 |
} |
|
608 |
return this.openServerExplorerWithoutValidate(explorer, parameters); |
|
609 |
} |
|
610 |
|
|
611 |
private DataServerExplorer openServerExplorerWithoutValidate( |
|
612 |
String explorerName, DataServerExplorerParameters parameters) |
|
613 |
throws InitializeException, ProviderNotRegisteredException, |
|
614 |
ValidateDataParametersException { |
|
615 |
|
|
616 |
String name = explorerName; // parameters.getExplorerName(); |
|
617 |
|
|
618 |
try { |
|
619 |
DataServerExplorerProvider server = |
|
620 |
(DataServerExplorerProvider) ToolsLocator |
|
621 |
.getExtensionPointManager() |
|
622 |
.get(DATA_MANAGER_EXPLORER) |
|
623 |
.create( |
|
624 |
name, |
|
625 |
new Object[] { parameters, |
|
626 |
new DefaultDataServerExplorerProviderServices() }); |
|
627 |
if (server == null) { |
|
628 |
throw new ProviderNotRegisteredException(name); |
|
629 |
} |
|
630 |
return server; |
|
631 |
} catch (InstantiationException e) { |
|
632 |
throw new InitializeException(e); |
|
633 |
} catch (IllegalAccessException e) { |
|
634 |
throw new InitializeException(e); |
|
635 |
} catch (SecurityException e) { |
|
636 |
throw new InitializeException(e); |
|
637 |
} catch (IllegalArgumentException e) { |
|
638 |
throw new InitializeException(e); |
|
639 |
} catch (NoSuchMethodException e) { |
|
640 |
throw new InitializeException(e); |
|
641 |
} catch (InvocationTargetException e) { |
|
642 |
throw new InitializeException(e); |
|
643 |
} |
|
644 |
} |
|
645 |
|
|
646 |
/** |
|
647 |
* @deprecated see openServerExplorer |
|
648 |
*/ |
|
649 |
public DataServerExplorer createServerExplorer( |
|
650 |
DataServerExplorerParameters parameters) throws InitializeException, |
|
651 |
ProviderNotRegisteredException, ValidateDataParametersException { |
|
652 |
return openServerExplorer(parameters.getExplorerName(), parameters); |
|
653 |
} |
|
654 |
|
|
655 |
public List getExplorerProviders() { |
|
656 |
return ToolsLocator.getExtensionPointManager() |
|
657 |
.get(DATA_MANAGER_EXPLORER).getNames(); |
|
658 |
} |
|
659 |
|
|
660 |
/* |
|
661 |
* ==================================================================== |
|
662 |
* |
|
663 |
* Expresion evaluation related services |
|
664 |
*/ |
|
665 |
public Evaluator createExpresion(String expresion) |
|
666 |
throws InitializeException { |
|
667 |
try { |
|
668 |
return (Evaluator) ToolsLocator |
|
669 |
.getExtensionPointManager() |
|
670 |
.get(DATA_MANAGER_EXPRESION_EVALUATOR) |
|
671 |
.create(DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
|
672 |
new Object[] { expresion }); |
|
673 |
} catch (SecurityException e) { |
|
674 |
throw new InitializeException(e); |
|
675 |
} catch (IllegalArgumentException e) { |
|
676 |
throw new InitializeException(e); |
|
677 |
} catch (NoSuchMethodException e) { |
|
678 |
throw new InitializeException(e); |
|
679 |
} catch (InstantiationException e) { |
|
680 |
throw new InitializeException(e); |
|
681 |
} catch (IllegalAccessException e) { |
|
682 |
throw new InitializeException(e); |
|
683 |
} catch (InvocationTargetException e) { |
|
684 |
throw new InitializeException(e); |
|
685 |
} |
|
686 |
} |
|
687 |
|
|
688 |
public void registerDefaultEvaluator(Class evaluatorClass) { |
|
689 |
if (!Evaluator.class.isAssignableFrom(evaluatorClass)) { |
|
690 |
throw new ClassCastException(); |
|
691 |
} |
|
692 |
ToolsLocator |
|
693 |
.getExtensionPointManager() |
|
694 |
.add(DATA_MANAGER_EXPRESION_EVALUATOR, |
|
695 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION) |
|
696 |
.append(DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
|
697 |
"Default expresion evaluator for use in DAL", evaluatorClass); |
|
698 |
} |
|
699 |
|
|
700 |
/* |
|
701 |
* ==================================================================== |
|
702 |
* |
|
703 |
* Index related services |
|
704 |
*/ |
|
705 |
|
|
706 |
public List getFeatureIndexProviders() { |
|
707 |
return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_INDEX) |
|
708 |
.getNames(); |
|
709 |
} |
|
710 |
|
|
711 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
|
712 |
defaultDataIndexProviders.put(new Integer(dataType), name); |
|
713 |
} |
|
714 |
|
|
715 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
|
716 |
return (String) defaultDataIndexProviders.get(new Integer(dataType)); |
|
717 |
} |
|
718 |
|
|
719 |
public FeatureIndexProviderServices createFeatureIndexProvider(String name, |
|
720 |
FeatureStore store, FeatureType type, String indexName, |
|
721 |
FeatureAttributeDescriptor attr) throws InitializeException, |
|
722 |
ProviderNotRegisteredException { |
|
723 |
|
|
724 |
if (name == null) { |
|
725 |
name = getDefaultFeatureIndexProviderName(attr.getType()); |
|
726 |
} |
|
727 |
|
|
728 |
if (name == null) { |
|
729 |
throw new InitializeException( |
|
730 |
"There not any index provider registered.", null); |
|
731 |
} |
|
732 |
|
|
733 |
try { |
|
734 |
FeatureIndexProvider provider = |
|
735 |
(FeatureIndexProvider) ToolsLocator.getExtensionPointManager() |
|
736 |
.get(DATA_MANAGER_INDEX).create(name); |
|
737 |
if (provider == null) { |
|
738 |
throw new ProviderNotRegisteredException(name); |
|
739 |
} |
|
740 |
FeatureIndexProviderServices services = |
|
741 |
new DefaultFeatureIndex((FeatureStoreProviderServices) store, |
|
742 |
type, provider, attr.getName(), indexName); |
|
743 |
services.initialize(); |
|
744 |
return services; |
|
745 |
} catch (InstantiationException e) { |
|
746 |
throw new InitializeException(e); |
|
747 |
} catch (IllegalAccessException e) { |
|
748 |
throw new InitializeException(e); |
|
749 |
} catch (SecurityException e) { |
|
750 |
throw new InitializeException(e); |
|
751 |
} catch (IllegalArgumentException e) { |
|
752 |
throw new InitializeException(e); |
|
753 |
} |
|
754 |
} |
|
755 |
|
|
756 |
public void registerFeatureIndexProvider(String name, String description, |
|
757 |
Class clazz, int dataType) { |
|
758 |
ToolsLocator.getExtensionPointManager() |
|
759 |
.add(DATA_MANAGER_INDEX, DATA_MANAGER_INDEX_DESCRIPTION) |
|
760 |
.append(name, null, clazz); |
|
761 |
|
|
762 |
if (getDefaultFeatureIndexProviderName(dataType) == null) { |
|
763 |
setDefaultFeatureIndexProviderName(dataType, name); |
|
764 |
} |
|
765 |
} |
|
766 |
|
|
767 |
private void initializeIndexes() { |
|
768 |
this.defaultDataIndexProviders = new HashMap(); |
|
769 |
} |
|
770 |
|
|
771 |
public void intializeDataStore(DataStore store, |
|
772 |
DataStoreParameters parameters) throws InitializeException, |
|
773 |
ProviderNotRegisteredException { |
|
774 |
|
|
775 |
((DataStoreInitializer) store).intializePhase1(this, parameters); |
|
776 |
DataStoreProvider provider = |
|
777 |
this.createProvider((DataStoreProviderServices) store, parameters); |
|
778 |
((DataStoreInitializer) store).intializePhase2(provider); |
|
779 |
|
|
780 |
} |
|
781 |
|
|
782 |
public DataStoreProvider createProvider( |
|
783 |
DataStoreProviderServices providerServices, |
|
784 |
DataStoreParameters parameters) throws InitializeException, |
|
785 |
ProviderNotRegisteredException { |
|
786 |
String name = parameters.getDataStoreName(); |
|
787 |
DataStoreProvider provider = null; |
|
788 |
boolean retry = true; |
|
789 |
while (retry) { |
|
790 |
try { |
|
791 |
DataStoreProviderFactory providerFactory = |
|
792 |
(DataStoreProviderFactory) ToolsLocator |
|
793 |
.getExtensionPointManager() |
|
794 |
.get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name); |
|
795 |
if (providerFactory != null) { |
|
796 |
provider = |
|
797 |
(DataStoreProvider) providerFactory.createProvider( |
|
798 |
parameters, providerServices); |
|
799 |
} else { |
|
800 |
provider = |
|
801 |
(DataStoreProvider) ToolsLocator |
|
802 |
.getExtensionPointManager() |
|
803 |
.get(DATA_MANAGER_STORE) |
|
804 |
.create(name, |
|
805 |
new Object[] { parameters, providerServices }); |
|
806 |
} |
|
807 |
retry = false; |
|
808 |
} catch (Exception e) { |
|
809 |
if (openErrorHandler != null) { |
|
810 |
retry = openErrorHandler.canRetryOpen(e, parameters); |
|
811 |
} else { |
|
812 |
retry = false; |
|
813 |
} |
|
814 |
if (!retry) { |
|
815 |
throw new InitializeException( |
|
816 |
parameters.getDataStoreName(), e); |
|
817 |
} |
|
818 |
} |
|
819 |
} |
|
820 |
if (provider == null) { |
|
821 |
throw new ProviderNotRegisteredException(name); |
|
822 |
} |
|
823 |
return provider; |
|
824 |
} |
|
825 |
|
|
826 |
public void registerFeatureCacheProvider( |
|
827 |
FeatureCacheProviderFactory providerFactory) { |
|
828 |
ToolsLocator.getExtensionPointManager() |
|
829 |
.add(DATA_MANAGER_CACHE, DATA_MANAGER_CACHE_DESCRIPTION) |
|
830 |
.append(providerFactory.getName(), "", providerFactory); |
|
831 |
} |
|
832 |
|
|
833 |
public FeatureCacheProvider createFeatureCacheProvider(String name, |
|
834 |
DynObject parameters) throws DataException { |
|
835 |
if (name == null) { |
|
836 |
throw new InitializeException( |
|
837 |
"It is necessary to provide a cache name", null); |
|
838 |
} |
|
839 |
if (parameters == null) { |
|
840 |
throw new InitializeException( |
|
841 |
"It is necessary to provide parameters to create the explorer", |
|
842 |
null); |
|
843 |
} |
|
844 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
|
845 |
try { |
|
846 |
featureCacheProviderFactory = |
|
847 |
(FeatureCacheProviderFactory) ToolsLocator |
|
848 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
|
849 |
.create(name); |
|
850 |
if (featureCacheProviderFactory == null) { |
|
851 |
throw new ProviderNotRegisteredException(name); |
|
852 |
} |
|
853 |
return featureCacheProviderFactory.createCacheProvider(parameters); |
|
854 |
} catch (InstantiationException e) { |
|
855 |
throw new InitializeException(e); |
|
856 |
} catch (IllegalAccessException e) { |
|
857 |
throw new InitializeException(e); |
|
858 |
} |
|
859 |
} |
|
860 |
|
|
861 |
public List getFeatureCacheProviders() { |
|
862 |
ExtensionPoint extensionPoint = |
|
863 |
ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_CACHE); |
|
864 |
if (extensionPoint != null) { |
|
865 |
return ToolsLocator.getExtensionPointManager() |
|
866 |
.get(DATA_MANAGER_CACHE).getNames(); |
|
867 |
} else { |
|
868 |
return new ArrayList(); |
|
869 |
} |
|
870 |
} |
|
871 |
|
|
872 |
public DynObject createCacheParameters(String name) |
|
873 |
throws InitializeException, ProviderNotRegisteredException { |
|
874 |
if (name == null) { |
|
875 |
throw new InitializeException( |
|
876 |
"It is necessary to provide a cache name", null); |
|
877 |
} |
|
878 |
FeatureCacheProviderFactory featureCacheProviderFactory; |
|
879 |
try { |
|
880 |
featureCacheProviderFactory = |
|
881 |
(FeatureCacheProviderFactory) ToolsLocator |
|
882 |
.getExtensionPointManager().get(DATA_MANAGER_CACHE) |
|
883 |
.create(name); |
|
884 |
if (featureCacheProviderFactory == null) { |
|
885 |
throw new ProviderNotRegisteredException(name); |
|
886 |
} |
|
887 |
return featureCacheProviderFactory.createParameters(); |
|
888 |
} catch (InstantiationException e) { |
|
889 |
throw new InitializeException(e); |
|
890 |
} catch (IllegalAccessException e) { |
|
891 |
throw new InitializeException(e); |
|
892 |
} |
|
893 |
} |
|
894 |
|
|
895 |
public DataStoreParameters createMemoryStoreParameters( |
|
896 |
String autoOrderAttributeName) throws InitializeException { |
|
897 |
|
|
898 |
DataStoreParameters parameters; |
|
899 |
try { |
|
900 |
parameters = createStoreParameters(MemoryStoreProvider.NAME); |
|
901 |
if (autoOrderAttributeName != null) { |
|
902 |
parameters.setDynValue( |
|
903 |
MemoryStoreParameters.ORDER_PARAMETER_NAME, |
|
904 |
autoOrderAttributeName); |
|
905 |
} |
|
906 |
return parameters; |
|
907 |
} catch (ProviderNotRegisteredException e) { |
|
908 |
throw new InitializeException("MemoryStoreProvider", e); |
|
909 |
} |
|
910 |
} |
|
911 |
|
|
912 |
public FeatureStore createMemoryStore(String autoOrderAttributeName) |
|
913 |
throws InitializeException { |
|
914 |
|
|
915 |
DataStoreParameters parameters = |
|
916 |
createMemoryStoreParameters(autoOrderAttributeName); |
|
917 |
try { |
|
918 |
return (FeatureStore) createStore(parameters); |
|
919 |
} catch (ValidateDataParametersException e) { |
|
920 |
throw new InitializeException("MemoryStoreProvider", e); |
|
921 |
} catch (ProviderNotRegisteredException e) { |
|
922 |
throw new InitializeException("MemoryStoreProvider", e); |
|
923 |
} |
|
924 |
} |
|
925 |
|
|
926 |
public FeaturePagingHelper createFeaturePagingHelper( |
|
927 |
FeatureStore featureStore, int pageSize) throws BaseException { |
|
928 |
return new FeaturePagingHelperImpl(featureStore, pageSize); |
|
929 |
} |
|
930 |
|
|
931 |
public FeaturePagingHelper createFeaturePagingHelper( |
|
932 |
FeatureStore featureStore, FeatureQuery featureQuery, int pageSize) |
|
933 |
throws BaseException { |
|
934 |
return new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize); |
|
935 |
} |
|
936 |
|
|
937 |
public void setOpenErrorHandler(OpenErrorHandler handler) { |
|
938 |
openErrorHandler = handler; |
|
939 |
} |
|
940 |
|
|
941 |
public OpenErrorHandler getOpenErrorHandler() { |
|
942 |
return this.openErrorHandler; |
|
943 |
} |
|
944 |
|
|
945 |
public EditableFeatureType createFeatureType() { |
|
946 |
return new DefaultEditableFeatureType(); |
|
947 |
} |
|
948 |
|
|
949 |
public List getDataTypes() { |
|
950 |
if (dataTypes == null) { |
|
951 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
|
952 |
dataTypes = new ArrayList(); |
|
953 |
dataTypes.add(manager.get(DataTypes.STRING)); |
|
954 |
dataTypes.add(manager.get(DataTypes.BOOLEAN)); |
|
955 |
dataTypes.add(manager.get(DataTypes.INT)); |
|
956 |
dataTypes.add(manager.get(DataTypes.DOUBLE)); |
|
957 |
dataTypes.add(manager.get(DataTypes.DATE)); |
|
958 |
dataTypes.add(manager.get(DataTypes.GEOMETRY)); |
|
959 |
} |
|
960 |
return dataTypes; |
|
961 |
} |
|
962 |
|
|
963 |
public void registerFeatureAttributeGetter(String name, Class clazz) { |
|
964 |
if (name == null || clazz == null) { |
|
965 |
throw new IllegalArgumentException("Any parameters can be null"); |
|
966 |
} |
|
967 |
if(!(FeatureAttributeGetter.class.isAssignableFrom(clazz))) { |
|
968 |
throw new IllegalArgumentException( |
|
969 |
"Not supported implemtation: name=" + name |
|
970 |
+ " class=" + clazz.getName()); |
|
971 |
} |
|
972 |
} |
|
973 |
|
|
974 |
public FeatureAttributeGetter createFeatureAttributeGetter(String name) throws InitializeException { |
|
975 |
if (name == null) { |
|
976 |
throw new IllegalArgumentException("The parameter can not be null"); |
|
977 |
} |
|
978 |
|
|
979 |
try{ |
|
980 |
return (FeatureAttributeGetter) ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_FEATURE_ATTTRIBUTE_GETTER).create(name); |
|
981 |
} catch (InstantiationException e) { |
|
982 |
throw new InitializeException("FeatureAttributeGetter", e); |
|
983 |
} catch (IllegalAccessException e) { |
|
984 |
throw new InitializeException("FeatureAttributeGetter", e); |
|
985 |
} |
|
986 |
} |
|
987 |
|
|
988 |
public DataServerExplorerPool getDataServerExplorerPool() { |
|
989 |
if( this.dataServerExplorerPool==null ) { |
|
990 |
this.dataServerExplorerPool = new DefaultDataServerExplorerPool(); |
|
991 |
} |
|
992 |
return this.dataServerExplorerPool; |
|
993 |
} |
|
994 |
|
|
995 |
public void setDataServerExplorerPool(DataServerExplorerPool pool) { |
|
996 |
this.dataServerExplorerPool = pool; |
|
997 |
} |
|
998 |
|
|
999 |
private static final String DAL_OpenStore = "dal.openstore."; |
|
1000 |
|
|
1001 |
@Override |
|
1002 |
public DataStoreParameters createStoreParameters(DynStruct struct) throws InitializeException, ProviderNotRegisteredException { |
|
1003 |
if( !(struct instanceof DynStruct_v2 ) ) { |
|
1004 |
throw new IllegalArgumentException("A DynStruct_v2 is required."); |
|
1005 |
} |
|
1006 |
Tags tags = ((DynStruct_v2)struct).getTags(); |
|
1007 |
return this.createStoreParameters(tags); |
|
1008 |
} |
|
1009 |
|
|
1010 |
public DataStoreParameters createStoreParameters(Tags tags) throws InitializeException, ProviderNotRegisteredException { |
|
1011 |
String providerName = (String) tags.get(DAL_OpenStore+"provider"); |
|
1012 |
if( providerName == null ) { |
|
1013 |
throw new IllegalArgumentException("Tag DAL.OpenStore.provider is missing in struct."); |
|
1014 |
} |
|
1015 |
int prefixlen = DAL_OpenStore.length(); |
|
1016 |
DataStoreParameters parameters = this.createStoreParameters(providerName); |
|
1017 |
for( String key : tags ) { |
|
1018 |
if( key.startsWith(DAL_OpenStore) ) { |
|
1019 |
parameters.setDynValue(key.substring(prefixlen), tags.get(key)); |
|
1020 |
} |
|
1021 |
} |
|
1022 |
return parameters; |
|
1023 |
} |
|
1024 |
|
|
1025 |
@Override |
|
1026 |
public DataStore openStore(DynStruct struct) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
|
1027 |
DataStoreParameters paramters = this.createStoreParameters(struct); |
|
1028 |
DataStore store = this.openStore(paramters.getDataStoreName(), paramters); |
|
1029 |
return store; |
|
1030 |
} |
|
1031 |
|
|
1032 |
} |
|
1 |
package org.gvsig.fmap.dal.impl; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.net.URL; |
|
6 |
import java.net.URLClassLoader; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.List; |
|
10 |
import java.util.Map; |
|
11 |
import org.gvsig.fmap.dal.DataFactory; |
|
12 |
import org.gvsig.fmap.dal.DataManager; |
|
13 |
import static org.gvsig.fmap.dal.DataManager.READ_STORE_AUTHORIZATION; |
|
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 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
24 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
|
25 |
import org.gvsig.fmap.dal.Register; |
|
26 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
27 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
28 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
29 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
30 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
31 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
34 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
35 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
|
36 |
import org.gvsig.fmap.dal.feature.impl.FeatureStoreFactory; |
|
37 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
|
38 |
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl; |
|
39 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
|
40 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
|
41 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
|
42 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
|
43 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
|
44 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
|
45 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
|
46 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
47 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
|
48 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
49 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreParameters; |
|
50 |
import org.gvsig.fmap.dal.store.memory.MemoryStoreProvider; |
|
51 |
import org.gvsig.tools.ToolsLocator; |
|
52 |
import org.gvsig.tools.dataTypes.DataType; |
|
53 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
54 |
import org.gvsig.tools.dynobject.DynObject; |
|
55 |
import org.gvsig.tools.dynobject.DynStruct; |
|
56 |
import org.gvsig.tools.dynobject.DynStruct_v2; |
|
57 |
import org.gvsig.tools.dynobject.Tags; |
|
58 |
import org.gvsig.tools.evaluator.Evaluator; |
|
59 |
import org.gvsig.tools.exception.BaseException; |
|
60 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
|
61 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
|
62 |
import org.gvsig.tools.service.spi.Services; |
|
63 |
|
|
64 |
public class DefaultDataManager |
|
65 |
implements DataManager, DataManagerProviderServices, Services { |
|
66 |
|
|
67 |
private class Registers { |
|
68 |
|
|
69 |
private final Register store; |
|
70 |
private final Register storeProvider; |
|
71 |
private final Register serverExplorer; |
|
72 |
private final Register featureIndexProvider; |
|
73 |
|
|
74 |
public Registers() { |
|
75 |
this.store = new RegisterImpl( |
|
76 |
"Data.manager.stores.factory", |
|
77 |
"DAL store factories" |
|
78 |
); |
|
79 |
this.storeProvider = new RegisterImpl( |
|
80 |
"Data.manager.providers.factory", |
|
81 |
"DAL store provider factories" |
|
82 |
); |
|
83 |
this.serverExplorer = new RegisterImpl( |
|
84 |
"Data.manager.servereexplorer.factory", |
|
85 |
"DAL server explorer factories" |
|
86 |
); |
|
87 |
this.featureIndexProvider = new RegisterImpl( |
|
88 |
"Data.manager.feature.index.factory", |
|
89 |
"DAL feature index factories" |
|
90 |
); |
|
91 |
|
|
92 |
this.store.register(new FeatureStoreFactory()); |
|
93 |
} |
|
94 |
} |
|
95 |
private static final String TAG_DAL_OPENSTORE = "dal.openstore."; |
|
96 |
|
|
97 |
private final Registers registers; |
|
98 |
|
|
99 |
private final Map<Integer, String> defaultDataIndexProviders; |
|
100 |
|
|
101 |
private Class defaultEvaluatorClass = null; |
|
102 |
|
|
103 |
private OpenErrorHandler openErrorHandler = null; |
|
104 |
|
|
105 |
private DataServerExplorerPool dataServerExplorerPool = null; |
|
106 |
|
|
107 |
private List<DataType> dataTypes = null; |
|
108 |
|
|
109 |
private ClassLoader resourcesLoader = null; |
|
110 |
|
|
111 |
public DefaultDataManager() { |
|
112 |
this.registers = new Registers(); |
|
113 |
this.defaultDataIndexProviders = new HashMap<>(); |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public Register getStoreRegister() { |
|
118 |
return this.registers.store; |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public Register getStoreProviderRegister() { |
|
123 |
return this.registers.storeProvider; |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public Register getServerExplorerRegister() { |
|
128 |
return this.registers.serverExplorer; |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public Register getFeatureIndexRegister() { |
|
133 |
return this.registers.featureIndexProvider; |
|
134 |
} |
|
135 |
|
|
136 |
private String getStoreName(DataStoreParameters parameters) { |
|
137 |
for (DataFactory factory : this.getStoreRegister()) { |
|
138 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) factory; |
|
139 |
if (storeFactory.canUse(parameters)) { |
|
140 |
return storeFactory.getName(); |
|
141 |
} |
|
142 |
} |
|
143 |
return null; |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* @deprecated |
|
148 |
*/ |
|
149 |
@Override |
|
150 |
public void registerDefaultRasterStore(Class rasterStoreClass) { |
|
151 |
// Metodo usado por el raster nuevo para regstrar su factoria de store |
|
152 |
this.getStoreRegister().register(new RasterStoreFactory(rasterStoreClass)); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* @deprecated |
|
157 |
*/ |
|
158 |
@Override |
|
159 |
public void registerStoreFactory(String name, Class storeFactoryClass) { |
|
160 |
// Metodo usado por el raster viejo para registrar las factorias de sus stores |
|
161 |
this.getStoreRegister().register(new RasterStoreOldFactory(name, storeFactoryClass)); |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* @param name |
|
166 |
* @param storeProviderClass |
|
167 |
* @param parametersClass |
|
168 |
* @deprecated use registerStoreProviderFactory |
|
169 |
*/ |
|
170 |
@Override |
|
171 |
public void registerStoreProvider(String name, Class storeProviderClass, |
|
172 |
Class parametersClass) { |
|
173 |
if (name == null || storeProviderClass == null || parametersClass == null) { |
|
174 |
throw new IllegalArgumentException("Any parameters can be null"); |
|
175 |
} |
|
176 |
|
|
177 |
if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) { |
|
178 |
throw new IllegalArgumentException(parametersClass.getName() |
|
179 |
+ " must implement org.gvsig.fmap.dal.DataStoreParameters"); |
|
180 |
} |
|
181 |
|
|
182 |
if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) { |
|
183 |
// Envuelve al proveedor en una factoria por defecto. |
|
184 |
this.registerStoreProviderFactory(new DataStoreProviderToCoverageProviderFactoryWrapper( |
|
185 |
name, "", storeProviderClass, parametersClass)); |
|
186 |
return; |
|
187 |
} |
|
188 |
|
|
189 |
if (FeatureStoreProvider.class.isAssignableFrom(storeProviderClass)) { |
|
190 |
// Envuelve al proveedor en una factoria por defecto. |
|
191 |
this.registerStoreProviderFactory(new DataStoreProviderToFeatureStoreProviderFactoryWrapper( |
|
192 |
name, "", storeProviderClass, parametersClass)); |
|
193 |
return; |
|
194 |
} |
|
195 |
|
|
196 |
throw new IllegalArgumentException("Not supported implemtation: name=" |
|
197 |
+ name + " provider class=" + storeProviderClass.getName()); |
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public void registerExplorerProvider(String name, Class explorerClass, Class parametersClass) { |
|
203 |
if (name == null || explorerClass == null || parametersClass == null) { |
|
204 |
// FIXME Exception |
|
205 |
throw new IllegalArgumentException("Any parameters can be null"); |
|
206 |
} |
|
207 |
|
|
208 |
if (!DataServerExplorerParameters.class |
|
209 |
.isAssignableFrom(parametersClass)) { |
|
210 |
// FIXME Exception |
|
211 |
throw new IllegalArgumentException( |
|
212 |
parametersClass.getName() |
|
213 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorerParameters"); |
|
214 |
} |
|
215 |
|
|
216 |
if (!DataServerExplorer.class.isAssignableFrom(explorerClass)) { |
|
217 |
// FIXME Exception |
|
218 |
throw new IllegalArgumentException(explorerClass.getName() |
|
219 |
+ " must implement org.gvsig.fmap.dal.DataServerExplorer"); |
|
220 |
} |
|
221 |
|
|
222 |
// Envuelve al proveedor en una factoria por defecto. |
|
223 |
this.registerServerExplorerFactory( |
|
224 |
new DataServerExplorerToDataExplorerFactoryWrapper( |
|
225 |
name, "", explorerClass, parametersClass |
|
226 |
) |
|
227 |
); |
|
228 |
|
|
229 |
} |
|
230 |
|
|
231 |
@Override |
|
232 |
public void registerStoreFactory(DataStoreFactory_v2_4 factory) { |
|
233 |
this.getStoreRegister().register(factory); |
|
234 |
} |
|
235 |
|
|
236 |
@Override |
|
237 |
public void registerStoreProviderFactory(DataStoreProviderFactory factory) { |
|
238 |
this.getStoreProviderRegister().register(factory); |
|
239 |
} |
|
240 |
|
|
241 |
@Override |
|
242 |
public void registerServerExplorerFactory(DataServerExplorerFactory factory) { |
|
243 |
this.getServerExplorerRegister().register(factory); |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
247 |
public DataStoreParameters createStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
|
248 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName); |
|
249 |
return (DataStoreParameters) providerFactory.createParameters(); |
|
250 |
} |
|
251 |
|
|
252 |
@Override |
|
253 |
public NewDataStoreParameters createNewStoreParameters(String explorerName, String providerName) throws InitializeException, ProviderNotRegisteredException { |
|
254 |
try { |
|
255 |
DataServerExplorer explorer = this.openServerExplorer(explorerName, null); |
|
256 |
return explorer.getAddParameters(providerName); |
|
257 |
} catch (Exception ex) { |
|
258 |
throw new InitializeException(ex); |
|
259 |
} |
|
260 |
} |
|
261 |
|
|
262 |
@Override |
|
263 |
public DataServerExplorerParameters createServerExplorerParameters(String explorerName) throws InitializeException, ProviderNotRegisteredException { |
|
264 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName); |
|
265 |
DataServerExplorerParameters params = (DataServerExplorerParameters) explorerFactory.createParameters(); |
|
266 |
return params; |
|
267 |
} |
|
268 |
|
|
269 |
@Override |
|
270 |
public DataStoreParameters createMemoryStoreParameters(String autoOrderAttributeName) throws InitializeException { |
|
271 |
try { |
|
272 |
DataStoreParameters parameters = createStoreParameters(MemoryStoreProvider.NAME); |
|
273 |
if (autoOrderAttributeName != null) { |
|
274 |
parameters.setDynValue( |
|
275 |
MemoryStoreParameters.ORDER_PARAMETER_NAME, |
|
276 |
autoOrderAttributeName); |
|
277 |
} |
|
278 |
return parameters; |
|
279 |
} catch (Exception ex) { |
|
280 |
throw new InitializeException(ex); |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
|
285 |
public DataServerExplorer openServerExplorer(String explorerName, DataServerExplorerParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
|
286 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName); |
|
287 |
if (parameters == null) { |
|
288 |
parameters = (DataServerExplorerParameters) explorerFactory.createParameters(); |
|
289 |
} |
|
290 |
DataServerExplorer explorer = (DataServerExplorer) explorerFactory.create( |
|
291 |
parameters, |
|
292 |
new DefaultDataServerExplorerProviderServices() |
|
293 |
); |
|
294 |
return explorer; |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* @param parameters |
|
299 |
* @return |
|
300 |
* @throws org.gvsig.fmap.dal.exception.InitializeException |
|
301 |
* @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException |
|
302 |
* @throws org.gvsig.fmap.dal.exception.ValidateDataParametersException |
|
303 |
* @deprecated see openServerExplorer |
|
304 |
*/ |
|
305 |
@Override |
|
306 |
public DataServerExplorer createServerExplorer( |
|
307 |
DataServerExplorerParameters parameters) throws InitializeException, |
|
308 |
ProviderNotRegisteredException, ValidateDataParametersException { |
|
309 |
return openServerExplorer(parameters.getExplorerName(), parameters); |
|
310 |
} |
|
311 |
|
|
312 |
@Override |
|
313 |
public DataStore openStore(String providerName, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
|
314 |
|
|
315 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
|
316 |
if (!identityManager.getCurrentIdentity().isAuthorized(READ_STORE_AUTHORIZATION, parameters, providerName)) { |
|
317 |
throw new UnauthorizedException(READ_STORE_AUTHORIZATION, parameters, providerName); |
|
318 |
} |
|
319 |
|
|
320 |
String storeName = this.getStoreName(parameters); |
|
321 |
|
|
322 |
DataStoreFactory_v2_4 storeFactory = (DataStoreFactory_v2_4) this.getStoreRegister().getFactory(storeName); |
|
323 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName); |
|
324 |
|
|
325 |
DataStore store = (DataStore) storeFactory.create(parameters, this); |
|
326 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create(parameters, store); |
|
327 |
|
|
328 |
storeFactory.setProvider(store, provider); |
|
329 |
return store; |
|
330 |
} |
|
331 |
|
|
332 |
@Override |
|
333 |
public DataStore openStore(String provider, DynObject parameters) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException { |
|
334 |
DataStoreParameters params = toDataStoreParameters(provider, parameters); |
|
335 |
DataStore store = openStore(params.getDataStoreName(), params); |
|
336 |
return store; |
|
337 |
} |
|
338 |
|
|
339 |
@Override |
|
340 |
public FeatureStore createMemoryStore(String autoOrderAttributeName) throws InitializeException { |
|
341 |
try { |
|
342 |
DataStoreParameters parameters = createMemoryStoreParameters(autoOrderAttributeName); |
|
343 |
DataStore store = openStore(MemoryStoreProvider.NAME, parameters); |
|
344 |
return (FeatureStore) store; |
|
345 |
} catch (Exception ex) { |
|
346 |
throw new InitializeException(ex); |
|
347 |
} |
|
348 |
} |
|
349 |
|
|
350 |
@Override |
|
351 |
public DataStoreProviderFactory getStoreProviderFactory(String providerName) { |
|
352 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName); |
|
353 |
return (DataStoreProviderFactory) providerFactory; |
|
354 |
} |
|
355 |
|
|
356 |
@Override |
|
357 |
public List<String> getStoreProviders() { |
|
358 |
return this.getStoreProviderRegister().getFactoryNames(); |
|
359 |
} |
|
360 |
|
|
361 |
@Override |
|
362 |
public List<String> getStoreProviders(String explorerName) { |
|
363 |
try { |
|
364 |
DataServerExplorer explorer = openServerExplorer(explorerName, null); |
|
365 |
List names = explorer.getDataStoreProviderNames(); |
|
366 |
return names; |
|
367 |
} catch (Exception ex) { |
|
368 |
throw new RuntimeException("Can't get stores availables for explorer '" + explorerName + "'.", ex); |
|
369 |
} |
|
370 |
} |
|
371 |
|
|
372 |
@Override |
|
373 |
public List<String> getExplorerProviders() { |
|
374 |
List<String> names = this.getServerExplorerRegister().getFactoryNames(); |
|
375 |
return names; |
|
376 |
} |
|
377 |
|
|
378 |
@Override |
|
379 |
public DataStoreProvider createProvider(DataStoreProviderServices providerServices, DataStoreParameters parameters) throws InitializeException, ProviderNotRegisteredException { |
|
380 |
|
|
381 |
String providerName = parameters.getDataStoreName(); |
|
382 |
DataFactory providerFactory = this.getStoreProviderRegister().getFactory(providerName); |
|
383 |
if (providerFactory == null) { |
|
384 |
throw new ProviderNotRegisteredException(providerName); |
|
385 |
} |
|
386 |
while (true) { |
|
387 |
try { |
|
388 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create( |
|
389 |
parameters, providerServices |
|
390 |
); |
|
391 |
return provider; |
|
392 |
} catch (Exception e) { |
|
393 |
if (openErrorHandler == null) { |
|
394 |
throw new InitializeException(providerName, e); |
|
395 |
} |
|
396 |
boolean retry = openErrorHandler.canRetryOpen(e, parameters); |
|
397 |
if (!retry) { |
|
398 |
throw new InitializeException(providerName, e); |
|
399 |
} |
|
400 |
} |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
@Override |
|
405 |
public List<String> getFeatureIndexProviders() { |
|
406 |
List<String> names = this.getFeatureIndexRegister().getFactoryNames(); |
|
407 |
return names; |
|
408 |
} |
|
409 |
|
|
410 |
@Override |
|
411 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
|
412 |
this.defaultDataIndexProviders.put(dataType, name); |
|
413 |
} |
|
414 |
|
|
415 |
@Override |
|
416 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
|
417 |
return this.defaultDataIndexProviders.get(dataType); |
|
418 |
} |
|
419 |
|
|
420 |
@Override |
|
421 |
public FeatureIndexProviderServices createFeatureIndexProvider( |
|
422 |
String name, |
|
423 |
FeatureStore store, |
|
424 |
FeatureType type, |
|
425 |
String indexName, |
|
426 |
FeatureAttributeDescriptor attr |
|
427 |
) throws InitializeException, ProviderNotRegisteredException { |
|
428 |
|
|
429 |
if (name == null) { |
|
430 |
name = getDefaultFeatureIndexProviderName(attr.getType()); |
|
431 |
} |
|
432 |
|
|
433 |
if (name == null) { |
|
434 |
throw new InitializeException( |
|
435 |
"There not any index provider registered.", null); |
|
436 |
} |
|
437 |
DataFactory indexfactory = this.getFeatureIndexRegister().getFactory(name); |
|
438 |
if (indexfactory == null) { |
|
439 |
throw new InitializeException( |
|
440 |
"There not any index provider registered with name '" + name + "'.", null); |
|
441 |
|
|
442 |
} |
|
443 |
FeatureIndexProvider provider = (FeatureIndexProvider) indexfactory.create(null, null); |
|
444 |
|
|
445 |
FeatureIndexProviderServices services = new DefaultFeatureIndex( |
|
446 |
(FeatureStoreProviderServices) store, |
|
447 |
type, |
|
448 |
provider, |
|
449 |
attr.getName(), |
|
450 |
indexName |
|
451 |
); |
|
452 |
services.initialize(); |
|
453 |
return services; |
|
454 |
|
|
455 |
} |
|
456 |
|
|
457 |
@Override |
|
458 |
public String getTemporaryDirectory() { |
|
459 |
// FIXME Define a better tempdir solution |
|
460 |
String tmp = System.getProperty("TMP"); |
|
461 |
if (tmp == null) { |
|
462 |
tmp = System.getProperty("TEMP"); |
|
463 |
} |
|
464 |
if (tmp == null) { |
Also available in: Unified diff