Revision 20626

View differences:

trunk/libraries/libFMap_dataFile/src-test/org/gvsig/data/datastores/vectorial/file/shp/SHPTest.java
110 110

  
111 111
		try {
112 112
			store.close();
113
			store.dispose();
113 114
		} catch (CloseException e) {
114 115
			// TODO Auto-generated catch block
115 116
			e.printStackTrace();
116 117
		}
117
		store.dispose();
118

  
118 119
	}
119 120
}
trunk/libraries/libFMap_dataFile/src-test/org/gvsig/data/datastores/vectorial/file/dbf/DBFTest.java
6 6
import junit.framework.TestCase;
7 7

  
8 8
import org.gvsig.data.DataManager;
9
import org.gvsig.data.IDataCollection;
10
import org.gvsig.data.Resource;
11
import org.gvsig.data.ResourceManager;
9 12
import org.gvsig.data.datastores.vectorial.file.DataStoreTest;
10
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore;
11
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStoreParameters;
12 13
import org.gvsig.data.exception.CloseException;
13 14
import org.gvsig.data.exception.InitializeException;
14 15
import org.gvsig.data.exception.OpenException;
15 16
import org.gvsig.data.exception.ReadException;
16
import org.gvsig.data.vectorial.FeatureManager;
17 17
import org.gvsig.data.vectorial.IFeature;
18 18
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
19 19
import org.gvsig.data.vectorial.IFeatureCollection;
20 20
import org.gvsig.data.vectorial.IFeatureType;
21
import org.gvsig.data.vectorial.expansionadapter.MemoryExpansionAdapter;
22 21

  
23 22
import com.iver.cit.gvsig.fmap.drivers.dbf.TestDbf;
24 23

  
......
100 99

  
101 100
		try {
102 101
			store.close();
102
			store.dispose();
103 103
		} catch (CloseException e) {
104 104
			// TODO Auto-generated catch block
105 105
			e.printStackTrace();
106 106
		}
107
		store.dispose();
107

  
108 108
	}
109

  
110
	public void test_Resources(){
111

  
112
		DataManager manager = DataManager.getManager();
113
		Register.selfRegister();
114

  
115
		ResourceManager resMan = ResourceManager.getResourceManager();
116

  
117
		DBFStore store=null;
118
		DBFStore store2=null;
119
		DBFStore store3=null;
120
		DBFStoreParameters dbfParameters;
121

  
122
		dbfParameters=(DBFStoreParameters)manager.createDataStoreParameters(DBFStore.DATASTORE_NAME);
123
		dbfParameters.setFile(file);
124

  
125
		try {
126
			store = (DBFStore)manager.createDataStore(dbfParameters);
127
			store2 = (DBFStore)manager.createDataStore(dbfParameters);
128
			store3 = (DBFStore)manager.createDataStore(dbfParameters);
129
		} catch (InitializeException e) {
130
			e.printStackTrace();fail();
131
		}
132

  
133
		int i=0;
134
		Resource res = null;
135
		Object obj = null;
136

  
137
		Iterator iter = resMan.iterator();
138
		while (iter.hasNext()){
139
			obj = iter.next();
140
			if (obj instanceof DBFResource){
141
				i++;
142
				res = (Resource)obj;
143
			}
144
		}
145

  
146
		assertEquals(1, i);
147

  
148
		assertEquals(3, res.getRefencesCount());
149

  
150
		try {
151
			store.close();
152
		} catch (CloseException e) {
153
			e.printStackTrace();fail();
154
		}
155

  
156
		assertEquals(false, res.isOpen());
157

  
158
		IDataCollection coll = null;
159

  
160
		try {
161
			coll =store.getDataCollection();
162
		} catch (ReadException e) {
163
			e.printStackTrace();fail();
164
		}
165
		assertEquals(true, res.isOpen());
166

  
167
		coll.dispose();
168

  
169
		try {
170
			store3.dispose();
171
		} catch (CloseException e) {
172
			e.printStackTrace();fail();
173
		}
174

  
175
		assertEquals(2, res.getRefencesCount());
176

  
177
		try {
178
			store2.dispose();
179
		} catch (CloseException e) {
180
			e.printStackTrace();fail();
181
		}
182

  
183
		assertEquals(1, res.getRefencesCount());
184

  
185
		try {
186
			store.dispose();
187
		} catch (CloseException e) {
188
			e.printStackTrace();fail();
189
		}
190

  
191
		assertEquals(0, res.getRefencesCount());
192
		res = null;
193

  
194
		i=0;
195
		iter = resMan.iterator();
196
		while (iter.hasNext()){
197
			obj = iter.next();
198
			if (obj instanceof DBFResource){
199
				i++;
200
				res = (Resource)obj;
201
			}
202
		}
203

  
204
		assertEquals(0, i);
205

  
206
	}
