Revision 25789 branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/DBFStoreProvider.java

View differences:

DBFStoreProvider.java
5 5
import java.text.DateFormat;
6 6
import java.text.ParseException;
7 7
import java.util.ArrayList;
8
import java.util.Arrays;
8 9
import java.util.Date;
9 10
import java.util.Iterator;
10 11
import java.util.List;
11 12
import java.util.Locale;
13
import java.util.Set;
12 14

  
13 15
import org.gvsig.fmap.dal.DALLocator;
14 16
import org.gvsig.fmap.dal.DataManager;
15 17
import org.gvsig.fmap.dal.DataServerExplorer;
18
import org.gvsig.fmap.dal.DataStoreNotification;
16 19
import org.gvsig.fmap.dal.DataTypes;
17 20
import org.gvsig.fmap.dal.exception.CloseException;
18 21
import org.gvsig.fmap.dal.exception.DataException;
......
27 30
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
28 31
import org.gvsig.fmap.dal.feature.FeatureQuery;
29 32
import org.gvsig.fmap.dal.feature.FeatureSet;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
30 34
import org.gvsig.fmap.dal.feature.FeatureType;
31 35
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
32 36
import org.gvsig.fmap.dal.feature.exception.UnknowDataTypeException;
......
48 52
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
49 53
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
50 54
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile;
51
import org.gvsig.metadata.Metadata;
52
import org.gvsig.tools.exception.NotYetImplemented;
55
import org.gvsig.tools.ToolsLocator;
56
import org.gvsig.tools.dynobject.DelegatedDynObject;
57
import org.gvsig.tools.dynobject.DynClass;
58
import org.gvsig.tools.dynobject.DynField;
59
import org.gvsig.tools.dynobject.DynObject;
60
import org.gvsig.tools.dynobject.DynObjectManager;
61
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
53 62
import org.gvsig.tools.persistence.PersistenceException;
54 63
import org.gvsig.tools.persistence.PersistentState;
55 64

  
......
61 70
	//	private DBFResource dbf = null;
62 71
	private DbaseFile dbfFile = null;
63 72
	private ResourceProvider dbfResource;
64
	protected Metadata metadata;
65 73
	private static final Locale ukLocale = new Locale("en", "UK");
74
	private static final String DYNCLASS_NAME = "DBFStore";
75
	protected static DynClass DYNCLASS = null;
66 76
	private DBFStoreParameters dbfParams;
67 77
	private long counterNewsOIDs = -1;
68 78
	private DBFFeatureWriter writer;
......
80 90

  
81 91
	protected void init(DBFStoreParameters params) throws InitializeException {
82 92
		this.dbfParams = params;
93
		this.dynObject = (DelegatedDynObject) ToolsLocator
94
				.getDynObjectManager().createDynObject(
95
				DYNCLASS);
83 96

  
84 97
		File theFile = getDBFParameters().getDBFFile();
85 98
		dbfResource = this.createResource(FileResource.NAME,
86 99
				new Object[] { theFile.getAbsolutePath() });
87 100
		dbfResource.addConsumer(this);
88 101

  
89
		//DBFResource tmpResource = new DBFResource(dbfParameters);
90
		//
91
		//try {
92
		//	this.dbf = (DBFResource) this.store.addResource(tmpResource);
93
		//} catch (DataException e1) {
94
		//	throw new InitializeException(this.getName(), e1);
95
		//}
102
		this.dbfFile = new DbaseFile(theFile);
96 103

  
97

  
98
		this.dbfFile = new DbaseFile(theFile);
99 104
	}
100 105

  
101 106
	public FeatureStoreProvider initialize(FeatureStoreProviderServices store)
......
429 434
			this.dbfFile.open();
430 435
			this.dbfResource.notifyOpen();
431 436

  
437
			// Load metadata values
438
			this.dynObject.setDynValue(DBFLibrary.DYNFIELD_CODEPAGE_NAME,
439
					new Byte(this.dbfFile.getCodePage()));
440

  
432 441
		} catch (UnsupportedVersionException e) {
433 442
			throw new OpenException(this.getName(), e);
434 443
		} catch (ResourceNotifyOpenException e) {
......
469 478
		dbfFile = null;
470 479
		this.dbfResource.removeConsumer(this);
471 480
		dbfResource = null;
472
		metadata = null;
473 481
		super.dispose();
474 482
	}
475 483

  
......
632 640
		}
633 641
	}
634 642

  
643
	public Object getMetadataID() {
644
		try {
645
			return ((FileResource) this.dbfResource).getFile()
646
					.getAbsolutePath();
647
		} catch (AccessResourceException e) {
648
			// FIXME Exception
649
			throw new RuntimeException(e);
650
		}
651
	}
635 652

  
653
	public Iterator getChilds() {
654
		return Arrays.asList(new DynObject[] { this.dbfParams }).iterator();
655

  
656
	}
657

  
658
	protected static void registerDynClass() {
659
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
660
		DynClass dynClass;
661
		DynField field;
662
		if (DYNCLASS == null) {
663
			dynClass = dynman.add(DYNCLASS_NAME,
664
					"DBF File Store");
665
			field = DBFLibrary.addCodePageField(dynClass);
666

  
667
			dynClass.extend(dynman.get(FeatureStore.DYNCLASS_NAME));
668

  
669
			DYNCLASS = dynClass;
670
		}
671

  
672
	}
673

  
674
	public Object getDynValue(String name) throws DynFieldNotFoundException {
675
		try {
676
			this.open();
677
		} catch (OpenException e) {
678
			// FIXME
679
			throw new RuntimeException(e);
680
		}
681
		return super.getDynValue(name);
682
	}
683

  
684
	/*
685
	 * (non-Javadoc)
686
	 * 
687
	 * @see org.gvsig.metadata.Metadata#getMetadataChildren()
688
	 */
689
	public Set getMetadataChildren() {
690
		return null;
691
	}
692

  
693
	/*
694
	 * (non-Javadoc)
695
	 * 
696
	 * @see org.gvsig.metadata.Metadata#getMetadataName()
697
	 */
698
	public String getMetadataName() {
699
		return this.getDBFParameters().getDBFFile().getName();
700
	}
701

  
702
	/*
703
	 * (non-Javadoc)
704
	 * 
705
	 * @see
706
	 * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
707
	 * gvsig.fmap.dal.resource.spi.ResourceProvider)
708
	 */
709
	public void resourceChanged(ResourceProvider resource) {
710
		this.store.notifyChange(DataStoreNotification.RESOURCE_CHANGED,
711
				resource);
712
	}
636 713
}

Also available in: Unified diff