Revision 24496

View differences:

branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/impl/DefaultDataManager.java
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.DataExplorer;
10
import org.gvsig.fmap.dal.DataExplorerParameters;
11
import org.gvsig.fmap.dal.DataManager;
12
import org.gvsig.fmap.dal.DataStore;
13
import org.gvsig.fmap.dal.DataStoreParameters;
14
import org.gvsig.fmap.dal.exceptions.InitializeException;
15
import org.gvsig.fmap.dal.exceptions.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.DataStoreProvider;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.evaluator.Evaluator;
30
import org.gvsig.tools.operations.OperationManager;
31

  
32
public class DefaultDataManager implements DataManager, DataManagerProviderServices {
33

  
34
	final static private String DATA_MANAGER_STORE = "Data.manager.stores";
35
	final static private String DATA_MANAGER_STORE_DESCRIPTION = "DAL stores providers";
36

  
37
	final static private String DATA_MANAGER_STORE_PARAMS = "Data.manager.stores.params";
38
	final static private String DATA_MANAGER_STORE_PARAMS_DESCRIPTION = "DAL stores providers parameters";
39

  
40
	final static private String DATA_MANAGER_EXPLORER = "Data.manager.explorers";
41
	final static private String DATA_MANAGER_EXPLORER_DESCRIPTION = "DAL explorers providers";
42

  
43
	final static private String DATA_MANAGER_EXPLORER_PARAMS = "Data.manager.explorers.params";
44
	final static private String DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION = "DAL explorer providers parameters";
45

  
46
	final static private String DATA_MANAGER_INDEX = "Data.manager.indexes";
47
	final static private String DATA_MANAGER_INDEX_DESCRIPTION = "DAL index providers";
48

  
49
	final static private String DATA_MANAGER_EXPRESION_EVALUATOR = "Data.manager.expresion.evaluator";
50
	final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT = "default";
51
	final static private String DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION = "DAL expresion evaluators.";
52

  
53
	/** This map contains the name of the default provider for each data type */
54
	private Map defaultDataIndexProviders;
55

  
56

  
57
	public DefaultDataManager() {
58
		/*
59
		 * Create te extensions point in te registry.
60
		 */
61
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE,
62
				DATA_MANAGER_STORE_DESCRIPTION);
63

  
64
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS,
65
				DATA_MANAGER_STORE_PARAMS_DESCRIPTION);
66

  
67
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER,
68
				DATA_MANAGER_EXPLORER_DESCRIPTION);
69

  
70
		ToolsLocator.getExtensionPointManager().add(
71
				DATA_MANAGER_EXPLORER_PARAMS,
72
				DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION);
73

  
74
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX,
75
				DATA_MANAGER_INDEX_DESCRIPTION);
76

  
77
		ToolsLocator.getExtensionPointManager().add(
78
				DATA_MANAGER_EXPRESION_EVALUATOR,
79
				DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION);
80

  
81
		initializeIndexes();
82
	}
83

  
84
	/**
85
	 *
86
	 * @return ResourceManager
87
	 */
88

  
89
	public ResourceManager getResourceManager() {
90
		return DALLocator.getResourceManager();
91
	}
92

  
93
	public OperationManager getOperationManager() {
94
		return ToolsLocator.getOperationManager();
95
	}
96

  
97
	public String getTemporaryDirectory() {
98
		// FIXME Define a better tempdir solution
99
		String tmp = System.getenv("TMP");
100
		if (tmp == null) {
101
			tmp = System.getenv("TEMP");
102
		}
103
		if (tmp == null) {
104
			tmp = System.getenv("HOME");
105
		}
106
		return tmp;
107
	}
108

  
109
	/*
110
	 * ====================================================================
111
	 *
112
	 * Store related services
113
	 */
114
	public void registerStoreProvider(String name,
115
			Class storeProviderClass,
116
			Class parametersClass) {
117

  
118
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE,
119
				DATA_MANAGER_STORE_DESCRIPTION).append(name, null,
120
				storeProviderClass);
121

  
122
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_STORE_PARAMS,
123
				DATA_MANAGER_STORE_PARAMS_DESCRIPTION).append(name, null,
124
				parametersClass);
125
	}
126

  
127
	public DataStoreParameters createStoreParameters(String name)
128
			throws InitializeException, ProviderNotRegisteredException {
129
		try {
130
			DataStoreParameters params = (DataStoreParameters) ToolsLocator
131
					.getExtensionPointManager().get(DATA_MANAGER_STORE_PARAMS)
132
					.create(name);
133
			if (params == null) {
134
				throw new ProviderNotRegisteredException(name);
135
			}
136
			return params;
137
		} catch (InstantiationException e) {
138
			throw new InitializeException(e);
139
		} catch (IllegalAccessException e) {
140
			throw new InitializeException(e);
141
		} catch (SecurityException e) {
142
			throw new InitializeException(e);
143
		} catch (IllegalArgumentException e) {
144
			throw new InitializeException(e);
145
		}
146
	}
147

  
148
	public DataStore createStore(DataStoreParameters parameters)
