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