Revision 20626 trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dbf/DBFStore.java

View differences:

DBFStore.java
1 1
package org.gvsig.data.datastores.vectorial.file.dbf;
2 2

  
3
import java.io.File;
4 3
import java.lang.ref.WeakReference;
5
import java.text.DateFormat;
6
import java.text.ParseException;
4
import java.security.KeyException;
7 5
import java.util.ArrayList;
8 6
import java.util.Collection;
9
import java.util.Date;
10 7
import java.util.Iterator;
11 8
import java.util.List;
12
import java.util.Locale;
13 9

  
14 10
import org.gvsig.data.DataManager;
15 11
import org.gvsig.data.IDataCollection;
16 12
import org.gvsig.data.IDataExplorer;
17 13
import org.gvsig.data.IDataExplorerParameters;
18 14
import org.gvsig.data.IDataStoreParameters;
15
import org.gvsig.data.ResourceManager;
19 16
import org.gvsig.data.datastores.vectorial.IFeaturesWriter;
20 17
import org.gvsig.data.datastores.vectorial.file.DataExplorerFileParameters;
21
import org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile;
22 18
import org.gvsig.data.exception.CloseException;
19
import org.gvsig.data.exception.DataException;
23 20
import org.gvsig.data.exception.InitializeException;
24 21
import org.gvsig.data.exception.OpenException;
25 22
import org.gvsig.data.exception.ReadException;
26 23
import org.gvsig.data.exception.WriteException;
27 24
import org.gvsig.data.spatialprovisional.IExtent;
25
import org.gvsig.data.vectorial.AttributeDescriptor;
28 26
import org.gvsig.data.vectorial.FeatureStore;
29
import org.gvsig.data.vectorial.AttributeDescriptor;
27
import org.gvsig.data.vectorial.FeatureStoreNotification;
30 28
import org.gvsig.data.vectorial.FeatureType;
31
import org.gvsig.data.vectorial.FeatureStoreNotification;
32 29
import org.gvsig.data.vectorial.IFeature;
33 30
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
34 31
import org.gvsig.data.vectorial.IFeatureCollection;
35 32
import org.gvsig.data.vectorial.IFeatureID;
36 33
import org.gvsig.data.vectorial.IFeatureType;
37 34
import org.gvsig.data.vectorial.IsNotAttributeSettingException;
38
import org.gvsig.data.vectorial.IsNotFeatureSettingException;
39 35
import org.gvsig.exceptions.BaseException;
40 36
import org.gvsig.metadata.IMetadata;
41 37
import org.gvsig.metadata.IMetadataManager;
......
43 39

  
44 40
public class DBFStore extends FeatureStore{
45 41
	public static String DATASTORE_NAME = "DBFStore";
46
	protected DbaseFile dbf = new DbaseFile();
42
	protected DBFResource dbf= null;
47 43
	protected List featureTypes = new ArrayList();//<IFeatureType>
48 44
	protected IFeatureType featureType;
49
	private File file;
50 45
	protected IMetadata metadata;
51 46
	private DBFStoreParameters dbfParameters=null;
52 47

  
......
54 49
	 public void init(IDataStoreParameters parameters) throws InitializeException {
55 50
	        super.init(parameters);
56 51
	    	dbfParameters=(DBFStoreParameters)parameters;
57
	    	file=dbfParameters.getDBFFile();
58
			dbf.open(file);
52
	    	DBFResource tmpResoure = new DBFResource(dbfParameters.getDBFFile());
53

  
54
	    	ResourceManager resMan = ResourceManager.getResourceManager();
55

  
56
	    	try {
57
				this.dbf = (DBFResource)resMan.addResource(tmpResoure);
58
			} catch (DataException e1) {
59
				throw new InitializeException(this.getName(),e1);
60
			}
61

  
62
//			this.dbf.open();
63
//			this.dbf.addObserver(this);
64
	    	int fieldCount = -1;
65
	    	try{
66
	    		fieldCount =dbf.getFieldCount();
67
	    	} catch (DataException e) {
68
	    		throw new InitializeException(this.getName(),e);
69
			}
70

  
59 71
			featureType=new FeatureType();
60
			    for (int i = 0; i < dbf.getFieldCount(); i++) {
72
			    for (int i = 0; i < fieldCount; i++) {
61 73
			    	IFeatureAttributeDescriptor fad;
62 74
					try {
63 75
						fad = createFeatureAttribute(i);
64 76
					} catch (IsNotAttributeSettingException e) {
65 77
						throw new InitializeException(this.getName(),e);
78
					} catch (ReadException e) {
79
						// TODO Auto-generated catch block
80
						throw new InitializeException(this.getName(),e);
66 81
					}
67 82
	                featureType.add(fad);
68 83
	            }
69 84
	    }
70 85

  
71 86

  
72
	 private IFeatureAttributeDescriptor createFeatureAttribute(int i) throws IsNotAttributeSettingException {
87
	 private IFeatureAttributeDescriptor createFeatureAttribute(int i) throws ReadException, IsNotAttributeSettingException {
73 88
	        char fieldType = dbf.getFieldType(i);
74 89
	        AttributeDescriptor dad=new AttributeDescriptor();
75 90
	        dad.loading();
......
178 193
		return DATASTORE_NAME;
179 194
	}
180 195

  
181
	public void open() throws OpenException {
182
		this.observable.notifyObservers(this,
183
				new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_OPEN)
184
		);
196
	protected void doOpen() throws OpenException {
185 197
		//No hace nada
186
		this.observable.notifyObservers(this,
187
				new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_OPEN)
188
		);
189 198

  
190 199
	}
191 200

  
192
	public void close() throws CloseException {
193
		this.observable.notifyObservers(this,
194
                new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_CLOSE)
195
            );
196
		dbf.close();
197
        this.observable.notifyObservers(this,
198
                new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_CLOSE)
199
            );
201
	protected void doClose() throws CloseException {
202
		try {
203
			dbf.close();
204
		} catch (DataException e) {
205
			throw new CloseException(this.getName(),e);
206
		}
200 207

  
201 208
	}
202 209

  
203
	public void dispose() {
204
		this.observable.notifyObservers(this,
205
                new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_DISPOSE)
206
            );
207
        //No hace nada
208
        this.observable.notifyObservers(this,
209
                new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_DISPOSE)
210
            );