149
			throws InitializeException, ProviderNotRegisteredException {
150
		String name = parameters.getDataStoreName();
151

  
152
		try {
153
			DataStoreProvider storeProvider = (DataStoreProvider) ToolsLocator
154
					.getExtensionPointManager().get(DATA_MANAGER_STORE).create(
155
							name, new Object[] { parameters });
156
			if (storeProvider == null) {
157
				throw new ProviderNotRegisteredException(name);
158
			}
159

  
160
			return new DefaultFeatureStore(this, parameters,
161
					(FeatureStoreProvider) storeProvider);
162
		} catch (InstantiationException e) {
163
			throw new InitializeException(e);
164
		} catch (IllegalAccessException e) {
165
			throw new InitializeException(e);
166
		} catch (SecurityException e) {
167
			throw new InitializeException(e);
168
		} catch (IllegalArgumentException e) {
169
			throw new InitializeException(e);
170
		} catch (NoSuchMethodException e) {
171
			throw new InitializeException(e);
172
		} catch (InvocationTargetException e) {
173
			throw new InitializeException(e);
174
		}
175
	}
176

  
177
	public List getStoreProviders() {
178
		return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_STORE)
179
				.getNames();
180
	}
181

  
182
	/*
183
	 * ====================================================================
184
	 *
185
	 * Explorer related services
186
	 */
187
	public void registerExplorerProvider(String name, Class explorerClass,
188
			Class parametersClass) {
189

  
190
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_EXPLORER,
191
				DATA_MANAGER_EXPLORER_DESCRIPTION).append(name, null,
192
				explorerClass);
193

  
194
		ToolsLocator.getExtensionPointManager().add(
195
				DATA_MANAGER_EXPLORER_PARAMS,
196
				DATA_MANAGER_EXPLORER_PARAMS_DESCRIPTION).append(name, null,
197
				parametersClass);
198
	}
199

  
200
	public DataExplorerParameters createExplorerParameters(String name)
201
			throws InitializeException, ProviderNotRegisteredException {
202
		try {
203
			DataExplorerParameters params = (DataExplorerParameters) ToolsLocator
204
					.getExtensionPointManager()
205
					.get(
206
							DATA_MANAGER_EXPLORER_PARAMS)
207
					.create(name);
208
			if (params == null) {
209
				throw new ProviderNotRegisteredException(name);
210
			}
211
			return params;
212
		} catch (InstantiationException e) {
213
			throw new InitializeException(e);
214
		} catch (IllegalAccessException e) {
215
			throw new InitializeException(e);
216
		} catch (SecurityException e) {
217
			throw new InitializeException(e);
218
		} catch (IllegalArgumentException e) {
219
			throw new InitializeException(e);
220
		}
221
	}
222

  
223
	public DataExplorer createExplorer(DataExplorerParameters parameters)
224
			throws InitializeException, ProviderNotRegisteredException {
225

  
226
		String name = parameters.getType().getName();
227

  
228
		try {
229
			DataExplorer explorer = (DataExplorer) ToolsLocator
230
					.getExtensionPointManager().get(DATA_MANAGER_STORE).create(
231
							name, new Object[] { parameters });
232
			if (explorer == null) {
233
				throw new ProviderNotRegisteredException(name);
234
			}
235
			return explorer;
236
		} catch (InstantiationException e) {
237
			throw new InitializeException(e);
238
		} catch (IllegalAccessException e) {
239
			throw new InitializeException(e);
240
		} catch (SecurityException e) {
241
			throw new InitializeException(e);
242
		} catch (IllegalArgumentException e) {
243
			throw new InitializeException(e);
244
		} catch (NoSuchMethodException e) {
245
			throw new InitializeException(e);
246
		} catch (InvocationTargetException e) {
247
			throw new InitializeException(e);
248
		}
249
	}
250

  
251
	public List getExplorerProviders() {
252
		return ToolsLocator.getExtensionPointManager().get(
253
				DATA_MANAGER_EXPLORER).getNames();
254
	}
255

  
256

  
257
	/*
258
	 * ====================================================================
259
	 *
260
	 * Expresion evaluation related services
261
	 */
262
	public Evaluator createExpresion(String expresion)
263
			throws InitializeException {
264
		try {
265
			return (Evaluator) ToolsLocator.getExtensionPointManager().get(
266
					DATA_MANAGER_EXPRESION_EVALUATOR).create(
267
					DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT,
268
					new Object[] { expresion });
269
		} catch (SecurityException e) {
270
			throw new InitializeException(e);
271
		} catch (IllegalArgumentException e) {
272
			throw new InitializeException(e);
273
		} catch (NoSuchMethodException e) {
274
			throw new InitializeException(e);
275
		} catch (InstantiationException e) {
276
			throw new InitializeException(e);
277
		} catch (IllegalAccessException e) {
278
			throw new InitializeException(e);
279
		} catch (InvocationTargetException e) {
280
			throw new InitializeException(e);
281
		}
282
	}