109 207
}
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/base/MemoryStore.java
80 80
	public IExtent getFullExtent() {
81 81
		return fullExtent;
82 82
	}
83
	public void close() throws CloseException{
83
	protected void doClose() throws CloseException{
84 84
		arrayFeatures.clear();
85 85
		fullExtent=null;
86 86
	}
87
	public void dispose() throws CloseException{
87
	protected void doDispose() throws CloseException{
88 88
		close();
89 89
	}
90 90
	protected ArrayList getFeatures(){
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dgn/DGNStore.java
79 79
	protected IMetadata metadata;
80 80
	private DGNStoreParameters dgnParameters=null;
81 81
	private File dgnFile;
82
	private DGNReader m_DgnReader;
83 82
	private AttrInTableLabelingStrategy labeling;
84 83
	private VectorialUniqueValueLegend defaultLegend;
85 84

  
......
298 297
		return DATASTORE_NAME;
299 298
	}
300 299

  
301
	public void open() throws OpenException {
302
		this.observable.notifyObservers(this,
303
				new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_OPEN)
304
		);
300
	protected void doOpen() throws OpenException {
305 301
		float heightText = 10;
306 302
//		attr.setLoadedInMemory(true);
307 303
		initializeFeatureType();
304
		DGNReader m_DgnReader;
308 305
		try {
309 306
			m_DgnReader = new DGNReader(dgnFile.getAbsolutePath());
310 307
		} catch (ReadException e) {
......
851 848
//		}
852 849

  
853 850

  
854
		this.observable.notifyObservers(this,
855
				new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_OPEN)
856
		);
857

  
858 851
	}
859 852

  
860
	public void close() throws CloseException {
861
		this.observable.notifyObservers(this,
862
				new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_CLOSE)
863
		);
864
		super.close();
865
		this.observable.notifyObservers(this,
866
				new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_CLOSE)
867
		);
853
	protected void doClose() throws CloseException {
854
		super.doClose();
868 855

  
869 856
	}
870 857

  
871
	public void dispose() throws CloseException {
872
		this.observable.notifyObservers(this,
873
				new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_DISPOSE)
874
		);
858
	protected void doDispose() throws CloseException {
875 859
		close();
876
		this.observable.notifyObservers(this,
877
				new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_DISPOSE)
878
		);
860
		this.metadata=null;
861
		this.featureType=null;
862
		this.defaultLegend=null;
863
		super.doDispose();
864

  
879 865
	}
