Revision 42891

View differences:

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
23 23
 */
24 24
package org.gvsig.fmap.dal.impl;
25 25

  
26
import org.gvsig.fmap.dal.ExternalStoreProviderFactory;
26 27
import java.io.File;
27 28
import java.lang.reflect.InvocationTargetException;
28 29
import java.util.ArrayList;
29 30
import java.util.HashMap;
30
import java.util.Iterator;
31 31
import java.util.List;
32 32
import java.util.Map;
33 33

  
......
47 47
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
48 48
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
49 49
import org.gvsig.fmap.dal.feature.EditableFeatureType;
50
import org.gvsig.fmap.dal.feature.Feature;
51 50
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
52 51
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
53 52
import org.gvsig.fmap.dal.feature.FeatureQuery;
......
57 56
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType;
58 57
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex;
59 58
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
60
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectFeatureFacade;
61 59
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
62 60
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl;
63
import org.gvsig.fmap.dal.feature.spi.DataStoreProviderToFeatureStoreProviderFactoryWrapper;
64 61
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
65 62
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
66 63
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider;
67 64
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory;
68 65
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider;
69 66
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices;
67
import org.gvsig.fmap.dal.raster.RasterStoreProviderFactory;
70 68
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
71 69
import org.gvsig.fmap.dal.resource.ResourceManager;
72 70
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
......
228 226
     * 
229 227
     * Store related services
230 228
     */
229
    @Override
231 230
    public void registerStoreProvider(String name, Class storeProviderClass,
232 231
        Class parametersClass) {
233
        if (name == null || storeProviderClass == null
234
            || parametersClass == null) {
235
            // FIXME Exception
232
        if (name == null || storeProviderClass == null || parametersClass == null) {
236 233
            throw new IllegalArgumentException("Any parameters can be null");
237 234
        }
238 235

  
239 236
        if (!DataStoreParameters.class.isAssignableFrom(parametersClass)) {
240
            // FIXME Exception
241 237
            throw new IllegalArgumentException(parametersClass.getName()
242 238
                + " must implement org.gvsig.fmap.dal.DataStoreParameters");
243 239
        }
244 240

  
245 241
        if (CoverageStoreProvider.class.isAssignableFrom(storeProviderClass)) {
246
            ToolsLocator.getExtensionPointManager()
247
                .add(DATA_MANAGER_STORE, DATA_MANAGER_STORE_DESCRIPTION)
248
                .append(name, null, storeProviderClass);
249

  
250
            ToolsLocator
251
                .getExtensionPointManager()
252
                .add(DATA_MANAGER_STORE_PARAMS,
253
                    DATA_MANAGER_STORE_PARAMS_DESCRIPTION)
254
                .append(name, null, parametersClass);
242
            // Envuelve al proveedor en una factoria por defecto.
243
            this.registerStoreProviderFactory(new DataStoreProviderToCoverageProviderFactoryWrapper(
244
                name, "", storeProviderClass, parametersClass));
255 245
            return;
256 246
        }
257 247

  
......
351 341
            throw new UnauthorizedException(READ_STORE_AUTHORIZATION, parameters, provider);
352 342
        }
353 343
        
354
        // Usa el DynObjectEncoder y no el toString para ver los parametros aunque
344
        // Usa el DynObjectEncoder y no el toString para poder ver los parametros aunque
355 345
        // el proveedor de datos sobreescriba el metodo toString.
356 346
        DynObjectEncoder encoder = ToolsLocator.getDynObjectManager().createSimpleDynObjectEncoder();
357 347
        logger.info("openStore('{}','{}')", provider, encoder.encode(parameters));
......
360 350

  
361 351
        parameters.validate();
362 352

  
363
        DataStore store;
364
        try {
365
            DataStoreProviderFactory providerFactory;
366
            providerFactory =
367
                (DataStoreProviderFactory) ToolsLocator
368
                    .getExtensionPointManager()
369
                    .get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name);
370
            if (providerFactory != null) {
371
                if (FeatureStoreProviderFactory.class
372
                    .isAssignableFrom(providerFactory.getClass())) {
373
                    store = new DefaultFeatureStore();
374
                    this.intializeDataStore(store, parameters);
375
                    return store;
376
                }
377
            }
378
        } catch (InstantiationException e1) {
379
            // ignore
380
        } catch (IllegalAccessException e1) {
381
            // ignore
353
        DataStoreProviderFactory providerFactory = this.getStoreProviderFactory(name);
354
        if( providerFactory == null ) {
355
            throw new CantFindTheProviderFactoryException(name);
382 356
        }
357
        if( providerFactory instanceof FeatureStoreProviderFactory ) {
358
            DataStore store = this.createDefaultFeatureStore();
359
            this.intializeDataStore(store, parameters);
360
            return store;
361
            
362
        } else if( providerFactory instanceof RasterStoreProviderFactory ) {
363
            DataStore store = this.createDefaultRasterStore();
364
            this.intializeDataStore(store, parameters);
365
            return store;
366
            
367
        } else if( providerFactory instanceof ExternalStoreProviderFactory ) {
368
            DataStoreFactory factory = this.getStoreFactory(name);
369
            factory.setParameters(parameters);
370
            DataStore store = factory.createStore();
371
            this.intializeDataStore(store, parameters);
372
            return store;
373
            
374
        }
375
        throw new UnsupportedProviderFactoryException(name,providerFactory);
376
    }