283

  
284
	public void registerDefaultEvaluator(Class evaluatorClass) {
285
		if (!evaluatorClass.isInstance(Evaluator.class)) {
286
			throw new ClassCastException();
287
		}
288
		ToolsLocator.getExtensionPointManager().add(
289
				DATA_MANAGER_EXPRESION_EVALUATOR,
290
				DATA_MANAGER_EXPRESION_EVALUATOR_DESCRIPTION).append(
291
				DATA_MANAGER_EXPRESION_EVALUATOR_DEFAULT,
292
				"Default expresion evaluator for use in DAL", evaluatorClass);
293
	}
294

  
295
	/*
296
	 * ====================================================================
297
	 *
298
	 * Index related services
299
	 */
300

  
301

  
302
	public List getFeatureIndexProviders() {
303
		return ToolsLocator.getExtensionPointManager().get(DATA_MANAGER_INDEX)
304
		.getNames();
305
	}
306

  
307
	public void setDefaultFeatureIndexProviderName(int dataType, String name) {
308
		defaultDataIndexProviders.put(new Integer(dataType), name);
309
	}
310

  
311
	public String getDefaultFeatureIndexProviderName(int dataType) {
312
		return (String) defaultDataIndexProviders.get(new Integer(dataType));
313
	}
314

  
315
	public FeatureIndexProviderServices createFeatureIndexProvider(
316
			String name, FeatureStore store, FeatureType type, String indexName,
317
			FeatureAttributeDescriptor attr)
318
			throws InitializeException, ProviderNotRegisteredException {
319

  
320
			if (name == null) {
321
				name = getDefaultFeatureIndexProviderName(attr.getDataType());
322
			}
323

  
324
			try {
325
				FeatureIndexProvider provider = (FeatureIndexProvider) ToolsLocator
326
						.getExtensionPointManager()
327
						.get(
328
								DATA_MANAGER_INDEX)
329
						.create(name);
330
				if (provider == null) {
331
					throw new ProviderNotRegisteredException(name);
332
				}
333
				FeatureIndexProviderServices services = new DefaultFeatureIndex((FeatureStoreProviderServices) store, type, provider, attr.getName(), indexName);
334
				services.initialize();
335
				return services;
336
			} catch (InstantiationException e) {
337
				throw new InitializeException(e);
338
			} catch (IllegalAccessException e) {
339
				throw new InitializeException(e);
340
			} catch (SecurityException e) {
341
				throw new InitializeException(e);
342
			} catch (IllegalArgumentException e) {
343
				throw new InitializeException(e);
344
			}
345
	}
346

  
347
	public void registerFeatureIndexProvider(String name, String description,
348
			Class clazz, int dataType) {
349
		ToolsLocator.getExtensionPointManager().add(DATA_MANAGER_INDEX,
350
				DATA_MANAGER_INDEX_DESCRIPTION).append(name, null,
351
				clazz);
352

  
353
		if (getDefaultFeatureIndexProviderName(dataType) == null) {
354
			setDefaultFeatureIndexProviderName(dataType, name);
355
		}
356
	}
357

  
358
	private void initializeIndexes() {
359
		this.defaultDataIndexProviders = new HashMap();
360
	}
361

  
362
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/impl/DefaultDataExplorerType.java
1
package org.gvsig.fmap.dal.impl;
2

  
3
import org.gvsig.fmap.dal.DataExplorerType;
4

  
5
public class DefaultDataExplorerType implements DataExplorerType {
6

  
7
	public String getDescription() {
8
		// TODO Auto-generated method stub
9
		return null;
10
	}
11

  
12
	public String getName() {
13
		// TODO Auto-generated method stub
14
		return null;
15
	}
16

  
17
}
0 18

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DALLocator.java
1
package org.gvsig.fmap.dal;
2

  
3
import org.gvsig.fmap.dal.resource.ResourceManager;
4
import org.gvsig.tools.locator.AbstractLocator;
5
import org.gvsig.tools.locator.Locator;
6
import org.gvsig.tools.locator.LocatorException;
7

  
8
/**
9
 * @see {@link Locator}
10
 * 
11
 * This locator is the entry point of gvSIG's DAL, providing access to all DAL services. 
12
 * DAL services are grouped in two managers {@link DataManager} and {@link ResourceManager}.
13
 *  
14
 * This locator offers methods for registering as well as for obtaining both managers' unique instances.
15
 *
16
 */