880 866

  
881 867
	public boolean isEditable() {
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/shp/ShpFeatureCollection.java
17 17

  
18 18
public class ShpFeatureCollection extends DBFFeatureCollection {
19 19

  
20
	public ShpFeatureCollection(FeatureManager fm,SHPStore store,IFeatureType type, String filter) {
20
	public ShpFeatureCollection(FeatureManager fm,SHPStore store,IFeatureType type, String filter) throws ReadException {
21 21
		super(fm,store,type,filter);
22 22
	}
23 23
	public Iterator iterator() {
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/shp/SHPStore.java
231 231
		return DATASTORE_NAME;
232 232
	}
233 233

  
234
	public void open() throws OpenException {
235
		this.observable.notifyObservers(this,
236
				new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_OPEN)
237
		);
238
		super.open();
234
	protected void doOpen() throws OpenException {
235
		super.doOpen();
239 236
//		 create a new header.
240 237
		ShapeFileHeader2 myHeader = new ShapeFileHeader2();
241 238

  
......
278 275
////			throw new FileNotFoundDriverException(getName(),e,strFichDbf);
279 276
//		}
280 277
//		numReg = m_FichDbf.getRecordCount();
281
		this.observable.notifyObservers(this,
282
				new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_OPEN)
283
		);
284 278

  
285 279
	}
286 280

  
287
	public void close() throws CloseException {
288
		this.observable.notifyObservers(this,
289
                new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_CLOSE)
290
            );
291
		super.close();
281
	protected void doClose() throws CloseException {
282
		super.doClose();
292 283
		CloseException ret = null;
293 284

  
294 285
		try {
......
299 290
		} finally {
300 291
			try {
301 292
				fin.close();
293
				finShx.close();
302 294
			} catch (IOException e1) {
303 295
				ret = new CloseException(getName(),e1);
304 296
			}
......
309 301
//		}
310 302
		bb = null;
311 303
		bbShx = null;
312
        this.observable.notifyObservers(this,
313
                new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_CLOSE)
314
            );
315 304

  
316 305
	}
317 306

  
318
	public void dispose() {
319
		this.observable.notifyObservers(this,
320
                new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_DISPOSE)
321
            );
322
		super.dispose();
323
        this.observable.notifyObservers(this,
324
                new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_DISPOSE)
325
            );
307
	protected void doDispose() throws CloseException {
308
		super.doDispose();
326 309
	}
327 310

  
328 311
	public boolean isEditable() {
......
369 352
//		writer.init(this);
370 353
		return writer;
371 354
	}
372
	protected long getFeatureCount(){
355
	protected long getFeatureCount() throws ReadException{
373 356
		return dbf.getRecordCount();
374 357
	}
375 358

  
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dbf/DBFFeatureCollection.java
28 28
	protected long driverFeatureCount=0;
29 29
	protected long size=-1;
30 30

  
31
	public DBFFeatureCollection(FeatureManager fm,DBFStore store,IFeatureType type, String filter) {
31
	public DBFFeatureCollection(FeatureManager fm,DBFStore store,IFeatureType type, String filter) throws ReadException {
32 32
		this.featureManager=fm;
33 33
		this.store=store;
34 34
		driverFeatureCount=store.getFeatureCount();
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dbf/DBFResource.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   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.data.datastores.vectorial.file.dbf;
32

  
33
import java.io.File;
34
import java.nio.channels.FileChannel;
35
import java.util.Date;
36

  
37
import org.gvsig.data.Resource;
38
import org.gvsig.data.datastores.vectorial.file.IFileResource;
39
import org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile;
40
import org.gvsig.data.exception.CloseException;
41
import org.gvsig.data.exception.DataException;
42
import org.gvsig.data.exception.OpenException;
43
import org.gvsig.data.exception.ReadException;
44
import org.gvsig.data.exception.UnsupportedEncodingException;
45
import org.gvsig.data.exception.WriteException;
46

  
47

  
48
/**
49
 * @author jmvivo
50
 *
51
 */
52
public class DBFResource extends Resource implements IFileResource {
53

  
54
	protected DbaseFile dbfFile;
55
	protected File file;
56
	private boolean isOpen;
57
	private long fileLastModified = 0L;
58

  
59
	DBFResource (File aFile){
60
		this.file = aFile;
61
	}
62

  
63
	DbaseFile getDbf(){
64
		return this.dbfFile;
65
	}
66

  
67
	/* (non-Javadoc)
68
	 * @see org.gvsig.data.Resource#getKey()
69
	 */
70
	public String getKey() {
71
		return "DBF:"+this.file.getAbsolutePath();
72
	}
73

  
74
	/* (non-Javadoc)
75
	 * @see org.gvsig.data.datastores.vectorial.file.IFileResource#getFile()
76
	 */
77
	public File getFile() {
78
		return this.file;
79
	}
80

  
81
	/* (non-Javadoc)
82
	 * @see org.gvsig.data.Resource#description()
83
	 */
84

  
85
	public String description() {
86
		if (this.getFile()!= null){
87
			return "DBF File resource: " + this.getFile().getAbsolutePath();
88
		} else{
89
			return "DBF File resource: {No file}";
90
		}
91
	}
92

  
93
	/* (non-Javadoc)
94
	 * @see org.gvsig.data.Resource#doClose()
95
	 */
96
	protected boolean doClose() throws CloseException{
97
		dbfFile.close();
98
		isOpen = false;
99
		return true;
100
	}
101

  
102
	/* (non-Javadoc)
103
	 * @see org.gvsig.data.Resource#doDispose()
104
	 */
105
	protected void doDispose() throws DataException{
106
		this.dbfFile = null;
107
		this.file = null;
108

  
109
	}
110

  
111
	/* (non-Javadoc)
112
	 * @see org.gvsig.data.Resource#doOpen()
113
	 */
114
	protected boolean doOpen() throws OpenException{
115
		if (this.dbfFile == null){
116
			this.dbfFile = new DbaseFile(this.file);
117
			this.fileLastModified = this.file.lastModified();
118
		} else{
119
			if (this.fileLastModified < this.file.lastModified()) {
120
				this.changed();
121
			}
122
		}
123
		this.dbfFile.open();
124
		this.isOpen=true;
125
		return true;
126

  
127
	}
128

  
129
	/* (non-Javadoc)
130
	 * @see org.gvsig.data.Resource#isOpen()
131
	 */
132
	public boolean isOpen() {
133
		return this.isOpen;
134
	}
135

  
136
	private void checkOpen() throws OpenException{
137
		if (!this.isOpen){
138
			this.open();
139
		}
140

  
141
	}
142

  
143
	/**
144
	 * @param rowIndex
145
	 * @param fieldId
146
	 * @return
147
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getBooleanFieldValue(int, int)
148
	 */
149
	public boolean getBooleanFieldValue(int rowIndex, int fieldId)  throws ReadException{
150
		this.checkOpen();
151
		return dbfFile.getBooleanFieldValue(rowIndex, fieldId);
152
	}
153

  
154
	/**
155
	 * @return
156
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldCount()
157
	 */
158
	public int getFieldCount() throws ReadException {
159
		this.checkOpen();
160
		return dbfFile.getFieldCount();
161
	}
162

  
163
	/**
164
	 * @param inIndex
165
	 * @return
166
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldDecimalLength(int)
167
	 */
168
	public int getFieldDecimalLength(int inIndex) throws ReadException {
169
		this.checkOpen();
170
		return dbfFile.getFieldDecimalLength(inIndex);
171
	}
172

  
173
	/**
174
	 * @param inIndex
175
	 * @return
176
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldLength(int)
177
	 */
178
	public int getFieldLength(int inIndex)  throws ReadException{
179
		this.checkOpen();
180
		return dbfFile.getFieldLength(inIndex);
181
	}
182

  
183
	/**
184
	 * @param inIndex
185
	 * @return
186
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldName(int)
187
	 */
188
	public String getFieldName(int inIndex)  throws ReadException{
189
		this.checkOpen();
190
		return dbfFile.getFieldName(inIndex);
191
	}
192

  
193
	/**
194
	 * @param inIndex
195
	 * @return
196
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldType(int)
197
	 */
198
	public char getFieldType(int inIndex)  throws ReadException{
199
		this.checkOpen();
200
		return dbfFile.getFieldType(inIndex);
201
	}
202

  
203
	/**
204
	 * @return
205
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getRecordCount()
206
	 */
207
	public int getRecordCount()  throws ReadException{
208
		this.checkOpen();
209
		return dbfFile.getRecordCount();
210
	}
211

  
212
	/**
213
	 * @param rowIndex
214
	 * @param fieldId
215
	 * @return
216
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getStringFieldValue(int, int)
217
	 */
218
	public String getStringFieldValue(int rowIndex, int fieldId)  throws ReadException{
219
		this.checkOpen();
220
		return dbfFile.getStringFieldValue(rowIndex, fieldId);
221
	}
222

  
223
	/**
224
	 * @return
225
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getWriteChannel()
226
	 */
227
	public FileChannel getWriteChannel()  throws DataException{
228
		this.checkOpen();
229
		return dbfFile.getWriteChannel();
230
	}
231

  
232
	/**
233
	 * @param rowIndex
234
	 * @param fieldId
235
	 * @param obj
236
	 * @throws UnsupportedEncodingException
237
	 * @throws WriteException
238
	 * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#setFieldValue(int, int, java.lang.Object)
239
	 */
240
	public void setFieldValue(int rowIndex, int fieldId, Object obj) throws UnsupportedEncodingException, WriteException{
241
//		FIXME: this.checkOpen();?????
242
		dbfFile.setFieldValue(rowIndex, fieldId, obj);
243
	}
244

  
245
	/* (non-Javadoc)
246
	 * @see org.gvsig.data.Resource#doChanged()
247
	 */
248
	protected void doChanged() {
249
		this.fileLastModified = this.file.lastModified();
250

  
251
	}
252

  
253

  
254
}
255

  
0 256

  
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dbf/DBFFeature.java
63 63

  
64 64
	protected void loadValue(IFeatureAttributeDescriptor descriptor)  throws ReadException, IsNotFeatureSettingException{
65 65
		int i=((AttributeDescriptor)descriptor).originalPosition();
66
		if (store.dbf.getFieldCount()<=i)
67
			return;
68
		String value=store.dbf.getStringFieldValue((int) this.featureIndex, i);
66
		String value = null;
67
		try{
68
			if (store.dbf.getFieldCount()<=i)
69
				return;
70
			value=store.dbf.getStringFieldValue((int) this.featureIndex, i);
71
		} catch (DataException e){
72
			throw new ReadException(this.store.getName(),e);
73
		}
69 74
		value=value.trim();
70 75
		String fieldType=descriptor.getDataType();
71 76
		if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_STRING)){
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dbf/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(
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dbf/utils/DbaseFile.java
36 36
	// Header information for the DBase File
37 37
	private DbaseFileHeader myHeader;
38 38

  
39
	private File file;
40

  
39 41
	private RandomAccessFile raf;
40 42

  
41 43
	private FileChannel channel;
......
62 64

  
63 65
	private Charset chars;
64 66

  
67

  
65 68
	/** Utility for formatting Dbase fields. */
66 69
	public static class FieldFormatter {
67 70
		private StringBuffer buffer = new StringBuffer(255);
......
168 171
		}
169 172
	}
170 173

  
174
	public DbaseFile(File afile){
175
		this.file= afile;
176
	}
177

  
171 178
	// Retrieve number of records in the DbaseFile
172 179
	public int getRecordCount() {
173 180
		return myHeader.getNumRecords();
......
357 364
	 * @throws IOException
358 365
	 *             DOCUMENT ME!
359 366
	 */
360
	public void open(File file) throws FileNotFoundException, UnsupportedVersionException {
367
	public void open() throws FileNotFoundException, UnsupportedVersionException {
361 368
		/*
362 369
		 * 01h DOS USA code page 437 02h DOS Multilingual code page 850 03h
363 370
		 * Windows ANSI code page 1252 04h Standard Macintosh 64h EE MS-DOS code
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/IFileResource.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   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.data.datastores.vectorial.file;
32

  
33
import java.io.File;
34

  
35
/**
36
 * @author jmvivo
37
 *
38
 */
39
public interface IFileResource {
40
	public File getFile();
41
}
42

  
0 43

  
trunk/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/dxf/DXFStore.java
90 90
	protected final static int ID_FIELD_HEIGHTTEXT = 8;
91 91

  
92 92
	protected final static int ID_FIELD_ROTATIONTEXT = 9;
93
	private DriverAttributes attr = new DriverAttributes();
94
	private DxfFile.EntityFactory featureMaker;
95
	private DxfFile.VarSettings headerManager;
96 93
	private DxfFile dxfFeatureFile;
97
	private IObjList.vector features;
98 94
	private AttrInTableLabelingStrategy labeling;
99 95

  
100 96
	private VectorialUniqueValueLegend defaultLegend;
......
334 330
		return DATASTORE_NAME;
335 331
	}
336 332

  
337
	public void open() throws OpenException {
338
		this.observable.notifyObservers(this,
339
				new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_OPEN)
340
		);
333
	protected void doOpen() throws OpenException {
341 334
		float heightText = 10;
342 335

  
343
		attr.setLoadedInMemory(true);
344 336

  
345

  
346
		featureMaker = new DxfFeatureMaker(projection);
347
		headerManager = new DxfHeaderManager();
337
		DxfFile.EntityFactory featureMaker = new DxfFeatureMaker(projection);
338
		DxfFile.VarSettings headerManager = new DxfHeaderManager();
348 339
		dxfFeatureFile = new DxfFile(projection, dxfFile.getAbsolutePath(),
349 340
				featureMaker, headerManager);
350 341
		try {
......
352 343
		} catch (Exception e1) {
353 344
			throw new OpenException(getName(),e1);
354 345
		}
355
		features = (IObjList.vector) ((DxfFeatureMaker) featureMaker)
346
		IObjList.vector features = (IObjList.vector) ((DxfFeatureMaker) featureMaker)
356 347
				.getObjects();
357 348
		String acadVersion = (String) ((DxfHeaderManager) headerManager)
358 349
				.getAcadVersion();
......
940 931
//			} // for
941 932

  
942 933

  
943
		this.observable.notifyObservers(this,
944
				new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_OPEN)
945
		);
946

  
947 934
	}
948 935

  
949
	public void close() throws CloseException {
950
		this.observable.notifyObservers(this,
951
                new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_CLOSE)
952
            );
953
		super.close();
954
		features.clear();
955
        this.observable.notifyObservers(this,
956
                new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_CLOSE)
957
            );
958

  
936
	protected void doClose() throws CloseException {
937
		super.doClose();
959 938
	}
960 939

  
961
	public void dispose() throws CloseException {
962
		this.observable.notifyObservers(this,
963
                new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_DISPOSE)
964
            );
940
	protected void doDispose() throws CloseException {
965 941
		close();
966
        this.observable.notifyObservers(this,
967
                new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_DISPOSE)
968
            );
942
		super.doDispose();
969 943
	}
970 944

  
971 945
	public boolean isEditable() {

Also available in: Unified diff