svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / impl / DefaultDataManager.java @ 24017
History | View | Annotate | Download (21.8 KB)
1 |
package org.gvsig.fmap.data.impl; |
---|---|
2 |
|
3 |
import java.lang.reflect.Constructor; |
4 |
import java.lang.reflect.InvocationTargetException; |
5 |
import java.util.ArrayList; |
6 |
import java.util.HashMap; |
7 |
import java.util.Iterator; |
8 |
import java.util.List; |
9 |
import java.util.Map; |
10 |
import java.util.Set; |
11 |
|
12 |
import org.gvsig.fmap.data.DALLocator; |
13 |
import org.gvsig.fmap.data.DataExplorer; |
14 |
import org.gvsig.fmap.data.DataExplorerParameters; |
15 |
import org.gvsig.fmap.data.DataManager; |
16 |
import org.gvsig.fmap.data.DataStore; |
17 |
import org.gvsig.fmap.data.DataStoreParameters; |
18 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
19 |
import org.gvsig.fmap.data.exceptions.ProviderNotRegisteredException; |
20 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
21 |
import org.gvsig.fmap.data.feature.FeatureStore; |
22 |
import org.gvsig.fmap.data.feature.FeatureType; |
23 |
import org.gvsig.fmap.data.feature.impl.DefaultFeatureStore; |
24 |
import org.gvsig.fmap.data.feature.spi.FeatureStoreProvider; |
25 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProviderServices; |
26 |
import org.gvsig.fmap.data.resource.ResourceManager; |
27 |
import org.gvsig.fmap.data.spi.DataExplorerProvider; |
28 |
import org.gvsig.fmap.data.spi.DataManagerProvider; |
29 |
import org.gvsig.tools.evaluator.Evaluator; |
30 |
import org.gvsig.tools.extensionPoint.ExtensionPoint; |
31 |
import org.gvsig.tools.extensionPoint.ExtensionPointsSingleton; |
32 |
import org.gvsig.tools.operations.Operation; |
33 |
import org.gvsig.tools.operations.OperationContext; |
34 |
import org.gvsig.tools.operations.OperationException; |
35 |
import org.gvsig.tools.operations.OperationNotSupportedException; |
36 |
|
37 |
import com.iver.utiles.NotExistInXMLEntity; |
38 |
import com.iver.utiles.XMLEntity; |
39 |
|
40 |
public class DefaultDataManager implements DataManager, DataManagerProvider { |
41 |
private static ArrayList registers = new ArrayList(); |
42 |
|
43 |
private Class evaluatorClass = null; |
44 |
private Constructor evaluatorConstructor = null; |
45 |
|
46 |
/** This map contains the name of the default provider for each data type */
|
47 |
private Map defaultDataIndexProviders = new HashMap(); |
48 |
|
49 |
/**
|
50 |
* Define extension point names
|
51 |
*/
|
52 |
public interface ExtensionPointNames { |
53 |
public static final String DATAINDEX_PROVIDER = "DataIndexProvider"; |
54 |
public static final String DATASTORE_PROVIDER = "DataStoreProvider"; |
55 |
public static final String DATAEXPLORER_PROVIDER = "DataExplorerProvider"; |
56 |
} |
57 |
|
58 |
/*
|
59 |
* Create extension points
|
60 |
*/
|
61 |
private static ExtensionPoint dataExplorerProviderEP = new ExtensionPoint( |
62 |
ExtensionPointNames.DATAEXPLORER_PROVIDER, "Data Explorer Provider");
|
63 |
private static ExtensionPoint dataStoreProviderEP = new ExtensionPoint( |
64 |
ExtensionPointNames.DATASTORE_PROVIDER, "Data Store Provider");
|
65 |
private static ExtensionPoint dataIndexProviderEP = new ExtensionPoint( |
66 |
ExtensionPointNames.DATAINDEX_PROVIDER, "Data Index Provider");
|
67 |
|
68 |
/*
|
69 |
* Register extension points
|
70 |
*/
|
71 |
static {
|
72 |
ExtensionPointsSingleton.getInstance().put(dataExplorerProviderEP); |
73 |
ExtensionPointsSingleton.getInstance().put(dataStoreProviderEP); |
74 |
ExtensionPointsSingleton.getInstance().put(dataIndexProviderEP); |
75 |
} |
76 |
|
77 |
/**
|
78 |
*
|
79 |
* @return ResourceManager
|
80 |
*/
|
81 |
|
82 |
public ResourceManager getResourceManager() {
|
83 |
return DALLocator.getResourceManager();
|
84 |
} |
85 |
|
86 |
private List dataStoreOperations = new ArrayList(); |
87 |
|
88 |
public DefaultDataManager() {
|
89 |
// org.gvsig.fmap.data.feature.driver.shp.Register.selfRegister();
|
90 |
// org.gvsig.fmap.data.feature.driver.Register.selfRegister();
|
91 |
|
92 |
// org.gvsig.fmap.data.gml.Register.selfRegister();
|
93 |
} |
94 |
|
95 |
/* (non-Javadoc)
|
96 |
* @see org.gvsig.fmap.data.DataManager#registerDataStore(java.lang.String, java.lang.Class, java.lang.Class)
|
97 |
*/
|
98 |
|
99 |
public void registerDataStoreProvider(String name, Class dataStoreProviderClass, Class parametersClass) { |
100 |
RegisterInfo register = new RegisterInfo(RegisterInfo.TYPE_STORE, name,
|
101 |
dataStoreProviderClass, parametersClass); |
102 |
if (registers.contains(register)){
|
103 |
return;
|
104 |
} |
105 |
registers.add(register); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Levanta una instancia de los parametros solicitados inicializa el nombre
|
110 |
* en la instancia y la devuelve.
|
111 |
*
|
112 |
* @throws InitializeException
|
113 |
* @throws ProviderNotRegisteredException
|
114 |
**/
|
115 |
public DataStoreParameters createDataStoreParameters(String name) |
116 |
throws InitializeException, ProviderNotRegisteredException {
|
117 |
|
118 |
RegisterInfo registerInfo = this.getRegisterByName(name);
|
119 |
if (registerInfo == null){ |
120 |
throw new ProviderNotRegisteredException(name); |
121 |
} else if (registerInfo.type != RegisterInfo.TYPE_STORE) { |
122 |
throw new ProviderNotRegisteredException(name); |
123 |
} |
124 |
|
125 |
try {
|
126 |
return (DataStoreParameters)registerInfo.parametersClazz.newInstance();
|
127 |
} catch (InstantiationException e) { |
128 |
throw new InitializeException(name,e); |
129 |
} catch (IllegalAccessException e) { |
130 |
throw new InitializeException(name,e); |
131 |
} |
132 |
} |
133 |
|
134 |
|
135 |
|
136 |
/* (non-Javadoc)
|
137 |
* @see org.gvsig.fmap.data.DataManager#createDataStoreParameters(com.iver.utiles.XMLEntity)
|
138 |
*/
|
139 |
public DataStoreParameters createDataStoreParameters(XMLEntity xmlEntity)
|
140 |
throws InitializeException, ProviderNotRegisteredException {
|
141 |
String name;
|
142 |
try {
|
143 |
name = xmlEntity.getStringProperty("dataStoreName");
|
144 |
} catch (NotExistInXMLEntity e) {
|
145 |
throw new InitializeException(e); |
146 |
} |
147 |
|
148 |
DataStoreParameters params = this.createDataStoreParameters(name);
|
149 |
|
150 |
params.loadFromXMLEntity(xmlEntity); |
151 |
return params;
|
152 |
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* Levanta la instancia del datasource, levanta una instancia del driver que
|
157 |
* precisa el datasource y por ultimo invoca al metodo init del datasource.
|
158 |
*
|
159 |
* @throws InitializeException
|
160 |
* @throws ProviderNotRegisteredException
|
161 |
**/
|
162 |
/* (non-Javadoc)
|
163 |
* @see org.gvsig.fmap.data.DataManager#createDataStore(org.gvsig.fmap.data.impl.DataStoreParameters)
|
164 |
*/
|
165 |
public DataStore createDataStore(DataStoreParameters parameters)
|
166 |
throws InitializeException, ProviderNotRegisteredException {
|
167 |
String name = parameters.getDataStoreName();
|
168 |
|
169 |
RegisterInfo registerInfo = this.getRegisterByName(name);
|
170 |
if (registerInfo == null){ |
171 |
throw new ProviderNotRegisteredException(name); |
172 |
} |
173 |
|
174 |
if (FeatureStoreProvider.class.isAssignableFrom(registerInfo.clazz)) {
|
175 |
try {
|
176 |
FeatureStoreProvider provider = (FeatureStoreProvider) registerInfo.clazz |
177 |
.newInstance(); |
178 |
|
179 |
return new DefaultFeatureStore(this, parameters, provider); |
180 |
} catch (InstantiationException e) { |
181 |
throw new InitializeException(name, e); |
182 |
} catch (IllegalAccessException e) { |
183 |
throw new InitializeException(name, e); |
184 |
} |
185 |
|
186 |
} |
187 |
// FIXME
|
188 |
throw new UnsupportedOperationException(); |
189 |
|
190 |
} |
191 |
|
192 |
/* (non-Javadoc)
|
193 |
* @see org.gvsig.fmap.data.DataManager#createDataStore(com.iver.utiles.XMLEntity)
|
194 |
*/
|
195 |
public DataStore createDataStore(XMLEntity xmlEntity)
|
196 |
throws InitializeException, ProviderNotRegisteredException {
|
197 |
try {
|
198 |
Class storeClass = Class.forName(xmlEntity |
199 |
.getStringProperty("className"));
|
200 |
Constructor constructor = storeClass.getConstructor(new Class[] {DataManager.class,XMLEntity.class}); |
201 |
return (DataStore) constructor.newInstance(new Object[]{this,xmlEntity}); |
202 |
} catch (Exception e) { |
203 |
throw new InitializeException(e); |
204 |
} |
205 |
|
206 |
} |
207 |
|
208 |
|
209 |
/** Como conjunto de propiedades genericas a un tipo de DataStore
|
210 |
* a las que se puede acceder sin tener que crear un DataStore/Driver.
|
211 |
*
|
212 |
* Por ejemplo para "DriverDataSource.shp" podria tener el
|
213 |
* tamaƱo de identificador de campo.
|
214 |
*
|
215 |
* En "DriverDataSource.postgres" podria aportar informacion sobre
|
216 |
* las tablas disponibles o cosas asi. Hay que ver que precisa
|
217 |
* GeoDB y de donde lo puede obtener.
|
218 |
*
|
219 |
* Hay que pensarlo bien.
|
220 |
*
|
221 |
*/
|
222 |
|
223 |
/**
|
224 |
* Collection of generic properties of a DataStore type which can access
|
225 |
* without create a DataStore/Driver.
|
226 |
*
|
227 |
* For example for "DriverDataSource.shp" could have the size of the data
|
228 |
* identification.
|
229 |
*
|
230 |
* In "DriverDataSource.postgres" could add information about availables
|
231 |
* tables or things like that. We`ll have to see what GeoDB needs and where
|
232 |
* it can get.
|
233 |
*
|
234 |
* We have to think it good.
|
235 |
*/
|
236 |
/* (non-Javadoc)
|
237 |
* @see org.gvsig.fmap.data.DataManager#registerDataExplorer(java.lang.String, java.lang.Class, java.lang.Class)
|
238 |
*/
|
239 |
|
240 |
|
241 |
public void registerDataExplorer(String name, Class dataSourceClass, Class parametersClass) { |
242 |
RegisterInfo register = new RegisterInfo(RegisterInfo.TYPE_EXPLORER,
|
243 |
name, dataSourceClass, parametersClass); |
244 |
if (registers.contains(register)){
|
245 |
return;
|
246 |
} |
247 |
registers.add(register); |
248 |
} |
249 |
|
250 |
/**
|
251 |
* Levanta una instancia de los parametros solicitados inicializa el nombre
|
252 |
* en la instancia y la devuelve.
|
253 |
*
|
254 |
* @throws InitializeException
|
255 |
* TODO
|
256 |
* @throws ProviderNotRegisteredException
|
257 |
**/
|
258 |
|
259 |
public DataExplorerParameters createDataExplorerParameters(String name) |
260 |
throws InitializeException, ProviderNotRegisteredException {
|
261 |
RegisterInfo registerInfo = this.getRegisterByName(name);
|
262 |
if (registerInfo == null){ |
263 |
throw new ProviderNotRegisteredException(name); |
264 |
} else if (registerInfo.type != RegisterInfo.TYPE_EXPLORER) { |
265 |
throw new ProviderNotRegisteredException(name); |
266 |
} |
267 |
|
268 |
try {
|
269 |
return (DataExplorerParameters)registerInfo.parametersClazz.newInstance();
|
270 |
} catch (InstantiationException e) { |
271 |
throw new InitializeException(name,e); |
272 |
} catch (IllegalAccessException e) { |
273 |
throw new InitializeException(name,e); |
274 |
} catch (Exception e) { |
275 |
// TODO: de momento para los class en el caso de que no exista el explorer.
|
276 |
throw new InitializeException(name, e); |
277 |
} |
278 |
} |
279 |
|
280 |
/* (non-Javadoc)
|
281 |
* @see org.gvsig.fmap.data.DataManager#createDataExplorerParameters(com.iver.utiles.XMLEntity)
|
282 |
*/
|
283 |
|
284 |
public DataExplorerParameters createDataExplorerParameters(
|
285 |
XMLEntity xmlEntity) throws InitializeException,
|
286 |
ProviderNotRegisteredException { |
287 |
String name = null; |
288 |
try {
|
289 |
name = xmlEntity.getStringProperty("dataExplorerName");
|
290 |
} catch (NotExistInXMLEntity e) {
|
291 |
throw new InitializeException(e); |
292 |
} |
293 |
DataExplorerParameters params = this.createDataExplorerParameters(name);
|
294 |
|
295 |
params.loadFromXMLEntity(xmlEntity); |
296 |
|
297 |
return params;
|
298 |
} |
299 |
|
300 |
/* (non-Javadoc)
|
301 |
* @see org.gvsig.fmap.data.DataManager#createDataExplorer(org.gvsig.fmap.data.impl.DataExplorerParameters)
|
302 |
*/
|
303 |
public DataExplorer createDataExplorer(DataExplorerParameters parameters)
|
304 |
throws InitializeException, ProviderNotRegisteredException {
|
305 |
RegisterInfo registerInfo = this.getRegisterByName(parameters.getDataExplorerName());
|
306 |
if (registerInfo == null){ |
307 |
throw new ProviderNotRegisteredException(parameters.getDataExplorerName()); |
308 |
} |
309 |
try {
|
310 |
DataExplorer dataSource= (DataExplorer)registerInfo.clazz.newInstance(); |
311 |
dataSource.init(parameters); |
312 |
return dataSource;
|
313 |
} catch (InstantiationException e) { |
314 |
throw new InitializeException(parameters.getDataExplorerName(),e); |
315 |
} catch (IllegalAccessException e) { |
316 |
throw new InitializeException(parameters.getDataExplorerName(),e); |
317 |
} |
318 |
} |
319 |
|
320 |
/* (non-Javadoc)
|
321 |
* @see org.gvsig.fmap.data.DataManager#createDataExplorer(com.iver.utiles.XMLEntity)
|
322 |
*/
|
323 |
|
324 |
|
325 |
public DataExplorer createDataExplorer(XMLEntity xmlEntity)
|
326 |
throws InitializeException, ProviderNotRegisteredException {
|
327 |
|
328 |
String name;
|
329 |
try {
|
330 |
name = xmlEntity.getStringProperty("dataExplorerName");
|
331 |
} catch (NotExistInXMLEntity e) {
|
332 |
throw new InitializeException(e); |
333 |
} |
334 |
|
335 |
RegisterInfo registerInfo = this.getRegisterByName(name);
|
336 |
if (registerInfo == null) { |
337 |
throw new ProviderNotRegisteredException(name); |
338 |
} |
339 |
try {
|
340 |
DataExplorerProvider dataSource = (DataExplorerProvider) registerInfo.clazz |
341 |
.newInstance(); |
342 |
dataSource.init(xmlEntity); |
343 |
return dataSource;
|
344 |
} catch (InstantiationException e) { |
345 |
throw new InitializeException(name, e); |
346 |
} catch (IllegalAccessException e) { |
347 |
throw new InitializeException(name, e); |
348 |
} |
349 |
} |
350 |
|
351 |
private RegisterInfo getRegisterByName(String name){ |
352 |
Iterator iterator=registers.iterator();
|
353 |
while (iterator.hasNext()) {
|
354 |
RegisterInfo registerInfo = (RegisterInfo) iterator.next(); |
355 |
if (name.equalsIgnoreCase(registerInfo.name)) {
|
356 |
return registerInfo;
|
357 |
} |
358 |
} |
359 |
return null; |
360 |
} |
361 |
|
362 |
/* (non-Javadoc)
|
363 |
* @see org.gvsig.fmap.data.DataManager#registerDataStoreOperation(java.lang.String, java.lang.String, org.gvsig.fmap.data.operation.DataStoreOperation)
|
364 |
*/
|
365 |
|
366 |
|
367 |
|
368 |
public int registerDataStoreOperation(String storeName, String operationName, Operation operation) { |
369 |
if (operationName == null){ |
370 |
throw new IllegalArgumentException("operationName cannot be null."); |
371 |
} |
372 |
if (operation == null){ |
373 |
throw new IllegalArgumentException("operation cannot be null."); |
374 |
} |
375 |
|
376 |
RegisterInfo register = this.getRegisterByName(storeName);
|
377 |
if (register == null){ |
378 |
throw new IllegalArgumentException(storeName + " not registered"); |
379 |
} |
380 |
int index = registerGeometryOperationName(operationName);
|
381 |
|
382 |
register.registerOperation(index, operation); |
383 |
|
384 |
return index;
|
385 |
} |
386 |
|
387 |
/**
|
388 |
*
|
389 |
* @param String
|
390 |
* operationName
|
391 |
* @return int index
|
392 |
* @throws IllegalArgumentException
|
393 |
*/
|
394 |
|
395 |
private int registerGeometryOperationName(String operationName) { |
396 |
if (operationName == null) { |
397 |
throw new IllegalArgumentException("operationName cannot be null."); |
398 |
} |
399 |
|
400 |
|
401 |
int index = this.getOperationIndex(operationName); |
402 |
|
403 |
// int index = dataStoreOperations .indexOf(operationName);
|
404 |
if (index == -1) { |
405 |
dataStoreOperations.add(operationName); |
406 |
index = dataStoreOperations.indexOf(operationName); |
407 |
} |
408 |
return index;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
*
|
413 |
* @param String
|
414 |
* operationName
|
415 |
* @return int index
|
416 |
*/
|
417 |
|
418 |
private int getOperationIndex(String operationName) { |
419 |
int index = -1; |
420 |
for (int i = 0; i < dataStoreOperations.size(); i++) { |
421 |
if (((String) dataStoreOperations.get(i)) |
422 |
.equalsIgnoreCase(operationName)) { |
423 |
index = i; |
424 |
break;
|
425 |
} |
426 |
} |
427 |
return index;
|
428 |
} |
429 |
|
430 |
/**
|
431 |
*
|
432 |
* @param DataStore
|
433 |
* store
|
434 |
* @param int code
|
435 |
* @param DataStoreOperationContext
|
436 |
* context
|
437 |
* @return Object
|
438 |
* @throws OperationException
|
439 |
* @throws DataStoreOperationNotSupportedException
|
440 |
*/
|
441 |
|
442 |
public Object invokeDataStoreOperation(DataStore store, int code, |
443 |
OperationContext context) throws OperationException,
|
444 |
OperationNotSupportedException {
|
445 |
if (code < 0 || code >= dataStoreOperations.size()) { |
446 |
throw new OperationNotSupportedException(code, "{unknow}"); |
447 |
} |
448 |
RegisterInfo register = this.getRegisterByName(store.getName());
|
449 |
Operation operation = register.getOperation(code);
|
450 |
if (operation == null){ |
451 |
throw new OperationNotSupportedException(code, |
452 |
(String) this.dataStoreOperations.get(code)); |
453 |
} |
454 |
return operation.invoke(store, context);
|
455 |
|
456 |
} |
457 |
|
458 |
/**
|
459 |
*
|
460 |
* @param DataStore
|
461 |
* store
|
462 |
* @param String
|
463 |
* operationName
|
464 |
* @param OperationContext
|
465 |
* context
|
466 |
* @return Object
|
467 |
* @throws OperationException
|
468 |
* @throws OperationNotSupportedException
|
469 |
*/
|
470 |
|
471 |
public Object invokeDataStoreOperation(DataStore store, |
472 |
String operationName, OperationContext context)
|
473 |
throws OperationException, OperationNotSupportedException { |
474 |
return this.invokeDataStoreOperation(store, this.getOperationIndex(operationName), context); |
475 |
} |
476 |
|
477 |
private class RegisterInfo{ |
478 |
public static final String TYPE_STORE = "store"; |
479 |
public static final String TYPE_EXPLORER = "explorer"; |
480 |
|
481 |
private String name; |
482 |
private String type; |
483 |
private Class clazz; |
484 |
private Class parametersClazz; |
485 |
private List operations = new ArrayList(); |
486 |
|
487 |
/**
|
488 |
*
|
489 |
* @param String
|
490 |
* type
|
491 |
* @param String
|
492 |
* name
|
493 |
* @param Class
|
494 |
* dsc
|
495 |
* @param Class
|
496 |
* pc
|
497 |
*/
|
498 |
|
499 |
public RegisterInfo(String type, String name, Class dsc, Class pc) { |
500 |
this.type = type;
|
501 |
this.name=name;
|
502 |
this.clazz=dsc;
|
503 |
this.parametersClazz=pc;
|
504 |
} |
505 |
|
506 |
/*
|
507 |
* (non-Javadoc)
|
508 |
* @see java.lang.Object#equals(java.lang.Object)
|
509 |
*/
|
510 |
|
511 |
public boolean equals(Object obj) { |
512 |
if (obj instanceof RegisterInfo){ |
513 |
RegisterInfo ri = (RegisterInfo)obj; |
514 |
return ri.name.equals(this.name) && |
515 |
ri.clazz.equals(this.clazz) &&
|
516 |
ri.parametersClazz.equals(this.parametersClazz);
|
517 |
} |
518 |
return super.equals(obj); |
519 |
} |
520 |
|
521 |
/**
|
522 |
*
|
523 |
* @param int index
|
524 |
* @param DataStoreOperation
|
525 |
* operation
|
526 |
*/
|
527 |
|
528 |
public void registerOperation(int index, Operation operation) { |
529 |
|
530 |
while (index > operations.size()) {
|
531 |
operations.add(null);
|
532 |
} |
533 |
|
534 |
if (index == operations.size()) {
|
535 |
operations.add(operation); |
536 |
} else {
|
537 |
operations.set(index, operation); |
538 |
} |
539 |
} |
540 |
|
541 |
/**
|
542 |
*
|
543 |
* @param int index
|
544 |
* @return DataStoreOperation
|
545 |
*/
|
546 |
|
547 |
public Operation getOperation(int index) { |
548 |
try{
|
549 |
return (Operation) this.operations.get(index); |
550 |
}catch (IndexOutOfBoundsException e) { |
551 |
return null; |
552 |
} |
553 |
} |
554 |
|
555 |
|
556 |
} |
557 |
|
558 |
/**
|
559 |
*
|
560 |
* @param String
|
561 |
* toreName
|
562 |
* @param String
|
563 |
* operationName
|
564 |
* @return boolean
|
565 |
*/
|
566 |
|
567 |
public boolean implementsDataStoreOperation( |
568 |
String storeName, String operationName) { |
569 |
return this.implementsDataStoreOperation(storeName, this.getOperationIndex(operationName)); |
570 |
} |
571 |
|
572 |
/**
|
573 |
*
|
574 |
* @param String
|
575 |
* storeName
|
576 |
* @param int operationCode
|
577 |
* @return boolean
|
578 |
*/
|
579 |
|
580 |
public boolean implementsDataStoreOperation( |
581 |
String storeName, int operationCode) { |
582 |
RegisterInfo register = this.getRegisterByName(storeName);
|
583 |
Operation operation = register.getOperation(operationCode);
|
584 |
if (operation == null){ |
585 |
return false; |
586 |
} |
587 |
return true; |
588 |
} |
589 |
|
590 |
/**
|
591 |
*
|
592 |
* @return String[] reg
|
593 |
*/
|
594 |
|
595 |
public String[] getRegisters() { |
596 |
String[] reg=new String[registers.size()]; |
597 |
for (int i = 0; i < registers.size(); i++) { |
598 |
reg[i]=((RegisterInfo)registers.get(i)).name; |
599 |
} |
600 |
return reg;
|
601 |
} |
602 |
|
603 |
/* (non-Javadoc)
|
604 |
* @see org.gvsig.fmap.data.DataManager#getRegistersStores()
|
605 |
*/
|
606 |
|
607 |
public String[] getRegistersStores() { |
608 |
return this.getRegisterOfType(RegisterInfo.TYPE_STORE); |
609 |
} |
610 |
|
611 |
/* (non-Javadoc)
|
612 |
* @see org.gvsig.fmap.data.DataManager#getRegistersExplorers()
|
613 |
*/
|
614 |
|
615 |
public String[] getRegistersExplorers() { |
616 |
return this.getRegisterOfType(RegisterInfo.TYPE_EXPLORER); |
617 |
} |
618 |
|
619 |
/**
|
620 |
*
|
621 |
* @param String
|
622 |
* type
|
623 |
* @return String[]
|
624 |
*/
|
625 |
|
626 |
private String[] getRegisterOfType(String type) { |
627 |
List reg = new ArrayList(); |
628 |
RegisterInfo info = null;
|
629 |
for (int i = 0; i < registers.size(); i++) { |
630 |
info =(RegisterInfo) registers.get(i); |
631 |
if (info.type == type) {
|
632 |
reg.add(info.name); |
633 |
} |
634 |
} |
635 |
return (String[]) reg.toArray(new String[0]); |
636 |
|
637 |
} |
638 |
|
639 |
|
640 |
public Evaluator createExpresion(String expresion) { |
641 |
try {
|
642 |
return (Evaluator) this.evaluatorConstructor.newInstance(new Object[] {expresion}); |
643 |
} catch (InstantiationException e) { |
644 |
throw new IllegalArgumentException(); |
645 |
} catch (IllegalAccessException e) { |
646 |
throw new IllegalArgumentException(); |
647 |
} catch (InvocationTargetException e) { |
648 |
throw new IllegalArgumentException(); |
649 |
} |
650 |
} |
651 |
|
652 |
public void registerDefaultEvaluator(Class evaluatorClass) { |
653 |
if (!evaluatorClass.isInstance(Evaluator.class)) {
|
654 |
throw new ClassCastException(); |
655 |
} |
656 |
try {
|
657 |
this.evaluatorConstructor = evaluatorClass
|
658 |
.getConstructor(new Class[] { String.class }); |
659 |
} catch (SecurityException e) { |
660 |
throw new ClassCastException(); |
661 |
} catch (NoSuchMethodException e) { |
662 |
throw new ClassCastException(); |
663 |
} |
664 |
this.evaluatorClass = evaluatorClass;
|
665 |
} |
666 |
|
667 |
public FeatureIndexProviderServices createDataIndexProvider(FeatureStore store,
|
668 |
FeatureType type, FeatureAttributeDescriptor attr, |
669 |
String[] providerNames) throws InitializeException, ProviderNotRegisteredException { |
670 |
|
671 |
String name = null; |
672 |
|
673 |
// look up the specified preferred providers. The first found is chosen
|
674 |
if (providerNames != null) { |
675 |
boolean notFound = true; |
676 |
for (int i = 0; i < providerNames.length && notFound; i++) { |
677 |
if (dataIndexProviderEP.containsKey(providerNames[i])) {
|
678 |
notFound = false;
|
679 |
name = providerNames[i]; |
680 |
} |
681 |
} |
682 |
} |
683 |
|
684 |
// if no preferred providers were specified or none was found, use the default one
|
685 |
if (providerNames == null || name == null) { |
686 |
name = getDefaultDataIndexProviderName(attr.getDataType()); |
687 |
} |
688 |
|
689 |
// instantiate, initialize and return it
|
690 |
try {
|
691 |
FeatureIndexProviderServices dataIndexProvider = (FeatureIndexProviderServices) dataIndexProviderEP.create(name); |
692 |
dataIndexProvider.initialize(); |
693 |
return dataIndexProvider;
|
694 |
} catch (IllegalAccessException e) { |
695 |
throw new ProviderNotRegisteredException(name); |
696 |
} catch (InstantiationException e) { |
697 |
throw new InitializeException(name, e); |
698 |
} |
699 |
} |
700 |
|
701 |
public FeatureIndexProviderServices createDataIndexProvider(FeatureStore store,
|
702 |
FeatureType type, FeatureAttributeDescriptor attr) throws InitializeException, ProviderNotRegisteredException {
|
703 |
return createDataIndexProvider(store, type, attr, null); |
704 |
} |
705 |
|
706 |
public String[] getDataIndexProviders(int dataType) { |
707 |
//FIXME
|
708 |
Set set = dataIndexProviderEP.keySet();
|
709 |
return (String[])set.toArray(); |
710 |
} |
711 |
|
712 |
public String getTemporaryDirectory() { |
713 |
// FIXME Define a better tempdir solution
|
714 |
String tmp = System.getenv("TMP"); |
715 |
if (tmp == null) { |
716 |
tmp = System.getenv("TEMP"); |
717 |
} |
718 |
if (tmp == null) { |
719 |
tmp = System.getenv("HOME"); |
720 |
} |
721 |
return tmp;
|
722 |
} |
723 |
|
724 |
public void registerDataIndexProvider(String name, String description, Class clazz) { |
725 |
dataIndexProviderEP.put(name, description, clazz); |
726 |
} |
727 |
|
728 |
public void setDefaultDataIndexProviderName(int dataType, String name) { |
729 |
defaultDataIndexProviders.put(new Integer(dataType), name); |
730 |
} |
731 |
|
732 |
public String getDefaultDataIndexProviderName(int dataType) { |
733 |
return (String) defaultDataIndexProviders.get(new Integer(dataType)); |
734 |
} |
735 |
|
736 |
public List getDataExplorerProviders() { |
737 |
// TODO Auto-generated method stub
|
738 |
return null; |
739 |
} |
740 |
|
741 |
public List getDataStoreProviders() { |
742 |
// TODO Auto-generated method stub
|
743 |
return null; |
744 |
} |
745 |
} |