root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / impl / DefaultDataManager.java @ 27723
History | View | Annotate | Download (14 KB)
1 |
package org.gvsig.fmap.dal.impl; |
---|---|
2 |
|
3 |
import java.lang.reflect.InvocationTargetException; |
4 |
import java.util.HashMap; |
5 |
import java.util.List; |
6 |
import java.util.Map; |
7 |
|
8 |
import org.gvsig.fmap.dal.DALLocator; |
9 |
import org.gvsig.fmap.dal.DataManager; |
10 |
import org.gvsig.fmap.dal.DataServerExplorer; |
11 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
12 |
import org.gvsig.fmap.dal.DataStore; |
13 |
import org.gvsig.fmap.dal.DataStoreParameters; |
14 |
import org.gvsig.fmap.dal.exception.InitializeException; |
15 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
16 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
18 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
19 |
import org.gvsig.fmap.dal.feature.FeatureType; |
20 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
21 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
22 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
23 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
24 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
25 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
26 |
import org.gvsig.fmap.dal.raster.imp.DefaultCoverageStore; |
27 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
28 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
29 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
30 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
31 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.evaluator.Evaluator; |
34 |
import org.gvsig.tools.operations.OperationManager; |
35 |
|
36 |
public class DefaultDataManager implements DataManager, DataManagerProviderServices { |
37 |
|
38 |
final static private String DATA_MANAGER_STORE = "Data.manager.stores"; |
39 |
final static private String DATA_MANAGER_STORE_DESCRIPTION = "DAL stores providers"; |
40 |
|
41 |
final static private String DATA_MANAGER_STORE_PARAMS = "Data.manager.stores.params"; |
42 |
final static private String DATA_MANAGER_STORE_PARAMS_DESCRIPTION = "DAL stores providers parameters"; |
43 |
|
44 |
final static private String DATA_MANAGER_EXPLORER = "Data.manager.explorers"; |
45 |
final static private String DATA_MANAGER_EXPLORER_DESCRIPTION = "DAL explorers providers"; |
46 |
|
47 |
final static private String DATA_MANAGER_EXPLORER_PARAMS = "Data.manager.explorers.params"; |
48 |
final static private String DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION = "DAL explorer providers parameters"; |
49 |
|
50 |
final static private String DATA_MANAGER_INDEX = "Data.manager.indexes"; |
51 |
final static private String DATA_MANAGER_INDEX_DESCRIPTION = "DAL index providers"; |
52 |
|
53 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR = "Data.manager.expresion.evaluator"; |
54 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT = "default"; |
55 |
final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION = "DAL expresion evaluators."; |
56 |
|
57 |
/** This map contains the name of the default provider for each data type */
|
58 |
private Map defaultDataIndexProviders; |
59 |
|
60 |
|
61 |
public DefaultDataManager() {
|
62 |
/*
|
63 |
* Create te extensions point in te registry.
|
64 |
*/
|
65 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE, |
66 |
DATA_MANAGER_STORE_DESCRIPTION); |
67 |
|
68 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS, |
69 |
DATA_MANAGER_STORE_PARAMS_DESCRIPTION); |
70 |
|
71 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER, |
72 |
DATA_MANAGER_EXPLORER_DESCRIPTION); |
73 |
|
74 |
ToolsLocator.getExtensionPointManager().add( |
75 |
DATA_MANAGER_EXPLORER_PARAMS, |
76 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION); |
77 |
|
78 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX, |
79 |
DATA_MANAGER_INDEX_DESCRIPTION); |
80 |
|
81 |
ToolsLocator.getExtensionPointManager().add( |
82 |
DATA_MANAGER_EXPRESION_EVALUATOR, |
83 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION); |
84 |
|
85 |
initializeIndexes(); |
86 |
} |
87 |
|
88 |
/**
|
89 |
*
|
90 |
* @return ResourceManager
|
91 |
*/
|
92 |
|
93 |
public ResourceManager getResourceManager() {
|
94 |
return DALLocator.getResourceManager();
|
95 |
} |
96 |
|
97 |
public OperationManager getOperationManager() {
|
98 |
return ToolsLocator.getOperationManager();
|
99 |
} |
100 |
|
101 |
public String getTemporaryDirectory() { |
102 |
// FIXME Define a better tempdir solution
|
103 |
String tmp = System.getenv("TMP"); |
104 |
if (tmp == null) { |
105 |
tmp = System.getenv("TEMP"); |
106 |
} |
107 |
if (tmp == null) { |
108 |
tmp = System.getenv("HOME"); |
109 |
} |
110 |
return tmp;
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* ====================================================================
|
115 |
*
|
116 |
* Store related services
|
117 |
*/
|
118 |
public void registerStoreProvider(String name, |
119 |
Class storeProviderClass,
|
120 |
Class parametersClass) {
|
121 |
|
122 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE, |
123 |
DATA_MANAGER_STORE_DESCRIPTION).append(name, null,
|
124 |
storeProviderClass); |
125 |
|
126 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS, |
127 |
DATA_MANAGER_STORE_PARAMS_DESCRIPTION).append(name, null,
|
128 |
parametersClass); |
129 |
} |
130 |
|
131 |
public DataStoreParameters createStoreParameters(String name) |
132 |
throws InitializeException, ProviderNotRegisteredException {
|
133 |
try {
|
134 |
DataStoreParameters params = (DataStoreParameters) ToolsLocator |
135 |
.getExtensionPointManager().get(DATA_MANAGER_STORE_PARAMS) |
136 |
.create(name); |
137 |
if (params == null) { |
138 |
throw new ProviderNotRegisteredException(name); |
139 |
} |
140 |
return params;
|
141 |
} catch (InstantiationException e) { |
142 |
throw new InitializeException(e); |
143 |
} catch (IllegalAccessException e) { |
144 |
throw new InitializeException(e); |
145 |
} catch (SecurityException e) { |
146 |
throw new InitializeException(e); |
147 |
} catch (IllegalArgumentException e) { |
148 |
throw new InitializeException(e); |
149 |
} |
150 |
} |
151 |
|
152 |
public DataStore createStore(DataStoreParameters parameters)
|
153 |
throws InitializeException, ProviderNotRegisteredException,
|
154 |
ValidateDataParametersException { |
155 |
String name = parameters.getDataStoreName();
|
156 |
|
157 |
parameters.validate(); |
158 |
|
159 |
try {
|
160 |
DataStoreProvider storeProvider = (DataStoreProvider) ToolsLocator |
161 |
.getExtensionPointManager().get(DATA_MANAGER_STORE).create( |
162 |
name, new Object[] { parameters }); |
163 |
if (storeProvider == null) { |
164 |
throw new ProviderNotRegisteredException(name); |
165 |
} |
166 |
|
167 |
if (storeProvider instanceof CoverageStoreProvider){ |
168 |
return new DefaultCoverageStore(this, parameters, |
169 |
(CoverageStoreProvider) storeProvider); |
170 |
|
171 |
} else if (storeProvider instanceof FeatureStoreProvider){ |
172 |
|
173 |
return new DefaultFeatureStore(this, parameters, |
174 |
(FeatureStoreProvider) storeProvider); |
175 |
} else{
|
176 |
// FIXME Exception
|
177 |
throw new InitializeException(new RuntimeException( |
178 |
"Not supported implemtation: name=" + name
|
179 |
+ " provider class="
|
180 |
+ storeProvider.getClass().getName())); |
181 |
} |
182 |
|
183 |
|
184 |
} catch (InstantiationException e) { |
185 |
throw new InitializeException(e); |
186 |
} catch (IllegalAccessException e) { |
187 |
throw new InitializeException(e); |
188 |
} catch (SecurityException e) { |
189 |
throw new InitializeException(e); |
190 |
} catch (IllegalArgumentException e) { |
191 |
throw new InitializeException(e); |
192 |
} catch (NoSuchMethodException e) { |
193 |
throw new InitializeException(e); |
194 |
} catch (InvocationTargetException e) { |
195 |
throw new InitializeException(e); |
196 |
} |
197 |
} |
198 |
|
199 |
public List getStoreProviders() { |
200 |
return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_STORE)
|
201 |
.getNames(); |
202 |
} |
203 |
|
204 |
/*
|
205 |
* ====================================================================
|
206 |
*
|
207 |
* Explorer related services
|
208 |
*/
|
209 |
public void registerExplorerProvider(String name, Class explorerClass, |
210 |
Class parametersClass) {
|
211 |
|
212 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER, |
213 |
DATA_MANAGER_EXPLORER_DESCRIPTION).append(name, null,
|
214 |
explorerClass); |
215 |
|
216 |
ToolsLocator.getExtensionPointManager().add( |
217 |
DATA_MANAGER_EXPLORER_PARAMS, |
218 |
DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION).append(name, null,
|
219 |
parametersClass); |
220 |
} |
221 |
|
222 |
public DataServerExplorerParameters createServerExplorerParameters(String name) |
223 |
throws InitializeException, ProviderNotRegisteredException {
|
224 |
try {
|
225 |
DataServerExplorerParameters params = (DataServerExplorerParameters) ToolsLocator |
226 |
.getExtensionPointManager() |
227 |
.get( |
228 |
DATA_MANAGER_EXPLORER_PARAMS) |
229 |
.create(name); |
230 |
if (params == null) { |
231 |
throw new ProviderNotRegisteredException(name); |
232 |
} |
233 |
return params;
|
234 |
} catch (InstantiationException e) { |
235 |
throw new InitializeException(e); |
236 |
} catch (IllegalAccessException e) { |
237 |
throw new InitializeException(e); |
238 |
} catch (SecurityException e) { |
239 |
throw new InitializeException(e); |
240 |
} catch (IllegalArgumentException e) { |
241 |
throw new InitializeException(e); |
242 |
} |
243 |
} |
244 |
|
245 |
public DataServerExplorer createServerExplorer(DataServerExplorerParameters parameters)
|
246 |
throws InitializeException, ProviderNotRegisteredException,
|
247 |
ValidateDataParametersException { |
248 |
|
249 |
parameters.validate(); |
250 |
|
251 |
String name = parameters.getExplorerName();
|
252 |
|
253 |
try {
|
254 |
DataServerExplorerProvider server = (DataServerExplorerProvider) ToolsLocator |
255 |
.getExtensionPointManager().get(DATA_MANAGER_EXPLORER) |
256 |
.create( |
257 |
name, new Object[] { parameters }); |
258 |
if (server == null) { |
259 |
throw new ProviderNotRegisteredException(name); |
260 |
} |
261 |
server.initialize(new DefaultDataServerExplorerProviderServices());
|
262 |
return server;
|
263 |
} catch (InstantiationException e) { |
264 |
throw new InitializeException(e); |
265 |
} catch (IllegalAccessException e) { |
266 |
throw new InitializeException(e); |
267 |
} catch (SecurityException e) { |
268 |
throw new InitializeException(e); |
269 |
} catch (IllegalArgumentException e) { |
270 |
throw new InitializeException(e); |
271 |
} catch (NoSuchMethodException e) { |
272 |
throw new InitializeException(e); |
273 |
} catch (InvocationTargetException e) { |
274 |
throw new InitializeException(e); |
275 |
} |
276 |
} |
277 |
|
278 |
public List getExplorerProviders() { |
279 |
return ToolsLocator.getExtensionPointManager().get(
|
280 |
DATA_MANAGER_EXPLORER).getNames(); |
281 |
} |
282 |
|
283 |
|
284 |
/*
|
285 |
* ====================================================================
|
286 |
*
|
287 |
* Expresion evaluation related services
|
288 |
*/
|
289 |
public Evaluator createExpresion(String expresion) |
290 |
throws InitializeException {
|
291 |
try {
|
292 |
return (Evaluator) ToolsLocator.getExtensionPointManager().get(
|
293 |
DATA_MANAGER_EXPRESION_EVALUATOR).create( |
294 |
DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
295 |
new Object[] { expresion }); |
296 |
} catch (SecurityException e) { |
297 |
throw new InitializeException(e); |
298 |
} catch (IllegalArgumentException e) { |
299 |
throw new InitializeException(e); |
300 |
} catch (NoSuchMethodException e) { |
301 |
throw new InitializeException(e); |
302 |
} catch (InstantiationException e) { |
303 |
throw new InitializeException(e); |
304 |
} catch (IllegalAccessException e) { |
305 |
throw new InitializeException(e); |
306 |
} catch (InvocationTargetException e) { |
307 |
throw new InitializeException(e); |
308 |
} |
309 |
} |
310 |
|
311 |
public void registerDefaultEvaluator(Class evaluatorClass) { |
312 |
if (!Evaluator.class.isAssignableFrom(evaluatorClass)) {
|
313 |
throw new ClassCastException(); |
314 |
} |
315 |
ToolsLocator.getExtensionPointManager().add( |
316 |
DATA_MANAGER_EXPRESION_EVALUATOR, |
317 |
DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION).append( |
318 |
DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT, |
319 |
"Default expresion evaluator for use in DAL", evaluatorClass);
|
320 |
} |
321 |
|
322 |
/*
|
323 |
* ====================================================================
|
324 |
*
|
325 |
* Index related services
|
326 |
*/
|
327 |
|
328 |
|
329 |
public List getFeatureIndexProviders() { |
330 |
return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_INDEX)
|
331 |
.getNames(); |
332 |
} |
333 |
|
334 |
public void setDefaultFeatureIndexProviderName(int dataType, String name) { |
335 |
defaultDataIndexProviders.put(new Integer(dataType), name); |
336 |
} |
337 |
|
338 |
public String getDefaultFeatureIndexProviderName(int dataType) { |
339 |
return (String) defaultDataIndexProviders.get(new Integer(dataType)); |
340 |
} |
341 |
|
342 |
public FeatureIndexProviderServices createFeatureIndexProvider(
|
343 |
String name, FeatureStore store, FeatureType type, String indexName, |
344 |
FeatureAttributeDescriptor attr) |
345 |
throws InitializeException, ProviderNotRegisteredException {
|
346 |
|
347 |
if (name == null) { |
348 |
name = getDefaultFeatureIndexProviderName(attr.getDataType()); |
349 |
} |
350 |
|
351 |
if (name == null) { |
352 |
throw new InitializeException("There not any index provider registered.", null); |
353 |
} |
354 |
|
355 |
try {
|
356 |
FeatureIndexProvider provider = (FeatureIndexProvider) ToolsLocator |
357 |
.getExtensionPointManager() |
358 |
.get( |
359 |
DATA_MANAGER_INDEX) |
360 |
.create(name); |
361 |
if (provider == null) { |
362 |
throw new ProviderNotRegisteredException(name); |
363 |
} |
364 |
FeatureIndexProviderServices services = new DefaultFeatureIndex((FeatureStoreProviderServices) store, type, provider, attr.getName(), indexName);
|
365 |
services.initialize(); |
366 |
return services;
|
367 |
} catch (InstantiationException e) { |
368 |
throw new InitializeException(e); |
369 |
} catch (IllegalAccessException e) { |
370 |
throw new InitializeException(e); |
371 |
} catch (SecurityException e) { |
372 |
throw new InitializeException(e); |
373 |
} catch (IllegalArgumentException e) { |
374 |
throw new InitializeException(e); |
375 |
} |
376 |
} |
377 |
|
378 |
public void registerFeatureIndexProvider(String name, String description, |
379 |
Class clazz, int dataType) { |
380 |
ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX, |
381 |
DATA_MANAGER_INDEX_DESCRIPTION).append(name, null,
|
382 |
clazz); |
383 |
|
384 |
if (getDefaultFeatureIndexProviderName(dataType) == null) { |
385 |
setDefaultFeatureIndexProviderName(dataType, name); |
386 |
} |
387 |
} |
388 |
|
389 |
private void initializeIndexes() { |
390 |
this.defaultDataIndexProviders = new HashMap(); |
391 |
} |
392 |
|
393 |
public DataStoreProvider createStoreProvider(String name) |
394 |
throws InitializeException, ProviderNotRegisteredException {
|
395 |
|
396 |
try {
|
397 |
DataStoreProvider storeProvider = (DataStoreProvider) ToolsLocator |
398 |
.getExtensionPointManager().get(DATA_MANAGER_STORE).create( |
399 |
name); |
400 |
if (storeProvider == null) { |
401 |
throw new ProviderNotRegisteredException(name); |
402 |
} |
403 |
|
404 |
return storeProvider;
|
405 |
} catch (InstantiationException e) { |
406 |
throw new InitializeException(e); |
407 |
} catch (IllegalAccessException e) { |
408 |
throw new InitializeException(e); |
409 |
} catch (SecurityException e) { |
410 |
throw new InitializeException(e); |
411 |
} catch (IllegalArgumentException e) { |
412 |
throw new InitializeException(e); |
413 |
} |
414 |
} |
415 |
|
416 |
} |