210
	protected void doDispose() throws CloseException {
211
		ResourceManager resMan = ResourceManager.getResourceManager();
212

  
213
    	try {
214
			resMan.remove(this.dbf);
215
		} catch (DataException e1) {
216
			throw new CloseException(this.getName(),e1);
217
		} catch (KeyException e) {
218
			// TODO Auto-generated catch block
219
			throw new CloseException(this.getName(),e);
220
		}
221

  
222
		this.dbf = null;
223
		this.featureType=null;
224
		this.metadata=null;
225

  
211 226
	}
212 227

  
213 228
	public boolean isEditable() {
214
		if (file.canWrite()) return true;
229
		if (dbf.getFile().canWrite()) return true;
215 230
		return false;
216 231
	}
217 232

  
......
255 270
		return writer;
256 271
	}
257 272

  
258
	protected long getFeatureCount(){
273
	protected long getFeatureCount() throws ReadException{
259 274
		return dbf.getRecordCount();
260 275
	}
261 276

  
......
263 278
	public IDataStoreParameters getParameters() {
264 279
		return parameters;
265 280
	}
266
	public DbaseFile getBaseFile(){
267
		return dbf;
268
	}
269 281

  
282

  
270 283
	public IDataExplorer getExplorer() {
271 284
		DataManager dsm=DataManager.getManager();
272 285
		IDataExplorerParameters dsp = dsm.createDataExplorerParameters(

Also available in: Unified diff