17
public class DALLocator extends AbstractLocator {
18

  
19
	private static final String LOCATOR_NAME = "DALLocator";
20

  
21
	/**
22
	 * DataManager name used by the locator to access the instance
23
	 */
24
	public static final String DATA_MANAGER_NAME = "DataManager";
25

  
26
	private static final String DATA_MANAGER_DESCRIPTION = "DataManager of gvSIG Data Access Library";
27

  
28
	/**
29
	 * ResourceManager name used by the locator to access the instance
30
	 */
31
	public static final String RESOURCE_MANAGER_NAME = "ResourceManager";
32

  
33
	private static final String RESOURCE_MANAGER_DESCRIPTION = "ResourceManager of gvSIG Data Access Library";
34

  
35
	/**
36
	 * Unique instance.
37
	 */
38
	private static final DALLocator instance = new DALLocator();
39

  
40
	/**
41
	 * Return the singleton instance.
42
	 *
43
	 * @return the singleton instance
44
	 */
45
	public static DALLocator getInstance() {
46
		return instance;
47
	}
48

  
49
	/**
50
	 * Returns the Locator name.
51
	 * 
52
	 * @return String containing the locator name.
53
	 */
54
	public String getLocatorName() {
55
		return LOCATOR_NAME;
56
	}
57

  
58
	/**
59
	 * Return a reference to DataManager.
60
	 *
61
	 * @return a reference to DataManager
62
	 * @throws LocatorException
63
	 *             if there is no access to the class or the class cannot be
64
	 *             instantiated
65
	 * @see Locator#get(String)
66
	 */
67
	public static DataManager getDataManager() throws LocatorException {
68
		return (DataManager) getInstance().get(DATA_MANAGER_NAME);
69
	}
70

  
71
	/**
72
	 * Registers the Class implementing the DataManager interface.
73
	 *
74
	 * @param clazz
75
	 *            implementing the DataManager interface
76
	 */
77
	public static void registerDataManager(Class clazz) {
78
		getInstance().register(DATA_MANAGER_NAME, DATA_MANAGER_DESCRIPTION,
79
				clazz);
80
	}
81
	
82
	/**
83
	 * Registers a class as the default DataManager.
84
	 * 
85
	 * @param clazz
86
	 * 			  implementing the DataManager interface
87
	 */
88
	public static void registerDefaultDataManager(Class clazz) {
89
		getInstance().registerDefault(DATA_MANAGER_NAME, DATA_MANAGER_DESCRIPTION,
90
				clazz);
91
	}
92

  
93
	/**
94
	 * Return a reference to ResourceManager.
95
	 *
96
	 * @return a reference to ResourceManager
97
	 * @throws LocatorException
98
	 *             if there is no access to the class or the class cannot be
99
	 *             instantiated
100
	 * @see Locator#get(String)
101
	 */
102
	public static ResourceManager getResourceManager() throws LocatorException {
103
		return (ResourceManager) getInstance().get(RESOURCE_MANAGER_NAME);
104
	}
105

  
106
	/**
107
	 * Registers the Class implementing the MDManager interface.
108
	 *
109
	 * @param clazz
110
	 *            implementing the MDManager interface
111
	 */
112
	public static void registerResourceManager(Class clazz) {
113
		getInstance().register(RESOURCE_MANAGER_NAME,
114
				RESOURCE_MANAGER_DESCRIPTION, clazz);
115
	}
116

  
117
}
0 118

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataSet.java
1
package org.gvsig.fmap.dal;
2

  
3
import org.gvsig.tools.visitor.Visitable;
4

  
5
/**
6
 * <p> Interface that represents a generic set of data. It may proceed either from a data 
7
 * query, a user selection or a collection of locked elements.</p>
8
 */
