Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dbf / DBFStoreProvider.java @ 28076

History | View | Annotate | Download (19.9 KB)

1
package org.gvsig.fmap.dal.store.dbf;
2

    
3
import java.io.File;
4
import java.io.IOException;
5
import java.text.DateFormat;
6
import java.text.ParseException;
7
import java.util.ArrayList;
8
import java.util.Arrays;
9
import java.util.Date;
10
import java.util.Iterator;
11
import java.util.List;
12
import java.util.Locale;
13

    
14
import org.gvsig.fmap.dal.DALLocator;
15
import org.gvsig.fmap.dal.DataManager;
16
import org.gvsig.fmap.dal.DataServerExplorer;
17
import org.gvsig.fmap.dal.DataStoreNotification;
18
import org.gvsig.fmap.dal.DataTypes;
19
import org.gvsig.fmap.dal.exception.CloseException;
20
import org.gvsig.fmap.dal.exception.DataException;
21
import org.gvsig.fmap.dal.exception.FileNotFoundException;
22
import org.gvsig.fmap.dal.exception.InitializeException;
23
import org.gvsig.fmap.dal.exception.OpenException;
24
import org.gvsig.fmap.dal.exception.ReadException;
25
import org.gvsig.fmap.dal.exception.UnsupportedVersionException;
26
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
27
import org.gvsig.fmap.dal.feature.DisposableIterator;
28
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
29
import org.gvsig.fmap.dal.feature.EditableFeatureType;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
32
import org.gvsig.fmap.dal.feature.FeatureQuery;
33
import org.gvsig.fmap.dal.feature.FeatureSet;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.dal.feature.FeatureType;
36
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
37
import org.gvsig.fmap.dal.feature.exception.UnknownDataTypeException;
38
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
39
import org.gvsig.fmap.dal.feature.spi.FeatureData;
40
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
41
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
42
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
43
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
44
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
45
import org.gvsig.fmap.dal.resource.exception.ResourceBeginException;
46
import org.gvsig.fmap.dal.resource.exception.ResourceException;
47
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyChangesException;
48
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyCloseException;
49
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException;
50
import org.gvsig.fmap.dal.resource.file.FileResource;
51
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
52
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
53
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
54
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
55
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile;
56
import org.gvsig.tools.ToolsLocator;
57
import org.gvsig.tools.dynobject.DelegatedDynObject;
58
import org.gvsig.tools.dynobject.DynClass;
59
import org.gvsig.tools.dynobject.DynField;
60
import org.gvsig.tools.dynobject.DynObject;
61
import org.gvsig.tools.dynobject.DynObjectManager;
62
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
63
import org.gvsig.tools.exception.BaseException;
64
import org.gvsig.tools.persistence.PersistenceException;
65
import org.gvsig.tools.persistence.PersistentState;
66

    
67
public class DBFStoreProvider extends AbstractFeatureStoreProvider implements
68
                ResourceConsumer {
69

    
70
        public static String NAME = "DBFStore";
71
        public static String DESCRIPTION = "DBF file";
72
        //        private DBFResource dbf = null;
73
        private DbaseFile dbfFile = null;
74
        private ResourceProvider dbfResource;
75
        private static final Locale ukLocale = new Locale("en", "UK");
76
        private static final String DYNCLASS_NAME = "DBFStore";
77
        protected static DynClass DYNCLASS = null;
78
        private DBFStoreParameters dbfParams;
79
        private long counterNewsOIDs = -1;
80
        private DBFFeatureWriter writer;
81

    
82
        public DBFStoreProvider() throws InitializeException {
83
                super();
84
                writer = new DBFFeatureWriter(this.getName());
85
        }
86

    
87
        public DBFStoreProvider(DBFStoreParameters params)
88
                        throws InitializeException {
89
                super();
90
                this.init(params);
91
                writer = new DBFFeatureWriter(this.getName());
92
        }
93

    
94

    
95
        protected void init(DBFStoreParameters params) throws InitializeException {
96
                this.dbfParams = params;
97
                this.dynObject = (DelegatedDynObject) ToolsLocator
98
                                .getDynObjectManager().createDynObject(
99
                                DYNCLASS);
100

    
101
                this.dynObject.setDynValue("DefaultSRS", null);
102
                this.dynObject.setDynValue("Envelope", null);
103

    
104
                File theFile = getDBFParameters().getDBFFile();
105
                dbfResource = this.createResource(FileResource.NAME,
106
                                new Object[] { theFile.getAbsolutePath() });
107
                dbfResource.addConsumer(this);
108

    
109
                this.dbfFile = new DbaseFile(theFile);
110

    
111
        }
112

    
113
        public FeatureStoreProvider initialize(FeatureStoreProviderServices store)
114
                        throws InitializeException {
115
                super.initialize(store);
116
                this.initFeatureType();
117
                return this;
118
        }
119

    
120
        public String getName() {
121
                return NAME;
122
        }
123

    
124
        protected DBFStoreParameters getDBFParameters() {
125
                return dbfParams;
126
        }
127

    
128

    
129
        public DataServerExplorer getExplorer() throws ReadException {
130
                DataManager manager = DALLocator.getDataManager();
131
                FilesystemServerExplorerParameters params;
132
                try {
133
                        params = (FilesystemServerExplorerParameters) manager
134
                                        .createServerExplorerParameters(FilesystemServerExplorer.NAME);
135
                        params.setRoot(this.getDBFParameters().getDBFFile().getParent());
136
                        return manager.createServerExplorer(params);
137
                } catch (DataException e) {
138
                        throw new ReadException(this.getName(), e);
139
                } catch (ValidateDataParametersException e) {
140
                        // TODO Auto-generated catch block
141
                        throw new ReadException(this.getName(), e);
142
                }
143
        }
144

    
145
        public FeatureData getFeatureDataByReference(
146
                        FeatureReferenceProviderServices reference, FeatureType featureType)
147
                        throws DataException {
148

    
149
                return this.getFeatureDataByIndex(((Long) reference.getOID())
150
                                .longValue(),
151
                                featureType);
152
        }
153

    
154

    
155
        public FeatureData getFeatureDataByReference(
156
                        FeatureReferenceProviderServices reference) throws DataException {
157
                return this.getFeatureDataByReference(reference, this.store
158
                                .getDefaultFeatureType());
159
        }
160

    
161
        public void performEditing(Iterator deleteds, Iterator inserteds,
162
                        Iterator updateds)
163
                        throws PerformEditingException {
164

    
165
                try {
166
                        this.resourcesBegin();
167
                        FeatureSet set = this.store.getFeatureSet();
168
                        DBFStoreParameters tmpParams = (DBFStoreParameters) this
169
                                        .getDBFParameters().getCopy();
170

    
171
                        tmpParams.setDBFFileName(tmpParams.getDBFFileName() + ".tmp");
172

    
173
                        writer.begin(tmpParams, this.store
174
                                        .getDefaultFeatureType(), set.getSize());
175

    
176
                        DisposableIterator iter = set.fastIterator();
177
                        while (iter.hasNext()) {
178
                                Feature feature=(Feature) iter.next();
179
                                writer.append(feature);
180
                        }
181
                        iter.dispose();
182

    
183

    
184
                        writer.end();
185

    
186
                        try {
187
                                this.close();
188
                        } catch (CloseException e1) {
189
                                throw new PerformEditingException(this.getName(), e1);
190
                        }
191
                        this.getDBFParameters().getDBFFile().delete();
192
                        tmpParams.getDBFFile().renameTo(
193
                                        this.getDBFParameters().getDBFFile());
194

    
195
                        this.resourcesNotifyChanges();
196
                        this.initFeatureType();
197
                } catch (Exception e) {
198
                        throw new PerformEditingException(this.getName(), e);
199
                } finally {
200
                        this.resourcesEnd();
201
                }
202

    
203
                this.counterNewsOIDs = -1;
204
        }
205

    
206
        /*
207
         * ==================================================
208
         */
209

    
210
        public FeatureData createFeatureData(FeatureType type) throws DataException {
211
                return new DBFFeatureData(this, type);
212
        }
213

    
214

    
215
        /*
216
         * ===================================================
217
         */
218

    
219
        FeatureStoreProviderServices getProviderServices() {
220
                return this.store;
221
        }
222

    
223

    
224
        protected void initFeatureType() throws InitializeException {
225
                FeatureType defaultType = this.getTheFeatureType().getNotEditableCopy();
226
                List types = new ArrayList(1);
227
                types.add(defaultType);
228
                this.store.setFeatureTypes(types, defaultType);
229
        }
230

    
231
        protected EditableFeatureType getTheFeatureType() throws InitializeException {
232
                try {
233
                        this.open();
234
                        this.resourcesBegin();
235
                } catch (DataException e) {
236
                        throw new InitializeException(this.getName(), e);
237
                }
238
                try {
239
                        int fieldCount = -1;
240
                        fieldCount = dbfFile.getFieldCount();
241

    
242
                        EditableFeatureType fType = this.store.createFeatureType();
243

    
244
                        fType.setHasOID(true);
245
                        int precision;
246
                        for (int i = 0; i < fieldCount; i++) {
247
                                char fieldType = dbfFile.getFieldType(i);
248
                                EditableFeatureAttributeDescriptor attr;
249

    
250
                                if (fieldType == 'L') {
251
                                        attr = fType
252
                                                        .add(dbfFile.getFieldName(i), DataTypes.BOOLEAN);
253
                                        attr.setDefaultValue(new Boolean(false));
254
                                        attr.setAllowNull(false);
255

    
256
                                } else if ((fieldType == 'F') || (fieldType == 'N')) {
257
                                        precision = dbfFile.getFieldDecimalLength(i);
258
                                        if (precision > 0) {
259
                                                attr = fType.add(dbfFile.getFieldName(i),
260
                                                                DataTypes.DOUBLE, dbfFile.getFieldLength(i));
261
                                                attr.setPrecision(precision);
262
                                                attr.setDefaultValue(new Double(0));
263

    
264
                                        } else {
265
                                                attr = fType
266
                                                                .add(dbfFile.getFieldName(i), DataTypes.INT);
267
                                                attr.setDefaultValue(new Integer(0));
268
                                        }
269
                                        attr.setAllowNull(false);
270

    
271
                                } else if (fieldType == 'C') {
272
                                        attr = fType.add(dbfFile.getFieldName(i), DataTypes.STRING);
273
                                        attr.setSize(dbfFile.getFieldLength(i));
274
                                        attr.setDefaultValue("");
275
                                        attr.setAllowNull(false);
276

    
277
                                } else if (fieldType == 'D') {
278
                                        attr = fType.add(dbfFile.getFieldName(i), DataTypes.DATE);
279
                                        attr.setDefaultValue(null);
280
                                        attr.setAllowNull(true);
281
                                } else {
282
                                        throw new InitializeException(this.getName(),
283
                                                        new UnknownDataTypeException(
284
                                                                        dbfFile.getFieldName(i), "" + fieldType,
285
                                                                        this.getName()));
286
                                }
287
                        }
288
                        return fType;
289
                } finally {
290
                        this.resourcesEnd();
291
                }
292
        }
293

    
294

    
295
        protected void loadValue(FeatureData featureData, int rowIndex,
296
                        FeatureAttributeDescriptor descriptor) throws ReadException {
297
                if (descriptor.getEvaluator() != null) {
298
                        // Nothing to do
299
                        return;
300
                }
301

    
302

    
303
                int dbfIndex = this.dbfFile.getFieldIndex(descriptor.getName());
304
                String value = null;
305
                try {
306
                        value = this.dbfFile.getStringFieldValue(rowIndex, dbfIndex);
307
                } catch (DataException e) {
308
                        throw new ReadException(this.store.getName(), e);
309
                }
310
                value = value.trim();
311
                int fieldType = descriptor.getDataType();
312
                switch (fieldType) {
313
                case DataTypes.STRING:
314
                        featureData.set(descriptor.getIndex(), value);
315
                        break;
316

    
317
                case DataTypes.DOUBLE:
318
                        try {
319
                                featureData.set(descriptor.getIndex(), new Double(value));
320
                        } catch (NumberFormatException e) {
321
                                featureData.set(descriptor.getIndex(), null);
322
                        }
323
                        break;
324

    
325
                case DataTypes.INT:
326
                        try {
327
                                featureData.set(descriptor.getIndex(), new Integer(value));
328
                        } catch (NumberFormatException e) {
329
                                featureData.set(descriptor.getIndex(), null);
330
                        }
331
                        break;
332

    
333
                case DataTypes.FLOAT:
334
                        try {
335
                                featureData.set(descriptor.getIndex(), new Float(value));
336
                        } catch (NumberFormatException e) {
337
                                featureData.set(descriptor.getIndex(), null);
338
                        }
339
                        break;
340

    
341
                case DataTypes.LONG:
342
                        try {
343
                                featureData.set(descriptor.getIndex(), new Long(value));
344
                        } catch (NumberFormatException e) {
345
                                featureData.set(descriptor.getIndex(), null);
346
                        }
347
                        break;
348

    
349
                case DataTypes.BOOLEAN:
350
                        featureData.set(descriptor.getIndex(), new Boolean(value));
351
                        break;
352

    
353
                case DataTypes.BYTE:
354
                        try {
355
                                featureData.set(descriptor.getIndex(), new Byte(value));
356
                        } catch (NumberFormatException e) {
357
                                featureData.set(descriptor.getIndex(), null);
358
                        }
359
                        break;
360

    
361
                case DataTypes.DATE:
362
                        if (value.equals("")){
363
                                value=null;
364
                                return;
365
                        }
366
                        String year = value.substring(0, 4);
367
                        String month = value.substring(4, 6);
368
                        String day = value.substring(6, 8);
369
                        DateFormat df;
370
                        if (descriptor.getDateFormat() == null){
371
                                df = DateFormat.getDateInstance(DateFormat.SHORT,
372
                                                ukLocale);
373
                        } else{
374
                                df = descriptor.getDateFormat();
375
                        }
376
                        /*
377
                         * Calendar c = Calendar.getInstance(); c.clear();
378
                         * c.set(Integer.parseInt(year), Integer.parseInt(month),
379
                         * Integer.parseInt(day)); c.set(Calendar.MILLISECOND, 0);
380
                         */
381
                        String strAux = month + "/" + day + "/" + year;
382
                        Date dat = null;
383
                        try {
384
                                dat = df.parse(strAux);
385
                        } catch (ParseException e) {
386
                                throw new ReadException(this.store.getName(), e);
387
                        }
388
                        featureData.set(descriptor.getIndex(), dat);
389
                        break;
390

    
391

    
392
                default:
393
                        featureData
394
                                        .set(descriptor.getIndex(), descriptor.getDefaultValue());
395
                        break;
396
                }
397
        }
398

    
399

    
400
        /***
401
         * NOT supported in Alter Mode
402
         *
403
         * @param index
404
         * @return
405
         * @throws ReadException
406
         */
407
        protected FeatureData getFeatureDataByIndex(long index) throws DataException {
408
                return this
409
                                .getFeatureDataByIndex(index, this.store
410
                                .getDefaultFeatureType());
411
        }
412

    
413
        public long getFeatureCount() throws ReadException, OpenException,
414
                        ResourceNotifyChangesException {
415
                this.open();
416
                try {
417
                        this.resourcesBegin();
418
                } catch (ResourceBeginException e) {
419
                        throw new ReadException(this.getName(), e);
420
                }
421
                try {
422
                        return this.dbfFile.getRecordCount();
423
                } finally {
424
                        this.resourcesEnd();
425
                }
426
        }
427

    
428
        public FeatureSetProvider createSet(FeatureQuery query, FeatureType featureType)
429
                        throws DataException {
430
                return new DBFSetProvider(this, query, featureType);
431
        }
432

    
433
        public boolean canCreate() {
434
                return true;
435
        }
436

    
437
        public boolean canWriteGeometry(int geometryType) throws DataException {
438
                return false;
439
        }
440

    
441
        public void open() throws OpenException {
442
                if (this.dbfFile.isOpen()) {
443
                        return;
444
                }
445
                try {
446
                        this.resourcesBegin();
447
                } catch (ResourceBeginException e) {
448
                        throw new OpenException(this.getName(), e);
449
                }
450
                try {
451
                        this.openFile();
452
                        this.resourcesOpen();
453

    
454
                        // Load metadata values
455
                        this.loadMetadataValues();
456

    
457
                } catch (UnsupportedVersionException e) {
458
                        throw new OpenException(this.getName(), e);
459
                } catch (ResourceNotifyOpenException e) {
460
                        throw new OpenException(this.getName(), e);
461
                } catch (FileNotFoundException e) {
462
                        throw new OpenException(this.getName(), e);
463
                } catch (IOException e) {
464
                        throw new OpenException(this.getName(), e);
465
                } catch (BaseException e) {
466
                        throw new OpenException(this.getName(), e);
467
                } finally {
468
                        this.resourcesEnd();
469
                }
470
        }
471

    
472
        protected void openFile() throws FileNotFoundException,
473
                        UnsupportedVersionException, IOException, DataException {
474
                this.dbfFile.open();
475
        }
476

    
477
        protected void loadMetadataValues() throws DynFieldNotFoundException,
478
                        ReadException {
479
                this.dynObject.setDynValue(DBFLibrary.DYNFIELD_CODEPAGE_NAME, new Byte(
480
                                this.dbfFile.getCodePage()));
481

    
482
        }
483

    
484
        public void close() throws CloseException {
485
                if (!this.dbfFile.isOpen()) {
486
                        return;
487
                }
488
                super.close();
489
                //Cerrar recurso
490
                try {
491
                        this.resourcesBegin();
492
                } catch (ResourceBeginException e) {
493
                        throw new CloseException(this.getName(), e);
494
                }
495
                try {
496
                        this.closeFile();
497
                        this.resourcesNotifyClose();
498

    
499
                } catch (ResourceNotifyCloseException e) {
500
                        throw new CloseException(this.getName(), e);
501
                } finally {
502
                        this.resourcesEnd();
503
                }
504
        }
505

    
506
        protected void closeFile() throws CloseException {
507
                this.dbfFile.close();
508
        }
509

    
510
        public void dispose() throws CloseException {
511
                this.close();
512
                dbfFile = null;
513
                this.dbfResource.removeConsumer(this);
514
                dbfResource = null;
515
                super.dispose();
516
        }
517

    
518
        public boolean closeResourceRequested(ResourceProvider resource) {
519
                try {
520
                        this.close();
521
                } catch (CloseException e) {
522
                        return false;
523
                }
524
                return true;
525
        }
526

    
527
        public boolean allowWrite() {
528
                File file;
529
                try {
530
                        file = new File((String) this.dbfResource.get());
531
                } catch (AccessResourceException e) {
532
                        return false;
533
                }
534
                return file.canWrite();
535
        }
536

    
537
        public void refresh() throws OpenException {
538
                try {
539
                        this.close();
540
                } catch (CloseException e) {
541
                        throw new OpenException(this.getName(), e);
542
                }
543
                this.open();
544
                try {
545
                        this.initFeatureType();
546
                } catch (InitializeException e) {
547
                        throw new OpenException(this.getName(), e);
548
                }
549
        }
550

    
551
        /**
552
         *
553
         * @param index
554
         * @param featureType
555
         * @return
556
         * @throws ReadException
557
         */
558
        protected FeatureData getFeatureDataByIndex(long index,
559
                        FeatureType featureType) throws DataException {
560
                FeatureData featureData = this.createFeatureData(featureType);
561
                featureData.setOID(new Long(index));
562
                return featureData;
563
        }
564

    
565
        protected void initFeatureDataByIndex(FeatureData featureData,
566
                        long index, FeatureType featureType) throws DataException {
567
                featureData.setOID(new Long(index));
568
        }
569

    
570
        /**
571
         *
572
         * @param featureData
573
         * @throws DataException
574
         */
575
        protected void loadFeatureDataByIndex(FeatureData featureData)
576
                        throws DataException {
577
                this.open();
578
                this.resourcesBegin();
579
                long index = ((Long) featureData.getOID()).longValue();
580
                try {
581
                        if (index >= this.dbfFile.getRecordCount()) {
582
                                // FIXME
583
                                throw new ArrayIndexOutOfBoundsException("" + index);
584
                        }
585
                        Iterator iterator = featureData.getType().iterator();
586
                        while (iterator.hasNext()) {
587
                                FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator
588
                                                .next();
589
                                this.loadValue(featureData, (int) index, descriptor);
590
                        }
591

    
592

    
593
                } finally {
594
                        this.resourcesEnd();
595
                }
596
        }
597

    
598
        public int getFeatureReferenceOIDType() {
599
                return DataTypes.LONG;
600
        }
601

    
602
        public Object createNewOID() {
603
                if (this.counterNewsOIDs < 0) {
604
                        try {
605
                                this.counterNewsOIDs = this.getFeatureCount();
606
                        } catch (DataException e) {
607
                                e.printStackTrace();
608
                        }
609

    
610
                }else{
611
                        this.counterNewsOIDs++;
612
                }
613
                return new Long(counterNewsOIDs);
614
        }
615

    
616
        public boolean supportsAppendMode() {
617
                return true;
618
        }
619

    
620

    
621
        public void append(Feature feature) throws DataException {
622
                this.resourcesBegin();
623
                try {
624
                        writer.append(feature);
625
                } finally {
626
                        this.resourcesEnd();
627
                }
628
        }
629

    
630
        public void beginAppend() throws DataException {
631
                this.close();
632
                this.resourcesBegin();
633
                try {
634
                        FeatureSet set = this.store.getFeatureSet();
635
                        writer.begin(this.getDBFParameters(), this.store
636
                                        .getDefaultFeatureType(), set.getSize());
637
                } finally {
638
                        this.resourcesEnd();
639
                }
640
        }
641

    
642
        public void endAppend() throws DataException {
643
                this.resourcesBegin();
644
                try {
645
                        writer.end();
646

    
647
                        this.resourcesNotifyChanges();
648
                        this.counterNewsOIDs = -1;
649
                } finally {
650
                        this.resourcesEnd();
651
                }
652
        }
653

    
654
        public PersistentState getState() throws PersistenceException {
655
                // Nothing to do
656
                return null;
657
        }
658

    
659
        public void saveToState(PersistentState state) throws PersistenceException {
660
                try {
661
                        this.init((DBFStoreParameters) this.store.getParameters());
662
                } catch (InitializeException e) {
663
                        throw new PersistenceException(e);
664
                }
665
        }
666

    
667
        public void setState(PersistentState state) throws PersistenceException {
668
                try {
669
                        this.init((DBFStoreParameters) this.store.getParameters());
670
                } catch (InitializeException e) {
671
                        throw new PersistenceException(e);
672
                }
673
        }
674

    
675
        public Iterator getChilds() {
676
                return Arrays.asList(new DynObject[] { this.dbfParams }).iterator();
677

    
678
        }
679

    
680
        protected static void registerDynClass() {
681
                DynObjectManager dynman = ToolsLocator.getDynObjectManager();
682
                DynClass dynClass;
683
                DynField field;
684
                if (DYNCLASS == null) {
685
                        dynClass = dynman.add(DYNCLASS_NAME,
686
                                        "DBF File Store");
687
                        field = DBFLibrary.addCodePageField(dynClass);
688

    
689
                        dynClass.extend(dynman.get(FeatureStore.DYNCLASS_NAME));
690

    
691
                        DYNCLASS = dynClass;
692
                }
693

    
694
        }
695

    
696
        public Object getDynValue(String name) throws DynFieldNotFoundException {
697
                try {
698
                        this.open();
699
                } catch (OpenException e) {
700
                        // FIXME
701
                        throw new RuntimeException(e);
702
                }
703
                return super.getDynValue(name);
704
        }
705

    
706

    
707
        /*
708
         * (non-Javadoc)
709
         *
710
         * @see
711
         * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
712
         * gvsig.fmap.dal.resource.spi.ResourceProvider)
713
         */
714
        public void resourceChanged(ResourceProvider resource) {
715
                this.store.notifyChange(DataStoreNotification.RESOURCE_CHANGED,
716
                                resource);
717
        }
718

    
719
        protected void resourcesBegin() throws ResourceBeginException {
720
                this.dbfResource.begin();
721
        }
722

    
723
        protected void resourcesEnd() {
724
                this.dbfResource.end();
725
        }
726

    
727
        /**
728
         *
729
         * @throws ResourceNotifyChangesException
730
         */
731
        protected void resourcesNotifyChanges()
732
                        throws ResourceNotifyChangesException {
733
                this.dbfResource.notifyChanges();
734
        }
735

    
736
        /**
737
         * @throws ResourceNotifyCloseException
738
         *
739
         */
740
        protected void resourcesNotifyClose() throws ResourceNotifyCloseException {
741
                this.dbfResource.notifyClose();
742
        }
743

    
744
        /**
745
         * @throws ResourceNotifyOpenException
746
         *
747
         */
748
        protected void resourcesOpen() throws ResourceNotifyOpenException {
749
                this.dbfResource.notifyOpen();
750
        }
751

    
752
        public Object getSourceId() {
753
                return this.getDBFParameters().getFile();
754
        }
755

    
756
        protected void resourceCloseRequest() throws ResourceException {
757
                this.dbfResource.closeRequest();
758
        }
759
}