383 377

  
384
        Extension storeProviderExtension =
385
            ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_STORE)
386
                .get(name);
378
    private static class UnsupportedProviderFactoryException extends InitializeException {
379
        private static final long serialVersionUID = 2635455949723618046L;
387 380

  
388
        if (storeProviderExtension == null) {
389
            throw new ProviderNotRegisteredException(name);
381
        public UnsupportedProviderFactoryException(String resourceName,DataStoreProviderFactory providerFactory) {
382
		super("Error intializing resource '%(resource)'. Unsupported provider factory '%(factory).", 
383
                    "_UnsupportedProviderFactoryException", 
384
                    serialVersionUID
385
                );
386
		setValue("resource", resourceName);
387
		setValue("factory", providerFactory.getClass().getName());
390 388
        }
389
        
390
    }
391
    
392
    private static class CantFindTheProviderFactoryException extends InitializeException {
393
        private static final long serialVersionUID = -2736434434177690011L;
391 394

  
392
        Class providerClass = storeProviderExtension.getExtension();
393
        if (providerClass == null) {
394
            throw new ProviderNotRegisteredException(name);
395
        public CantFindTheProviderFactoryException(String resourceName) {
396
		super("Error intializing resource '%(resource)'. Can't find provider factory for this resource.", 
397
                    "_CantFindTheProviderFactoryException", 
398
                    serialVersionUID
399
                );
400
		setValue("resource", resourceName);
395 401
        }
396

  
397
        if (CoverageStoreProvider.class.isAssignableFrom(providerClass)) {
398
            ExtensionPoint.Extension point =
399
                ToolsLocator.getExtensionPointManager()
400
                    .get(DATA_MANAGER_STORE_FACTORY).get(name);
401
            DataStoreFactory factory = null;
402
            try {
403
                factory = (DataStoreFactory) point.create();
404
            } catch (InstantiationException e) {
405
                throw new InitializeException(e);
406
            } catch (IllegalAccessException e) {
407
                throw new InitializeException(e);
408
            }
409
            factory.setParameters(parameters);
410
            store = factory.createStore();
411
        } else
412
            if (FeatureStoreProvider.class.isAssignableFrom(providerClass)) {
413

  
414
                store = new DefaultFeatureStore();
415

  
416
            } else {
417
                // FIXME Exception
418
                throw new InitializeException(name, new RuntimeException(
419
                    "Not supported implemtation: name=" + name
420
                        + " provider class=" + providerClass.getName()));
421
            }
422

  
423
        this.intializeDataStore(store, parameters);
424

  
425
        return store;
402
        
426 403
    }
427

  
404
    
405
    private DataStore createDefaultFeatureStore() {
406
        return new DefaultFeatureStore();
407
    }
408
    
409
    private DataStore createDefaultRasterStore() {
410
        try {
411
            return (DataStore) this.defaultRasterStoreClass.newInstance();
412
        } catch (InstantiationException | IllegalAccessException ex) {
413
            throw new RuntimeException("Can't create the default RasterStore", ex);
414
        }
415
    }
416
    
417
    private Class defaultRasterStoreClass = null;
418
    public void registerDefaultRasterStore(Class rasterStoreClass) {
419
        this.defaultRasterStoreClass = rasterStoreClass;
420
    }
421
    
422
    private DataStoreFactory getStoreFactory(String name) throws InitializeException {
423
        ExtensionPoint.Extension point =
424
            ToolsLocator.getExtensionPointManager()
425
                .get(DATA_MANAGER_STORE_FACTORY).get(name);
426
        try {
427
            DataStoreFactory factory = (DataStoreFactory) point.create();
428
            return factory;
429
        } catch (InstantiationException | IllegalAccessException e) {
430
            throw new InitializeException(e);
431
        }
432
    }
433
    
428 434
    public DataStore openStore(String provider, DynObject parameters)
429 435
        throws InitializeException, ProviderNotRegisteredException,
430 436
        ValidateDataParametersException {
......
470 476
        return names3;
471 477
    }
472 478

  
479
    @Override
473 480
    public DataStoreProviderFactory getStoreProviderFactory(String name) {
474 481
        try {
475 482
            return (DataStoreProviderFactory) ToolsLocator
476 483
                .getExtensionPointManager()
477 484
                .get(DATA_MANAGER_STORE_PROVIDER_FACTORY).create(name);
478
        } catch (InstantiationException e) {
485
        } catch (InstantiationException | IllegalAccessException e) {
479 486
            return null;
480
        } catch (IllegalAccessException e) {
481
            return null;
482 487
        }
483 488
    }
484 489

  
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/DataStoreProviderToFeatureStoreProviderFactoryWrapper.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 java.lang.reflect.Constructor;
27

  
28
import org.gvsig.fmap.dal.DataParameters;
29
import org.gvsig.fmap.dal.DataStoreProvider;
30
import org.gvsig.fmap.dal.exception.InitializeException;
31
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
32
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory;
33
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
34
import org.gvsig.tools.dynobject.DynObject;
35

  
36
public class DataStoreProviderToFeatureStoreProviderFactoryWrapper extends
37
		AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory {
38

  
39
	private Class providerClass = null;
40
	private Class parametersClass = null;
41

  
42
	public DataStoreProviderToFeatureStoreProviderFactoryWrapper(String name, String description,
43
			Class provider, Class parametersClass) {
44
		super(name, description);
45
		this.providerClass = provider;
46
		this.parametersClass = parametersClass;
47
	}
48

  
49
	public DataStoreProvider createProvider(DataParameters parameters,
50
			DataStoreProviderServices providerServices)
51
			throws InitializeException {
52
		try {
53
			Class[] argsTypes = new Class[] { DataParameters.class,
54
					DataStoreProviderServices.class };
55
			Object[] args = new Object[] { parameters, providerServices };
56

  
57
			Constructor contructor;
58
			contructor = findConstructor(providerClass, argsTypes);
59
			return (DataStoreProvider) contructor.newInstance(args);
60
		} catch (Throwable e) {
61
			throw new InitializeException(e);
62
		}
63
	}
64

  
65
	public final DynObject createParameters() {
66
		try {
67
			return (DynObject) parametersClass.newInstance();
68
		} catch (Exception e) {
69
			throw new RuntimeException(e);
70
		}
71
	}
72
	
73
	protected Constructor findConstructor(Class clazz, Class[] types)
74
			throws SecurityException, NoSuchMethodException {
75
		try {
76
			return clazz.getConstructor(types);
77
		} catch (NoSuchMethodException e) {
78
			// Nothing to do
79
		}
80

  
81
		// search for the required constructor
82
		Constructor[] constrs = clazz.getConstructors();
83
		boolean allMatch;
84
		for (int i = 0; i < constrs.length; i++) {
85
			Class[] paramTypes = constrs[i].getParameterTypes();
86
			if (paramTypes.length == types.length) { // a general candidate
87
				allMatch = true;
88
				for (int j = 0; j < paramTypes.length; j++) {
89
					if (!isParameterCompatible(types[j], paramTypes[j])) {
90
						allMatch = false;
91
						break;
92
					}
93
				}
94
				if (allMatch) {
95
					return constrs[i];
96
				}
97

  
98
			}
99
		}
100
		StringBuffer strb = new StringBuffer();
101
		strb.append(clazz.getName());
102
		strb.append('(');
103
		if (types.length > 0) {
104
			for (int i = 0; i < types.length - 1; i++) {
105
				strb.append(types[i].getName());
106
				strb.append(',');
107
			}
108
			strb.append(types[types.length - 1].getName());
109
		}
110
		strb.append(')');
111
		throw new NoSuchMethodException(strb.toString());
112
	}
113

  
114
	private boolean isParameterCompatible(Class current, Class defined) {
115
		if (current == null) {
116
			return !defined.isPrimitive();
117
		} else {
118
			return current.isAssignableFrom(defined);
119
		}
120
	}
121
}
0 122

  
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/DataStoreProviderToCoverageProviderFactoryWrapper.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.lang.reflect.Constructor;
28

  
29
import org.gvsig.fmap.dal.DataParameters;
30
import org.gvsig.fmap.dal.DataStoreProvider;
31
import org.gvsig.fmap.dal.exception.InitializeException;
32
import org.gvsig.fmap.dal.spi.AbstractDataStoreProviderFactory;
33
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
34
import org.gvsig.tools.dynobject.DynObject;
35

  
36
public class DataStoreProviderToCoverageProviderFactoryWrapper extends
37
		AbstractDataStoreProviderFactory implements ExternalStoreProviderFactory {
38

  
39
	private Class providerClass = null;
40
	private Class parametersClass = null;
41

  
42
	public DataStoreProviderToCoverageProviderFactoryWrapper(String name, String description,
43
			Class provider, Class parametersClass) {
44
                super(name,description);
45
		this.providerClass = provider;
46
		this.parametersClass = parametersClass;
47
	}
48

  
49
        @Override
50
	public DataStoreProvider createProvider(DataParameters parameters,
51
			DataStoreProviderServices providerServices)
52
			throws InitializeException {
53
		try {
54
			Class[] argsTypes = new Class[] { DataParameters.class,
55
					DataStoreProviderServices.class };
56
			Object[] args = new Object[] { parameters, providerServices };
57

  
58
			Constructor contructor;
59
			contructor = findConstructor(providerClass, argsTypes);
60
			return (DataStoreProvider) contructor.newInstance(args);
61
		} catch (Throwable e) {
62
			throw new InitializeException(e);
63
		}
64
	}
65

  
66
        @Override
67
	public final DynObject createParameters() {
68
		try {
69
			return (DynObject) parametersClass.newInstance();
70
		} catch (Exception e) {
71
			throw new RuntimeException(e);
72
		}
73
	}
74
	
75
	protected Constructor findConstructor(Class clazz, Class[] types)
76
			throws SecurityException, NoSuchMethodException {
77
		try {
78
			return clazz.getConstructor(types);
79
		} catch (NoSuchMethodException e) {
80
			// Nothing to do
81
		}
82

  
83
		// search for the required constructor
84
		Constructor[] constrs = clazz.getConstructors();
85
		boolean allMatch;
86
            for (Constructor constr : constrs) {
87
                Class[] paramTypes = constr.getParameterTypes();
88
                if (paramTypes.length == types.length) {
89
                    // a general candidate
90
                    allMatch = true;
91
                    for (int j = 0; j < paramTypes.length; j++) {
92
                        if (!isParameterCompatible(types[j], paramTypes[j])) {
93
                            allMatch = false;
94
                            break;
95
					}
96
				}
97
                    if (allMatch) {
98
                        return constr;
99
                    }
100
                }
101
            }
102
		StringBuilder strb = new StringBuilder();
103
		strb.append(clazz.getName());
104
		strb.append('(');
105
		if (types.length > 0) {
106
			for (int i = 0; i < types.length - 1; i++) {
107
				strb.append(types[i].getName());
108
				strb.append(',');
109
			}
110
			strb.append(types[types.length - 1].getName());
111
		}
112
		strb.append(')');
113
		throw new NoSuchMethodException(strb.toString());
114
	}
115

  
116
	private boolean isParameterCompatible(Class current, Class defined) {
117
		if (current == null) {
118
			return !defined.isPrimitive();
119
		} else {
120
			return current.isAssignableFrom(defined);
121
		}
122
	}
123

  
124
}
0 125

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/exception/InitializeException.java
30 30
	 *
31 31
	 */
32 32
	private static final long serialVersionUID = -3054877505579218816L;
33
	private final static String MESSAGE_FORMAT = "Exception intializing '%(resource)'.";
33
	private final static String MESSAGE_FORMAT = "Error intializing resource '%(resource)'.";
34 34
	private final static String MESSAGE_KEY = "_InitializeException";
35 35

  
36
        protected InitializeException() {
37
            super();
38
        }
39
        
36 40
	public InitializeException(String resource, Throwable cause) {
37 41
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
38 42
		setValue("resource", resource);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/exception/DataException.java
37 37

  
38 38
	protected Map values = new HashMap();
39 39

  
40
        protected DataException() {
41
            
42
        }
43
        
40 44
	public DataException(String messageFormat, Throwable cause,
41 45
			String messageKey, long code) {
42 46
		super(messageFormat, cause, messageKey, code);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/raster/RasterStoreProviderFactory.java
1

  
2
package org.gvsig.fmap.dal.raster;
3

  
4
import org.gvsig.fmap.dal.DataStoreProviderFactory;
5

  
6

  
7
public interface RasterStoreProviderFactory extends DataStoreProviderFactory {
8
    
9
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/ExternalStoreProviderFactory.java
1

  
2
package org.gvsig.fmap.dal;
3

  
4
import org.gvsig.fmap.dal.DataStoreProviderFactory;
5

  
6

  
7
public interface ExternalStoreProviderFactory extends DataStoreProviderFactory {
8
    
9
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/DataStoreProviderToFeatureStoreProviderFactoryWrapper.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.feature.spi;
25

  
26
import java.lang.reflect.Constructor;
27

  
28
import org.gvsig.fmap.dal.DataParameters;
29
import org.gvsig.fmap.dal.DataStoreProvider;
30
import org.gvsig.fmap.dal.exception.InitializeException;
31
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
32
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
33
import org.gvsig.tools.dynobject.DynObject;
34

  
35
public class DataStoreProviderToFeatureStoreProviderFactoryWrapper extends
36
		AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory {
37

  
38
	private Class providerClass = null;
39
	private Class parametersClass = null;
40

  
41
	public DataStoreProviderToFeatureStoreProviderFactoryWrapper(String name, String description,
42
			Class provider, Class parametersClass) {
43
		super(name, description);
44
		this.providerClass = provider;
45
		this.parametersClass = parametersClass;
46
	}
47

  
48
	public DataStoreProvider createProvider(DataParameters parameters,
49
			DataStoreProviderServices providerServices)
50
			throws InitializeException {
51
		try {
52
			Class[] argsTypes = new Class[] { DataParameters.class,
53
					DataStoreProviderServices.class };
54
			Object[] args = new Object[] { parameters, providerServices };
55

  
56
			Constructor contructor;
57
			contructor = findConstructor(providerClass, argsTypes);
58
			return (DataStoreProvider) contructor.newInstance(args);
59
		} catch (Throwable e) {
60
			throw new InitializeException(e);
61
		}
62
	}
63

  
64
	public final DynObject createParameters() {
65
		try {
66
			return (DynObject) parametersClass.newInstance();
67
		} catch (Exception e) {
68
			throw new RuntimeException(e);
69
		}
70
	}
71
	
72
	protected Constructor findConstructor(Class clazz, Class[] types)
73
			throws SecurityException, NoSuchMethodException {
74
		try {
75
			return clazz.getConstructor(types);
76
		} catch (NoSuchMethodException e) {
77
			// Nothing to do
78
		}
79

  
80
		// search for the required constructor
81
		Constructor[] constrs = clazz.getConstructors();
82
		boolean allMatch;
83
		for (int i = 0; i < constrs.length; i++) {
84
			Class[] paramTypes = constrs[i].getParameterTypes();
85
			if (paramTypes.length == types.length) { // a general candidate
86
				allMatch = true;
87
				for (int j = 0; j < paramTypes.length; j++) {
88
					if (!isParameterCompatible(types[j], paramTypes[j])) {
89
						allMatch = false;
90
						break;
91
					}
92
				}
93
				if (allMatch) {
94
					return constrs[i];
95
				}
96

  
97
			}
98
		}
99
		StringBuffer strb = new StringBuffer();
100
		strb.append(clazz.getName());
101
		strb.append('(');
102
		if (types.length > 0) {
103
			for (int i = 0; i < types.length - 1; i++) {
104
				strb.append(types[i].getName());
105
				strb.append(',');
106
			}
107
			strb.append(types[types.length - 1].getName());
108
		}
109
		strb.append(')');
110
		throw new NoSuchMethodException(strb.toString());
111
	}
112

  
113
	private boolean isParameterCompatible(Class current, Class defined) {
114
		if (current == null) {
115
			return !defined.isPrimitive();
116
		} else {
117
			return current.isAssignableFrom(defined);
118
		}
119
	}
120
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/AbstractDataStoreProviderFactory.java
41 41
		this.description = description;
42 42
	}
43 43
	
44
        @Override
44 45
	public final Provider create(DynObject parameters, ProviderServices services)
45 46
			throws ServiceException {
46 47
		throw new UnsupportedOperationException();
47 48
	}
48 49

  
50
        @Override
49 51
	public final void initialize() {
50 52
		throw new UnsupportedOperationException();
51 53
	}
52 54

  
55
        @Override
53 56
	public final String getName() {
54 57
		return this.name;
55 58
	}
56 59

  
60
        @Override
57 61
	public final String getDescription() {
58 62
		return this.description;
59 63
	}
60 64

  
65
        @Override
61 66
	public int allowRead() {
62 67
		return UNKNOWN;
63 68
	}
64 69

  
70
        @Override
65 71
	public int allowWrite() {
66 72
		return UNKNOWN;
67 73
	}
68 74

  
75
        @Override
69 76
	public int allowCreate() {
70 77
		return UNKNOWN;
71 78
	}
72 79

  
80
        @Override
73 81
	public int hasTabularSupport() {
74 82
		return UNKNOWN;
75 83
	}
76 84

  
85
        @Override
77 86
	public int hasVectorialSupport() {
78 87
		return UNKNOWN;
79 88
	}
80 89

  
90
        @Override
81 91
	public int hasRasterSupport() {
82 92
		return UNKNOWN;
83 93
	}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/DALSPILocator.java
1

  
2
package org.gvsig.fmap.dal.spi;
3

  
4
import org.gvsig.fmap.dal.DALLocator;
5
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
6
import org.gvsig.tools.locator.LocatorException;
7

  
8

  
9
public class DALSPILocator {
10
    
11
    public static DataManagerProviderServices getDataManagerProviderServices() throws LocatorException {
12
        return (DataManagerProviderServices) DALLocator.getDataManager();
13
    }
14
    
15
    public static ResourceManagerProviderServices getResourceManagerProviderServices() throws LocatorException {
16
        return (ResourceManagerProviderServices) DALLocator.getResourceManager();
17
    }
18
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/DataManagerProviderServices.java
49 49
 */
50 50
public interface DataManagerProviderServices extends DataManager {
51 51

  
52
    /**
53
     * 
54
     * @param name
55
     * @param dataStoreProviderClass
56
     * @param parametersClass 
57
     * @deprecated Use registerStoreProviderFactory
58
     */
52 59
	public void registerStoreProvider(String name,
53 60
			Class dataStoreProviderClass,
54 61
			Class parametersClass);
......
56 63
	/**
57 64
	 * Registers a store factory. 
58 65
	 * @param name
59
	 * @param dataStoreProviderClass
60
	 * @param factoryClass
66
         * @param storeFactoryClass
61 67
	 */
62 68
	public void registerStoreFactory(String name,
63 69
			Class storeFactoryClass);
......
67 73
	 *
68 74
	 * FIXME
69 75
	 *
70
	 * @param <code>name</code> of de provider
76
         * @param name
71 77
	 * @param dataSourceClass
72 78
	 *            class of provider
73 79
	 * @param parametersClass
......
98 104
	/**
99 105
	 * Returns a DataIndexProvider compatible with the attribute data type.
100 106
	 *
107
         * @param name
101 108
	 * @param store
102 109
	 *            associated FeatureStore
103 110
	 * @param type
104 111
	 *            associated FeatureType
112
         * @param indexName
105 113
	 * @param attr
106 114
	 *            associated FeatureAttributeDescriptor
107
	 * @param providerNames
108
	 *            array of strings containing one or more preferred providers
109 115
	 * @return empty DataIndexProvider, initialized and ready to use
116
         * @throws org.gvsig.fmap.dal.exception.InitializeException
117
         * @throws org.gvsig.fmap.dal.exception.ProviderNotRegisteredException
110 118
	 */
111 119
	public FeatureIndexProviderServices createFeatureIndexProvider(String name, FeatureStore store, FeatureType type,
112 120
			String indexName,
113 121
			FeatureAttributeDescriptor attr) throws InitializeException,
114 122
			ProviderNotRegisteredException;
115 123

  
116
	 /**
117
     * Registers a new cache provider.
118
     *
119
     * @param name
120
     * 			provider's name
121
     *
122
     * @param description
123
     * 			provider's description
124
     *
125
     * @param clazz
126
     * 			a custom FeatureCacheProvider implementation
127
     */
124
       /**
125
        * Registers a new cache provider.
126
        *
127
        *
128
        * @param providerFactory
129
        */
128 130
	 public void registerFeatureCacheProvider(FeatureCacheProviderFactory providerFactory);
129 131
		    
130 132
	 /**
......
143 145
	  *
144 146
	  * Creates a new instance of the provider associated to the passed parameters.
145 147
	  * 
146
	  * @param store
148
          * @param providerServices
147 149
	  * @param parameters
148 150
	  * @return
149 151
	  * @throws InitializeException
......
153 155

  
154 156
	 public void registerStoreProviderFactory(DataStoreProviderFactory factory);
155 157

  
158
         /**
159
          * Este metodo es temporal hasta que se integre el nuevo raster en el 
160
          * core de gvSIG.
161
          * 
162
          * @param rasterStoreClass 
163
          */
164
         public void registerDefaultRasterStore(Class rasterStoreClass);
156 165
}

Also available in: Unified diff