Revision 32880 branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/DBFStoreProvider.java
DBFStoreProvider.java | ||
---|---|---|
16 | 16 |
import org.gvsig.fmap.dal.DataServerExplorer; |
17 | 17 |
import org.gvsig.fmap.dal.DataStoreNotification; |
18 | 18 |
import org.gvsig.fmap.dal.DataTypes; |
19 |
import org.gvsig.fmap.dal.FileHelper; |
|
19 | 20 |
import org.gvsig.fmap.dal.exception.CloseException; |
20 | 21 |
import org.gvsig.fmap.dal.exception.DataException; |
21 | 22 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
... | ... | |
53 | 54 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
54 | 55 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
55 | 56 |
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile; |
56 |
import org.gvsig.tools.ToolsLocator;
|
|
57 |
import org.gvsig.tools.dynobject.DynClass;
|
|
58 |
import org.gvsig.tools.dynobject.DynField;
|
|
57 |
import org.gvsig.metadata.MetadataLocator;
|
|
58 |
import org.gvsig.metadata.MetadataManager;
|
|
59 |
import org.gvsig.metadata.exceptions.MetadataException;
|
|
59 | 60 |
import org.gvsig.tools.dynobject.DynObject; |
60 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
61 | 61 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
62 | 62 |
import org.gvsig.tools.exception.BaseException; |
63 | 63 |
|
... | ... | |
68 | 68 |
public static String DESCRIPTION = "DBF file"; |
69 | 69 |
// private DBFResource dbf = null; |
70 | 70 |
private static final Locale ukLocale = new Locale("en", "UK"); |
71 |
private static final String DYNCLASS_NAME = "DBFStore"; |
|
72 |
protected static DynClass DYNCLASS = null; |
|
71 |
|
|
72 |
public static final String METADATA_DEFINITION_NAME = NAME; |
|
73 |
private static final String METADATA_ENCODING = "Encoding"; |
|
74 |
private static final String METADATA_CODEPAGE = "CodePage"; |
|
75 |
|
|
76 |
// public static final String DYNFIELD_CURRENT_ENCODING = "CurrentEncoding"; |
|
77 |
// public static final String DYNFIELD_ORIGINAL_ENCODING = "OriginalEncoding"; |
|
73 | 78 |
|
74 |
public static final String DYNFIELD_CURRENT_ENCODING = "CurrentEncoding"; |
|
75 |
public static final String DYNFIELD_ORIGINAL_ENCODING = "OriginalEncoding"; |
|
76 |
|
|
77 | 79 |
private DbaseFile dbfFile = null; |
78 | 80 |
private ResourceProvider dbfResource; |
79 | 81 |
private long counterNewsOIDs = -1; |
80 | 82 |
private DBFFeatureWriter writer; |
81 | 83 |
|
84 |
|
|
85 |
protected static void registerMetadataDefinition() throws MetadataException { |
|
86 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
|
87 |
if( manager.getDefinition(METADATA_DEFINITION_NAME)==null ) { |
|
88 |
manager.addDefinition( |
|
89 |
METADATA_DEFINITION_NAME, |
|
90 |
DBFStoreParameters.class.getResourceAsStream("DBFStoreMetadata.xml"), |
|
91 |
DBFStoreParameters.class.getClassLoader() |
|
92 |
); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
82 | 96 |
public DBFStoreProvider(DBFStoreParameters params, |
83 | 97 |
DataStoreProviderServices storeServices) |
84 | 98 |
throws InitializeException { |
85 |
this(params, storeServices, ToolsLocator |
|
86 |
.getDynObjectManager().createDynObject( |
|
87 |
DYNCLASS)); |
|
99 |
super( |
|
100 |
params, |
|
101 |
storeServices, |
|
102 |
FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
|
103 |
); |
|
104 |
this.init(params, storeServices); |
|
88 | 105 |
} |
89 | 106 |
|
90 | 107 |
protected DBFStoreProvider(DBFStoreParameters params, |
... | ... | |
96 | 113 |
|
97 | 114 |
protected void init(DBFStoreParameters params, |
98 | 115 |
DataStoreProviderServices storeServices) throws InitializeException { |
99 |
this.setDynValue("DefaultSRS", null); |
|
100 |
this.setDynValue("Envelope", null); |
|
101 |
|
|
102 | 116 |
File theFile = getDBFParameters().getDBFFile(); |
103 | 117 |
initResource(params, storeServices); |
104 | 118 |
|
... | ... | |
111 | 125 |
|
112 | 126 |
} |
113 | 127 |
|
128 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
|
129 |
try { |
|
130 |
this.open(); |
|
131 |
} catch (OpenException e) { |
|
132 |
throw new RuntimeException(e); |
|
133 |
} |
|
134 |
if( METADATA_ENCODING.equalsIgnoreCase(name) ) { |
|
135 |
return this.dbfFile.getOriginalCharset(); |
|
136 |
} else if( METADATA_CODEPAGE.equalsIgnoreCase(name) ) { |
|
137 |
return new Byte(this.dbfFile.getCodePage()); |
|
138 |
} |
|
139 |
return super.getDynValue(name); |
|
140 |
} |
|
141 |
|
|
114 | 142 |
protected void initResource(DBFStoreParameters params, |
115 | 143 |
DataStoreProviderServices storeServices) throws InitializeException { |
116 | 144 |
|
... | ... | |
137 | 165 |
params = (FilesystemServerExplorerParameters) manager |
138 | 166 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
139 | 167 |
params.setRoot(this.getDBFParameters().getDBFFile().getParent()); |
140 |
return manager.createServerExplorer(params);
|
|
168 |
return manager.openServerExplorer(FilesystemServerExplorer.NAME,params);
|
|
141 | 169 |
} catch (DataException e) { |
142 | 170 |
throw new ReadException(this.getName(), e); |
143 | 171 |
} catch (ValidateDataParametersException e) { |
... | ... | |
170 | 198 |
DBFStoreParameters tmpParams = |
171 | 199 |
(DBFStoreParameters) getDBFParameters().getCopy(); |
172 | 200 |
|
173 |
tmpParams.setDBFFileName(tmpParams.getDBFFileName()
|
|
201 |
tmpParams.setDBFFile(tmpParams.getDBFFileName() |
|
174 | 202 |
+ ".tmp"); |
175 | 203 |
|
176 | 204 |
writer.begin(tmpParams, store.getDefaultFeatureType(), |
... | ... | |
465 | 493 |
public Object run() throws Exception { |
466 | 494 |
openFile(); |
467 | 495 |
resourcesOpen(); |
468 |
|
|
469 |
// Load metadata values |
|
470 |
loadMetadataValues(); |
|
471 | 496 |
return null; |
472 | 497 |
} |
473 | 498 |
}); |
... | ... | |
482 | 507 |
this.dbfFile.open(); |
483 | 508 |
} |
484 | 509 |
|
485 |
protected void loadMetadataValues() throws DynFieldNotFoundException, |
|
486 |
ReadException { |
|
487 |
this.setDynValue(DBFLibrary.DYNFIELD_CODEPAGE_NAME, new Byte( |
|
488 |
this.dbfFile.getCodePage())); |
|
489 |
this.setDynValue(DYNFIELD_CURRENT_ENCODING, dbfFile |
|
490 |
.getCurrenCharset().name()); |
|
491 |
this.setDynValue(DYNFIELD_ORIGINAL_ENCODING, dbfFile |
|
492 |
.getOriginalCharset().name()); |
|
493 |
} |
|
494 |
|
|
495 | 510 |
public void close() throws CloseException { |
496 | 511 |
if (dbfFile == null || !this.dbfFile.isOpen()) { |
497 | 512 |
return; |
... | ... | |
655 | 670 |
}); |
656 | 671 |
} |
657 | 672 |
|
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 |
field = dynClass.addDynField(DYNFIELD_CURRENT_ENCODING); |
|
668 |
field.setType(org.gvsig.tools.dataTypes.DataTypes.STRING); |
|
669 |
|
|
670 |
field = dynClass.addDynField(DYNFIELD_ORIGINAL_ENCODING); |
|
671 |
field.setType(org.gvsig.tools.dataTypes.DataTypes.STRING); |
|
672 |
|
|
673 |
dynClass.extend(dynman.get(FeatureStore.DYNCLASS_NAME)); |
|
674 |
|
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
DYNCLASS = dynClass; |
|
679 |
} |
|
680 |
|
|
681 |
} |
|
682 |
|
|
683 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
|
684 |
try { |
|
685 |
this.open(); |
|
686 |
} catch (OpenException e) { |
|
687 |
// FIXME |
|
688 |
throw new RuntimeException(e); |
|
689 |
} |
|
690 |
return super.getDynValue(name); |
|
691 |
} |
|
692 |
|
|
693 |
|
|
694 | 673 |
/* |
695 | 674 |
* (non-Javadoc) |
696 | 675 |
* |
Also available in: Unified diff