9
public interface DataSet extends Visitable {
10
	
11
	/**
12
	 * Frees this DataSet resources
13
	 */
14
	public void dispose();
15
	
16
	/**
17
	 * Indicates whether this DataSet belongs to a specific store
18
	 * @param store 
19
	 * 			a DataStore   
20
	 * @return true if this belongs to the given DataStore, false if not.
21
	 */
22
	public boolean isFromStore(DataStore store);
23

  
24
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DALLibrary.java
1
package org.gvsig.fmap.dal;
2

  
3
import org.gvsig.fmap.dal.impl.DefaultDataManager;
4
import org.gvsig.fmap.dal.resource.ResourceManager;
5
import org.gvsig.fmap.dal.resource.impl.DefaultResourceManager;
6
import org.gvsig.tools.ToolsLibrary;
7
import org.gvsig.tools.locator.BaseLibrary;
8
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
9

  
10
/**
11
 * Initializes gvSIG's desktop DAL by registering the default implementation for {@link DataManager}
12
 * and {@link ResourceManager}.
13
 *
14
 */
15
public class DALLibrary extends BaseLibrary {
16

  
17
    public void initialize() throws ReferenceNotRegisteredException {
18
        super.initialize();
19
		ToolsLibrary toolsLib = new ToolsLibrary();
20

  
21
		toolsLib.initialize();
22
		toolsLib.postInitialize();
23

  
24
		DALLocator.registerDefaultDataManager(DefaultDataManager.class);
25
		DALLocator.registerResourceManager(DefaultResourceManager.class);
26
	}
27

  
28
	public void postInitialize() {
29
		super.postInitialize();
30

  
31
		// Validate there is any implementation registered.
32
		DataManager dataManager = DALLocator.getDataManager();
33
		if (dataManager == null) {
34
			throw new ReferenceNotRegisteredException(
35
					DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance());
36
		}
37

  
38
		ResourceManager resourceManager = DALLocator.getResourceManager();
39
		if (resourceManager == null) {
40
			throw new ReferenceNotRegisteredException(
41
					DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance());
42
		}
43
	}
44

  
45
}
0 46

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataStore.java
1
package org.gvsig.fmap.dal;
2

  
3
import java.util.Iterator;
4

  
5
import org.gvsig.fmap.dal.exceptions.DataException;
6
import org.gvsig.metadata.Metadatable;
7
import org.gvsig.tools.observer.ComplexWeakReferencingObservable;
8
import org.gvsig.tools.observer.Observer;
9
import org.gvsig.tools.operations.Operations;
10
import org.gvsig.tools.persistence.Persistent;
11

  
12
/**
13
 * <p>This is the basic interface for all data sources. Depending on the context, 
14
 * it can represent a geographic layer, an alphanumeric database table or any data file. 
15
 * DataStore offers generic services like:
16
 *   <ul>
17
 *     <li>Open, close and reject data sources</li>
18
 *     <li>Access to data sets, with the possibility of loading data 
19
 *     	in background.</li>
20
 *     <li>Use of selection and locks, as well as data sets</li>
21
 *     <li>Edition</li>
22
 *     <li>Register of event observers through the Observable interface</li>
23
 *     <li>Access to data sources embedded into itself (like GML)</li>
24
 *     <li>Information about the Spatial Reference Systems used by the data source</li>
25
 *   </ul>
26
 * </p>
27
 * <br>
28
 *
29
 */
30
public interface DataStore extends ComplexWeakReferencingObservable, Metadatable, Persistent,
31
		Operations {
32

  
33
	/**
34
	 * Returns this store's name.
35
	 * 
36
	 * @return String containing this store's name.
37
	 */
38
	public String getName();
39

  
40
	/**
41
	 * Return the of parameters of this store
42
	 *
43
	 * @return parameters of this store
44
	 */
45
	public DataStoreParameters getParameters();
46

  
47

  
48
	/**
49
	 * Refreshes this store state.
50
	 * 
51
	 * @throws DataException
52
	 */
53
	public void refresh() throws DataException;
54

  
55
	/**
56
	 * Frees this store's resources
57
	 * 
58
	 * @throws DataException
59
	 */
60
	public void dispose() throws DataException;
61

  
62
	/**
63
	 * Returns all available data.
64
	 *
65
	 * @return a set of data
66
	 * @throws DataException
67
	 *             if there is any error while loading the data
68
	 */
69
	DataSet getDataSet() throws DataException;
70

  
71
	/**
72
	 * Returns a subset of data taking into account the properties and
73
	 * restrictions of the DataQuery.
74
	 *
75
	 * @param dataQuery
76
	 *            defines the properties of the requested data
77
	 * @return a set of data
78
	 * @throws DataException
79
	 *             if there is any error while loading the data
80
	 */
81
	DataSet getDataSet(DataQuery dataQuery) throws DataException;
82

  
83
	/**
84
	 * Loads all available data and notifies the observer for each loaded block of data.
85
	 *
86
	 * @param observer
87
	 *            to be notified for each block of data loaded
88
	 * @throws DataException
89
	 *             if there is any error while loading the data
90
	 */
91
	void getDataSet(Observer observer) throws DataException;
92

  
93
	/**
94
	 * Loads a subset of data taking into account the properties and
95
	 * restrictions of the DataQuery. Data loading is performed by calling the
96
	 * Observer, once each data block is loaded.
97
	 *
98
	 * @param dataQuery
99
	 *            defines the properties of the requested data	 
100
	 * @param observer
101
	 *            to be notified for each block of data loaded
102
	 * @throws DataException
103
	 *             if there is any error while loading the data
104
	 */
105
	void getDataSet(DataQuery dataQuery, Observer observer) throws DataException;
106

  
107
	/**
108
	 * Returns the selected set of data
109
	 * 
110
	 * @return DataSet
111
	 */
112

  
113
	public DataSet getSelection() throws DataException;
114

  
115
	/**
116
	 * Sets the current data selection with the given data set.
117
	 * 
118
	 * @param DataSet
119
	 *            selection
120
	 * @throws DataException
121
	 */
122
	public void setSelection(DataSet selection) throws DataException;
123

  
124
	/**
125
	 * Creates a new selection.
126
	 *
127
	 * @return DataSet that contains the selection
128
	 * 
129
	 * @throws DataException
130
	 */
131
	public DataSet createSelection() throws DataException;
132

  
133
	/**
134
	 * Returns an iterator over this store children
135
	 * 
136
	 * @return Iterator over this DataStore children
137
	 */
138
	public Iterator getChildren();
139

  
140
	/**
141
	 * Returns the DataExplorer to which this DataStore belongs, if there is any.
142
	 * 
143
	 * @return DataExplorer to which this DataStore belongs, or <code>null</code> if 
144
	 * 		   this was not accessed through any DataExplorer.
145
	 * 
146
	 * @throws DataException
147
	 */
148
	public DataExplorer getExplorer() throws DataException;
149

  
150
}
151

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataExplorer.java
1
package org.gvsig.fmap.dal;
2

  
3
import java.util.List;
4

  
5
import org.gvsig.fmap.dal.exceptions.DataException;
6

  
7
/**
8
 * DataExplorer is an abstraction for any type of data server. It allows connecting 
9
 * to the server and browsing its contents.
10
 * 
11
 * More specifically, this interface provides a list of the available data stores 
12
 * in a server.
13
 */
14
public interface DataExplorer {
15

  
16
	/**
17
	 * Returns the DataExplorer's name
18
	 * 
19
	 * @return String containing this DataExplorer's name
20
	 */
21
	public String getName();
22
	
23
	/**
24
	 * Indicates whether this DataExplorer can create a new DataStore in the server.
25
	 * 
26
	 * @return true if this DataExplorer can be created or false otherwise.
27
	 */
28
	public boolean canCreate();
29

  
30
	/**
31
	 * Provides a list of available stores in the server.
32
	 * 
33
	 * @return list of DataStoreParameters
34
	 * 
35
	 * @throws DataException
36
	 */
37
	public List list() throws DataException;
38

  
39
	/**
40
	 * Adds a DataStoreParameters to this DataExplorer.
41
	 * 
42
	 * @param 
43
	 * 		parameters, an instance of DataStoreParameters.
44
	 * @return true if the DataStoreParameters were successfully added, false otherwise.
45
	 * 		
46
	 * @throws DataException
47
	 */
48
	public boolean add(DataStoreParameters parameters)
49
			throws DataException;
50

  
51
	/**
52
	 * Removes a store from the server given its DataStoreParameters.
53
	 * If the store is a file then this method deletes the file, if it is a table
54
	 * in a database then this method drops the table, and so on.
55
	 * 
56
	 * @param 
57
	 * 		parameters
58
	 * @throws DataException
59
	 */
60
	void remove(DataStoreParameters parameters) throws DataException;
61

  
62
	/**
63
	 * Given the store's name, returns its parameters for creation.
64
	 * 
65
	 * @param storeName
66
	 * @return
67
	 */
68
	public DataStoreParameters getCreationParameters(String storeName);
69

  
70
	/**
71
	 * Frees the resources used by this DataExplorer.
72
	 * 
73
	 * @throws DataException
74
	 */
75
	public void dispose() throws DataException;
76

  
77
	/**
78
	 * Returns this DataExplorer parameters
79
	 * 
80
	 * @return an instance of DataExplorerParameters containing this DataExplorer parameters.
81
	 */
82
	public DataExplorerParameters getParameters();
83

  
84
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataExplorerType.java
1
package org.gvsig.fmap.dal;
2

  
3
/**
4
 * This interface describes a DataExplorerType 
5
 * by providing its name and description.
6
 */
7
public interface DataExplorerType {
8

  
9
	/**
10
	 * Returns the name of this DataExplorerType
11
	 * 
12
	 * @return String containing the name of this DataExplorerType
13
	 */
14
	public String getName();
15

  
16
	/**
17
	 * Returns the description of this DataExplorerType
18
	 * 
19
	 * @return String containing the description of this DataExplorerType
20
	 */
21
	public String getDescription();
22

  
23
}
0 24

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataParameters.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal;
29

  
30
import org.gvsig.tools.persistence.Persistent;
31

  
32
/**
33
 * This interface is a generic persistent parameter container. It is used in a variety 
34
 * of contexts in which a set of arbitrary parameters is needed.
35
 */
36
public interface DataParameters extends Persistent {
37

  
38
	/**
39
	 * Returns the value of an attribute given its name.
40
	 * 
41
	 * @param name 
42
	 * 			of the attribute
43
	 * @return value of the attribute
44
	 */
45
	public Object getAttribute(String name);
46

  
47
	/**
48
	 * Sets the value of an attribute
49
	 * 
50
	 * @param name of the attribute, if it exists it is overwritten, if it does not exist it 
51
	 * 			is added to the container.
52
	 * @param value attribute's value
53
	 * @return this
54
	 */
55
	public DataParameters setAttribute(String name, Object value);
56

  
57
	/**
58
	 * clears the parameter container.
59
	 */
60
	public void clear();
61

  
62
	/**
63
	 * Creates and returns a new copy of this DataParameters.
64
	 * 
65
	 * @return a new copy of this
66
	 */
67
	public DataParameters getCopy();
68
}
0 69

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataStoreNotification.java
1
package org.gvsig.fmap.dal;
2

  
3
/**
4
 * This interface represents a notification produced by a DataStore.
5
 * 
6
 * Notifications can be of several types. This interface also defines a set 
7
 * of constants that represent the types of notifications that a DataStore 
8
 * can produce.
9
 */
10
public interface DataStoreNotification {
11

  
12
	/** Complex notification for special situations */
13
	public static final String COMPLEX_NOTIFICATION = "complex_notification";
14

  
15
	/** Fired before opening the store */
16
	public static final String BEFORE_OPEN = "before_Open_DataStore";
17
	
18
	/** Fired after opening the store */
19
	public static final String AFTER_OPEN = "after_Open_DataStore";
20

  
21
	/** Fired before closing the store */
22
	public static final String BEFORE_CLOSE = "before_Close_DataStore";
23
	
24
	/** Fired after closing the store */
25
	public static final String AFTER_CLOSE = "after_Close_DataStore";
26

  
27
	/** Fired before disposing the store */
28
	public static final String BEFORE_DISPOSE = "before_Dispose_DataStore";
29
	
30
	/** Fired after disposing the store */
31
	public static final String AFTER_DISPOSE = "after_Dispose_DataStore";
32

  
33
	/** Fired after the store selection has changed */
34
	public static final String SELECTION_CHANGE = "after_SelectionChange_DataStore";
35

  
36
	/** Fired when a resource of the store has changed */
37
	public static final String RESOURCE_CHANGED = "resourceChange_DataStore";
38

  
39
	/**
40
	 * Returns the DataStore that produced this notification
41
	 * @return DataStore source of this
42
	 */
43
	public DataStore getSource();
44
	
45
	/**
46
	 * Returns the type of this notification, represented by one of the constants defined in this interface.
47
	 * @return a String containing this notification's type
48
	 */
49
	public String getType();
50

  
51
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataTypes.java
1
package org.gvsig.fmap.dal;
2

  
3
import org.gvsig.fmap.dal.feature.Feature;
4
import org.gvsig.fmap.geom.Geometry;
5

  
6
/**
7
 * This interface defines a set of constants for all data 
8
 * types supported by the DAL.
9
 */
10
public interface DataTypes {
11
	public static final int UNKNOWN = 0;
12
	public static final int BYTE = 1;
13
	public static final int BOOLEAN = 2;
14
	public static final int INT = 3;
15
	public static final int LONG = 4;
16
	public static final int FLOAT = 5;
17
	public static final int DOUBLE = 6;
18
	public static final int STRING = 7;
19
	public static final int DATE = 8;
20
	public static final int TIME = 9;
21
	public static final int TIMESTAMP = 10;
22
	/** {@link Geometry} */
23
	public static final int GEOMETRY = 11;
24
	public static final int OBJECT = 12;
25
	/** {@link Feature} */
26
	public static final int FEATURE = 13;
27

  
28
	/** Array with the name of each data type. Use the constants to access this array. */
29
	public static final String[] TYPE_NAMES = new String[] {
30
		"UNKNOWN",
31
		"BYTE",
32
		"BOOLEAN",
33
		"INT",
34
		"LONG",
35
		"FLOAT",
36
		"DOUBLE",
37
		"STRING",
38
		"DATE",
39
		"TIME",
40
		"TIMESTAMP",
41
		"GEOMETRY",
42
		"OBJECT",
43
		"FEATURE"
44
	};
45
	
46

  
47
}
0 48

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataQuery.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {Create Parameter object to define queries}
26
 */
27
package org.gvsig.fmap.dal;
28

  
29
import java.util.HashMap;
30
import java.util.Map;
31

  
32
import org.gvsig.tools.persistence.AbstractPersistenceManager;
33
import org.gvsig.tools.persistence.PersistenceException;
34
import org.gvsig.tools.persistence.Persistent;
35
import org.gvsig.tools.persistence.PersistentState;
36

  
37
/**
38
 * Defines the properties of a collection of data, as a result of a query
39
 * through a DataStore.
40
 * <p>
41
 * The scala parameter can be used by the DataStore as a hint about the quality
42
 * or resolution of the data needed to view or operate with the data returned.
43
 * As an example, it may use the scala to return only a representative subset of
44
 * the data, or maybe to return Data with less detail, like a point or a line
45
 * instead of a polygon.
46
 * </p>
47
 *
48
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
49
 */
50
public class DataQuery implements Persistent {
51

  
52
    private double scale;
53

  
54
    private Map attributes = new HashMap();
55

  
56
    /**
57
     * Empty constructor.
58
     */
59
    public DataQuery() {
60
        super();
61
    }
62

  
63
    /**
64
     * Constructor with an scale.
65
     *
66
     * @param scale
67
     *            the scale for the data
68
     */
69
    public DataQuery(double scale) {
70
        super();
71
        this.scale = scale;
72
    }
73

  
74
    /**
75
     * Returns the scale.
76
     *
77
     * @return the scale
78
     */
79
    public double getScale() {
80
        return scale;
81
    }
82

  
83
    /**
84
     * Sets the scale.
85
     *
86
     * @param scale
87
     *            the scale to set
88
     */
89
    public void setScale(double scale) {
90
        this.scale = scale;
91
    }
92

  
93
    /**
94
     * Returns the value of an attribute.
95
     *
96
     * @param name
97
     *            of the attribute
98
     * @return the attribute value
99
     */
100
    public Object getAttribute(String name) {
101
        return attributes.get(name);
102
    }
103

  
104
    /**
105
     * Sets the value of an attribute.
106
     *
107
     * @param name
108
     *            of the attribute
109
     * @param value
110
     *            for the attribute
111
     */
112
    public void setAttribute(String name, Object value) {
113
        attributes.put(name, value);
114
    }
115

  
116
	public PersistentState getState() throws PersistenceException {
117
		return AbstractPersistenceManager.getState(this);
118
	}
119

  
120
	public void loadState(PersistentState state) throws PersistenceException {
121
		// FIXME: falta por terminar de implementar
122
		state.set("scale", scale);
123
	}
124

  
125
	public void setState(PersistentState state) throws PersistenceException {
126
		// FIXME: falta por terminar de implementar
127
		this.scale = state.getDouble("scale");
128
	}
129

  
130
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/ProviderNotRegisteredException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3
public class ProviderNotRegisteredException extends DataException {
4
	/**
5
	 *
6
	 */
7
	private static final long serialVersionUID = 4873697202452898968L;
8
	private final static String MESSAGE_FORMAT = "'%(providerName) not registered'.";
9
	private final static String MESSAGE_KEY = "_ProviderNotRegisteredException";
10

  
11
	public ProviderNotRegisteredException(String providerName) {
12
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
13
		setValue("providerName", providerName);
14
	}
15
}
0 16

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/WriteException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3
/**
4
 * FIXME
5
 *
6
 *
7
 */
8

  
9
public class WriteException extends DataException {
10

  
11
	/**
12
	 *
13
	 */
14
	private static final long serialVersionUID = 3656543768356545436L;
15
	private final static String MESSAGE_FORMAT = "Exception writing '%(resource)'.";
16
	private final static String MESSAGE_KEY = "_WriteException";
17

  
18
	public WriteException(String resource, Throwable cause) {
19
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
20
		setValue("resource", resource);
21
	}
22

  
23
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/DataEvaluatorException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3

  
4
public class DataEvaluatorException extends DataException {
5

  
6
	/**
7
	 *
8
	 */
9
	private static final long serialVersionUID = 4694862217382272837L;
10
	private final static String MESSAGE_FORMAT = "Evaluator exception";
11
	private final static String MESSAGE_KEY = "_DataEvaluatorException";
12

  
13
	public DataEvaluatorException(Throwable cause) {
14
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
15
	}
16

  
17
}
0 18

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/FileNotFoundException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3
import java.io.File;
4

  
5
public class FileNotFoundException extends DataException {
6

  
7
	/**
8
	 *
9
	 */
10
	private static final long serialVersionUID = 8748874874719052534L;
11
	private final static String MESSAGE_FORMAT = "File '%(file)' not found.";
12
	private final static String MESSAGE_KEY = "_OpenException";
13

  
14
	public FileNotFoundException(String filePath) {
15
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
16
		setValue("file", filePath);
17
	}
18

  
19
	public FileNotFoundException(File file) {
20
		this(file.getAbsolutePath());
21
	}
22

  
23
}
0 24

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/UnsupportedVersionException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3

  
4
public class UnsupportedVersionException extends DataException {
5
	/**
6
	 *
7
	 */
8
	private static final long serialVersionUID = 4614439562201218739L;
9
	private final static String MESSAGE_FORMAT = "Version '%(formatVersion) of '%(storeName)' not supported'.";
10
	private final static String MESSAGE_KEY = "_UnsupportedVersionException";
11

  
12
	public UnsupportedVersionException(String storeName, String formatVersion) {
13
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
14
		setValue("storeName", storeName);
15
		setValue("formatVersion", formatVersion);
16
	}
17
}
0 18

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/CopyParametersException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3
public class CopyParametersException extends DataRuntimeException {
4

  
5
	/**
6
	 *
7
	 */
8
	private static final long serialVersionUID = -401333851837941591L;
9
	private final static String MESSAGE_FORMAT = "Exception in copy '%(name)s'.";
10
	private final static String MESSAGE_KEY = "_CopyParametersException";
11

  
12
	public CopyParametersException(String name, Throwable cause) {
13
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
14
		setValue("name", name);
15
	}
16

  
17
}
0 18

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/UnsupportedEncodingException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3

  
4
public class UnsupportedEncodingException extends DataException {
5

  
6
	/**
7
	 *
8
	 */
9
	private static final long serialVersionUID = 7149758900102271415L;
10
	private final static String MESSAGE_FORMAT = "Unsupported encoding Exception.";
11
	private final static String MESSAGE_KEY = "_UnsupportedEncodingException";
12

  
13
	public UnsupportedEncodingException(Throwable cause) {
14
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
15
	}
16
}
0 17

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/DataEvaluatorRuntimeException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 {{Company}}   {{Task}}
26
*/
27

  
28

  
29
package org.gvsig.fmap.dal.exceptions;
30

  
31

  
32
public class DataEvaluatorRuntimeException extends DataRuntimeException {
33

  
34

  
35
	/**
36
	 *
37
	 */
38
	private static final long serialVersionUID = 957625345447753115L;
39
	private final static String MESSAGE_FORMAT = "Evaluator exception.";
40
	private final static String MESSAGE_KEY = "_DataEvaluatorRuntimeException";
41

  
42
	public DataEvaluatorRuntimeException(Throwable cause) {
43
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
44
	}
45
}
46

  
0 47

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/exceptions/InitializeException.java
1
package org.gvsig.fmap.dal.exceptions;
2

  
3

  
4
public class InitializeException extends DataException {
5

  
6
	/**
7
	 *
8
	 */
9
	private static final long serialVersionUID = -3054877505579218816L;
10
	private final static String MESSAGE_FORMAT = "Exception intializing '%(resource)'.";
11
	private final static String MESSAGE_KEY = "_InitializeException";
12

  
13
	public InitializeException(String resource, Throwable cause) {
14
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
15
		setValue("resource", resource);
16
	}
17

  
18
	public InitializeException(Throwable cause) {
19
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
20
		setValue("resource", "{unknow}");
21
	}
22

  
23
	protected InitializeException(String messageFormat, Throwable cause,
24
			String messageKey, long code) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff