root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dbf / DBFStoreProvider.java @ 25789
History | View | Annotate | Download (18.7 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 |
import java.util.Set; |
14 |
|
15 |
import org.gvsig.fmap.dal.DALLocator; |
16 |
import org.gvsig.fmap.dal.DataManager; |
17 |
import org.gvsig.fmap.dal.DataServerExplorer; |
18 |
import org.gvsig.fmap.dal.DataStoreNotification; |
19 |
import org.gvsig.fmap.dal.DataTypes; |
20 |
import org.gvsig.fmap.dal.exception.CloseException; |
21 |
import org.gvsig.fmap.dal.exception.DataException; |
22 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
23 |
import org.gvsig.fmap.dal.exception.InitializeException; |
24 |
import org.gvsig.fmap.dal.exception.OpenException; |
25 |
import org.gvsig.fmap.dal.exception.ReadException; |
26 |
import org.gvsig.fmap.dal.exception.UnsupportedVersionException; |
27 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
28 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
29 |
import org.gvsig.fmap.dal.feature.Feature; |
30 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
31 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
32 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 |
import org.gvsig.fmap.dal.feature.FeatureType; |
35 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
36 |
import org.gvsig.fmap.dal.feature.exception.UnknowDataTypeException; |
37 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureType; |
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.ResourceNotifyChangesException; |
47 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyCloseException; |
48 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException; |
49 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
50 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
51 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
52 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
53 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
54 |
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile; |
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; |
62 |
import org.gvsig.tools.persistence.PersistenceException; |
63 |
import org.gvsig.tools.persistence.PersistentState; |
64 |
|
65 |
public class DBFStoreProvider extends AbstractFeatureStoreProvider implements |
66 |
ResourceConsumer { |
67 |
|
68 |
public static String NAME = "DBFStore"; |
69 |
public static String DESCRIPTION = "DBF file"; |
70 |
// private DBFResource dbf = null;
|
71 |
private DbaseFile dbfFile = null; |
72 |
private ResourceProvider dbfResource;
|
73 |
private static final Locale ukLocale = new Locale("en", "UK"); |
74 |
private static final String DYNCLASS_NAME = "DBFStore"; |
75 |
protected static DynClass DYNCLASS = null; |
76 |
private DBFStoreParameters dbfParams;
|
77 |
private long counterNewsOIDs = -1; |
78 |
private DBFFeatureWriter writer;
|
79 |
public DBFStoreProvider() throws InitializeException { |
80 |
super();
|
81 |
writer = new DBFFeatureWriter(this.getName()); |
82 |
} |
83 |
|
84 |
public DBFStoreProvider(DBFStoreParameters params)
|
85 |
throws InitializeException {
|
86 |
super();
|
87 |
this.init(params);
|
88 |
writer = new DBFFeatureWriter(this.getName()); |
89 |
} |
90 |
|
91 |
protected void init(DBFStoreParameters params) throws InitializeException { |
92 |
this.dbfParams = params;
|
93 |
this.dynObject = (DelegatedDynObject) ToolsLocator
|
94 |
.getDynObjectManager().createDynObject( |
95 |
DYNCLASS); |
96 |
|
97 |
File theFile = getDBFParameters().getDBFFile();
|
98 |
dbfResource = this.createResource(FileResource.NAME,
|
99 |
new Object[] { theFile.getAbsolutePath() }); |
100 |
dbfResource.addConsumer(this);
|
101 |
|
102 |
this.dbfFile = new DbaseFile(theFile); |
103 |
|
104 |
} |
105 |
|
106 |
public FeatureStoreProvider initialize(FeatureStoreProviderServices store)
|
107 |
throws InitializeException {
|
108 |
super.initialize(store);
|
109 |
this.initFeatureType();
|
110 |
return this; |
111 |
} |
112 |
|
113 |
public String getName() { |
114 |
return NAME;
|
115 |
} |
116 |
|
117 |
protected DBFStoreParameters getDBFParameters() {
|
118 |
return dbfParams;
|
119 |
} |
120 |
|
121 |
|
122 |
public DataServerExplorer getExplorer() throws ReadException { |
123 |
DataManager manager = DALLocator.getDataManager(); |
124 |
FilesystemServerExplorerParameters params; |
125 |
try {
|
126 |
params = (FilesystemServerExplorerParameters) manager |
127 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
128 |
params.setRoot(this.getDBFParameters().getDBFFile().getParent());
|
129 |
return manager.createServerExplorer(params);
|
130 |
} catch (DataException e) {
|
131 |
throw new ReadException(this.getName(), e); |
132 |
} |
133 |
} |
134 |
|
135 |
public FeatureData getFeatureDataByReference(
|
136 |
FeatureReferenceProviderServices reference, FeatureType featureType) |
137 |
throws DataException {
|
138 |
|
139 |
return this.getFeatureDataByIndex(((Long) reference.getOID()) |
140 |
.longValue(), |
141 |
featureType); |
142 |
} |
143 |
|
144 |
|
145 |
public FeatureData getFeatureDataByReference(
|
146 |
FeatureReferenceProviderServices reference) throws DataException {
|
147 |
return this.getFeatureDataByReference(reference, this.store |
148 |
.getDefaultFeatureType()); |
149 |
} |
150 |
|
151 |
public void performEditing(Iterator deleteds, Iterator inserteds, |
152 |
Iterator updateds)
|
153 |
throws PerformEditingException {
|
154 |
try {
|
155 |
this.close();
|
156 |
} catch (CloseException e1) {
|
157 |
throw new PerformEditingException(this.getName(), e1); |
158 |
} |
159 |
|
160 |
try {
|
161 |
this.dbfResource.begin();
|
162 |
FeatureSet set = this.store.getFeatureSet();
|
163 |
writer.begin(this.getDBFParameters(), this.store |
164 |
.getDefaultFeatureType(), set.getSize()); |
165 |
|
166 |
Iterator iter = set.iterator();
|
167 |
while (iter.hasNext()) {
|
168 |
Feature feature=(Feature) iter.next(); |
169 |
writer.write(feature); |
170 |
} |
171 |
|
172 |
writer.end(); |
173 |
|
174 |
this.dbfResource.notifyChanges();
|
175 |
} catch (Exception e) { |
176 |
throw new PerformEditingException(this.getName(), e); |
177 |
} finally {
|
178 |
this.dbfResource.end();
|
179 |
this.dbfResource.removeConsumer(this); |
180 |
} |
181 |
|
182 |
this.counterNewsOIDs = -1; |
183 |
} |
184 |
|
185 |
/*
|
186 |
* ==================================================
|
187 |
*/
|
188 |
|
189 |
public FeatureData createFeatureData(FeatureType type) throws DataException { |
190 |
return new DBFFeatureData(this, (DefaultFeatureType) type); |
191 |
} |
192 |
|
193 |
|
194 |
/*
|
195 |
* ===================================================
|
196 |
*/
|
197 |
|
198 |
FeatureStoreProviderServices getProviderServices() { |
199 |
return this.store; |
200 |
} |
201 |
|
202 |
|
203 |
protected void initFeatureType() throws InitializeException { |
204 |
FeatureType defaultType = this.getTheFeatureType().getNotEditableCopy();
|
205 |
List types = new ArrayList(1); |
206 |
types.add(defaultType); |
207 |
this.store.setFeatureTypes(types, defaultType);
|
208 |
} |
209 |
|
210 |
protected EditableFeatureType getTheFeatureType() throws InitializeException { |
211 |
try {
|
212 |
this.open();
|
213 |
this.dbfResource.begin();
|
214 |
} catch (DataException e) {
|
215 |
throw new InitializeException(this.getName(), e); |
216 |
} |
217 |
try {
|
218 |
int fieldCount = -1; |
219 |
fieldCount = dbfFile.getFieldCount(); |
220 |
|
221 |
EditableFeatureType fType = this.store.createFeatureType();
|
222 |
|
223 |
fType.setHasOID(true);
|
224 |
int precision;
|
225 |
for (int i = 0; i < fieldCount; i++) { |
226 |
char fieldType = dbfFile.getFieldType(i);
|
227 |
EditableFeatureAttributeDescriptor attr; |
228 |
|
229 |
if (fieldType == 'L') { |
230 |
attr = fType |
231 |
.add(dbfFile.getFieldName(i), DataTypes.BOOLEAN); |
232 |
attr.setDefaultValue(false);
|
233 |
attr.setAllowNull(false);
|
234 |
|
235 |
} else if ((fieldType == 'F') || (fieldType == 'N')) { |
236 |
precision = dbfFile.getFieldDecimalLength(i); |
237 |
if (precision > 0) { |
238 |
attr = fType.add(dbfFile.getFieldName(i), |
239 |
DataTypes.DOUBLE, precision); |
240 |
attr.setDefaultValue(0d);
|
241 |
} else {
|
242 |
attr = fType |
243 |
.add(dbfFile.getFieldName(i), DataTypes.INT); |
244 |
attr.setDefaultValue(0);
|
245 |
} |
246 |
attr.setAllowNull(false);
|
247 |
|
248 |
} else if (fieldType == 'C') { |
249 |
attr = fType.add(dbfFile.getFieldName(i), DataTypes.STRING); |
250 |
attr.setSize(dbfFile.getFieldLength(i)); |
251 |
attr.setDefaultValue("");
|
252 |
attr.setAllowNull(false);
|
253 |
|
254 |
} else if (fieldType == 'D') { |
255 |
attr = fType.add(dbfFile.getFieldName(i), DataTypes.DATE); |
256 |
attr.setDefaultValue(null);
|
257 |
attr.setAllowNull(true);
|
258 |
} else {
|
259 |
throw new InitializeException(this.getName(), |
260 |
new UnknowDataTypeException(
|
261 |
dbfFile.getFieldName(i), "" + fieldType,
|
262 |
this.getName()));
|
263 |
} |
264 |
} |
265 |
return fType;
|
266 |
} finally {
|
267 |
this.dbfResource.end();
|
268 |
} |
269 |
} |
270 |
|
271 |
|
272 |
protected void loadValue(FeatureData featureData, int rowIndex, |
273 |
FeatureAttributeDescriptor descriptor) throws ReadException {
|
274 |
if (descriptor.getEvaluator() != null) { |
275 |
// Nothing to do
|
276 |
return;
|
277 |
} |
278 |
|
279 |
|
280 |
int fieldIndex = descriptor.getIndex();
|
281 |
int originalIndes = descriptor.getIndex();
|
282 |
if (!this.dbfFile.getFieldName(descriptor.getIndex()).equals( |
283 |
descriptor.getName())) { |
284 |
for (int i = 0; i < this.dbfFile.getFieldCount(); i++) { |
285 |
if (descriptor.getName().equals(this.dbfFile.getFieldName(i))) { |
286 |
originalIndes = i; |
287 |
break;
|
288 |
} |
289 |
} |
290 |
|
291 |
} |
292 |
String value = null; |
293 |
try {
|
294 |
value = this.dbfFile.getStringFieldValue(rowIndex, originalIndes);
|
295 |
} catch (DataException e) {
|
296 |
throw new ReadException(this.store.getName(), e); |
297 |
} |
298 |
value = value.trim(); |
299 |
int fieldType = descriptor.getDataType();
|
300 |
switch (fieldType) {
|
301 |
case DataTypes.STRING:
|
302 |
featureData.set(fieldIndex, value); |
303 |
break;
|
304 |
|
305 |
case DataTypes.DOUBLE:
|
306 |
try {
|
307 |
featureData.set(fieldIndex, new Double(value)); |
308 |
} catch (NumberFormatException e) { |
309 |
featureData.set(fieldIndex, null);
|
310 |
} |
311 |
break;
|
312 |
|
313 |
case DataTypes.INT:
|
314 |
try {
|
315 |
featureData.set(fieldIndex, new Integer(value)); |
316 |
} catch (NumberFormatException e) { |
317 |
featureData.set(fieldIndex, null);
|
318 |
} |
319 |
break;
|
320 |
|
321 |
case DataTypes.FLOAT:
|
322 |
try {
|
323 |
featureData.set(fieldIndex, new Float(value)); |
324 |
} catch (NumberFormatException e) { |
325 |
featureData.set(fieldIndex, null);
|
326 |
} |
327 |
break;
|
328 |
|
329 |
case DataTypes.LONG:
|
330 |
try {
|
331 |
featureData.set(fieldIndex, new Long(value)); |
332 |
} catch (NumberFormatException e) { |
333 |
featureData.set(fieldIndex, null);
|
334 |
} |
335 |
break;
|
336 |
|
337 |
case DataTypes.BOOLEAN:
|
338 |
featureData.set(fieldIndex, new Boolean(value)); |
339 |
break;
|
340 |
|
341 |
case DataTypes.BYTE:
|
342 |
try {
|
343 |
featureData.set(fieldIndex, new Byte(value)); |
344 |
} catch (NumberFormatException e) { |
345 |
featureData.set(fieldIndex, null);
|
346 |
} |
347 |
break;
|
348 |
|
349 |
case DataTypes.DATE:
|
350 |
String year = value.substring(0, 4); |
351 |
String month = value.substring(4, 6); |
352 |
String day = value.substring(6, 8); |
353 |
DateFormat df;
|
354 |
if (descriptor.getDateFormat() == null){ |
355 |
df = DateFormat.getDateInstance(DateFormat.SHORT, |
356 |
ukLocale); |
357 |
} else{
|
358 |
df = descriptor.getDateFormat(); |
359 |
} |
360 |
/*
|
361 |
* Calendar c = Calendar.getInstance(); c.clear();
|
362 |
* c.set(Integer.parseInt(year), Integer.parseInt(month),
|
363 |
* Integer.parseInt(day)); c.set(Calendar.MILLISECOND, 0);
|
364 |
*/
|
365 |
String strAux = month + "/" + day + "/" + year; |
366 |
Date dat = null; |
367 |
try {
|
368 |
dat = df.parse(strAux); |
369 |
} catch (ParseException e) { |
370 |
throw new ReadException(this.store.getName(), e); |
371 |
} |
372 |
featureData.set(fieldIndex, dat); |
373 |
break;
|
374 |
|
375 |
|
376 |
default:
|
377 |
featureData.set(fieldIndex, descriptor.getDefaultValue()); |
378 |
break;
|
379 |
} |
380 |
} |
381 |
|
382 |
|
383 |
/***
|
384 |
* NOT supported in Alter Mode
|
385 |
*
|
386 |
* @param index
|
387 |
* @return
|
388 |
* @throws ReadException
|
389 |
*/
|
390 |
protected FeatureData getFeatureDataByIndex(long index) throws DataException { |
391 |
return this |
392 |
.getFeatureDataByIndex(index, this.store
|
393 |
.getDefaultFeatureType()); |
394 |
} |
395 |
|
396 |
protected int getFeatureCount() throws ReadException, OpenException, |
397 |
ResourceNotifyChangesException { |
398 |
this.open();
|
399 |
try {
|
400 |
this.dbfResource.begin();
|
401 |
} catch (ResourceBeginException e) {
|
402 |
throw new ReadException(this.getName(), e); |
403 |
} |
404 |
try {
|
405 |
return this.dbfFile.getRecordCount(); |
406 |
} finally {
|
407 |
this.dbfResource.end();
|
408 |
} |
409 |
} |
410 |
|
411 |
public FeatureSetProvider createSet(FeatureQuery query)
|
412 |
throws DataException {
|
413 |
return new DBFSetProvider(this, query); |
414 |
} |
415 |
|
416 |
public boolean canCreate() { |
417 |
return true; |
418 |
} |
419 |
|
420 |
public boolean canWriteGeometry(int geometryType) throws DataException { |
421 |
return false; |
422 |
} |
423 |
|
424 |
public void open() throws OpenException { |
425 |
if (this.dbfFile.isOpen()) { |
426 |
return;
|
427 |
} |
428 |
try {
|
429 |
this.dbfResource.begin();
|
430 |
} catch (ResourceBeginException e) {
|
431 |
throw new OpenException(this.getName(), e); |
432 |
} |
433 |
try {
|
434 |
this.dbfFile.open();
|
435 |
this.dbfResource.notifyOpen();
|
436 |
|
437 |
// Load metadata values
|
438 |
this.dynObject.setDynValue(DBFLibrary.DYNFIELD_CODEPAGE_NAME,
|
439 |
new Byte(this.dbfFile.getCodePage())); |
440 |
|
441 |
} catch (UnsupportedVersionException e) {
|
442 |
throw new OpenException(this.getName(), e); |
443 |
} catch (ResourceNotifyOpenException e) {
|
444 |
throw new OpenException(this.getName(), e); |
445 |
} catch (FileNotFoundException e) { |
446 |
throw new OpenException(this.getName(), e); |
447 |
} catch (IOException e) { |
448 |
throw new OpenException(this.getName(), e); |
449 |
} finally {
|
450 |
this.dbfResource.end();
|
451 |
} |
452 |
} |
453 |
|
454 |
public void close() throws CloseException { |
455 |
super.close();
|
456 |
if (!this.dbfFile.isOpen()) { |
457 |
return;
|
458 |
} |
459 |
//Cerrar recurso
|
460 |
try {
|
461 |
this.dbfResource.begin();
|
462 |
} catch (ResourceBeginException e) {
|
463 |
throw new CloseException(this.getName(), e); |
464 |
} |
465 |
try {
|
466 |
this.dbfFile.close();
|
467 |
this.dbfResource.notifyClose();
|
468 |
|
469 |
} catch (ResourceNotifyCloseException e) {
|
470 |
throw new CloseException(this.getName(), e); |
471 |
} finally {
|
472 |
this.dbfResource.end();
|
473 |
} |
474 |
} |
475 |
|
476 |
public void dispose() throws CloseException { |
477 |
this.close();
|
478 |
dbfFile = null;
|
479 |
this.dbfResource.removeConsumer(this); |
480 |
dbfResource = null;
|
481 |
super.dispose();
|
482 |
} |
483 |
|
484 |
public boolean closeResourceRequested(ResourceProvider resource) { |
485 |
try {
|
486 |
this.close();
|
487 |
} catch (CloseException e) {
|
488 |
return false; |
489 |
} |
490 |
return true; |
491 |
} |
492 |
|
493 |
public boolean allowWrite() { |
494 |
File file;
|
495 |
try {
|
496 |
file = new File((String) this.dbfResource.get()); |
497 |
} catch (AccessResourceException e) {
|
498 |
return false; |
499 |
} |
500 |
return file.canWrite();
|
501 |
} |
502 |
|
503 |
public void refresh() throws OpenException { |
504 |
try {
|
505 |
this.close();
|
506 |
} catch (CloseException e) {
|
507 |
throw new OpenException(this.getName(), e); |
508 |
} |
509 |
this.open();
|
510 |
try {
|
511 |
this.getTheFeatureType();
|
512 |
} catch (InitializeException e) {
|
513 |
throw new OpenException(this.getName(), e); |
514 |
} |
515 |
} |
516 |
|
517 |
/**
|
518 |
*
|
519 |
* @param index
|
520 |
* @param featureType
|
521 |
* @return
|
522 |
* @throws ReadException
|
523 |
*/
|
524 |
protected FeatureData getFeatureDataByIndex(long index, |
525 |
FeatureType featureType) throws DataException {
|
526 |
FeatureData featureData = this.createFeatureData(featureType);
|
527 |
featureData.setOID(new Long(index)); |
528 |
return featureData;
|
529 |
} |
530 |
|
531 |
protected void initFeatureDataByIndex(FeatureData featureData, |
532 |
long index, FeatureType featureType) throws DataException { |
533 |
featureData.setOID(new Long(index)); |
534 |
} |
535 |
|
536 |
/**
|
537 |
*
|
538 |
* @param featureData
|
539 |
* @throws DataException
|
540 |
*/
|
541 |
protected void loadFeatureDataByIndex(FeatureData featureData) |
542 |
throws DataException {
|
543 |
this.open();
|
544 |
this.dbfResource.begin();
|
545 |
long index = ((Long) featureData.getOID()).longValue(); |
546 |
try {
|
547 |
if (index >= this.dbfFile.getRecordCount()) { |
548 |
// FIXME
|
549 |
throw new ArrayIndexOutOfBoundsException("" + index); |
550 |
} |
551 |
Iterator iterator = featureData.getType().iterator();
|
552 |
while (iterator.hasNext()) {
|
553 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator |
554 |
.next(); |
555 |
this.loadValue(featureData, (int) index, descriptor); |
556 |
} |
557 |
|
558 |
|
559 |
} finally {
|
560 |
this.dbfResource.end();
|
561 |
} |
562 |
} |
563 |
|
564 |
public int getFeatureReferenceOIDType() { |
565 |
return DataTypes.LONG;
|
566 |
} |
567 |
|
568 |
public Object createNewOID() { |
569 |
if (this.counterNewsOIDs < 0) { |
570 |
try {
|
571 |
this.counterNewsOIDs = this.getFeatureCount(); |
572 |
} catch (DataException e) {
|
573 |
e.printStackTrace(); |
574 |
} |
575 |
|
576 |
}else{
|
577 |
this.counterNewsOIDs++;
|
578 |
} |
579 |
return new Long(counterNewsOIDs); |
580 |
} |
581 |
|
582 |
public boolean supportsAppendMode() { |
583 |
return true; |
584 |
} |
585 |
|
586 |
|
587 |
public void append(Feature feature) { |
588 |
try {
|
589 |
writer.write(feature); |
590 |
} catch (DataException e) {
|
591 |
// TODO Auto-generated catch block
|
592 |
e.printStackTrace(); |
593 |
} |
594 |
} |
595 |
|
596 |
public void beginAppend() { |
597 |
try {
|
598 |
this.close();
|
599 |
this.dbfResource.begin();
|
600 |
FeatureSet set = this.store.getFeatureSet();
|
601 |
writer.begin(this.getDBFParameters(), this.store |
602 |
.getDefaultFeatureType(), set.getSize()); |
603 |
} catch (DataException e) {
|
604 |
// TODO Auto-generated catch block
|
605 |
e.printStackTrace(); |
606 |
} |
607 |
} |
608 |
|
609 |
public void endAppend() { |
610 |
try {
|
611 |
writer.end(); |
612 |
this.dbfResource.notifyChanges();
|
613 |
this.dbfResource.end();
|
614 |
this.dbfResource.removeConsumer(this); |
615 |
this.counterNewsOIDs = -1; |
616 |
} catch (DataException e) {
|
617 |
// TODO Auto-generated catch block
|
618 |
e.printStackTrace(); |
619 |
} |
620 |
} |
621 |
|
622 |
public PersistentState getState() throws PersistenceException { |
623 |
// Nothing to do
|
624 |
return null; |
625 |
} |
626 |
|
627 |
public void loadState(PersistentState state) throws PersistenceException { |
628 |
try {
|
629 |
this.init((DBFStoreParameters) this.store.getParameters()); |
630 |
} catch (InitializeException e) {
|
631 |
throw new PersistenceException(e); |
632 |
} |
633 |
} |
634 |
|
635 |
public void setState(PersistentState state) throws PersistenceException { |
636 |
try {
|
637 |
this.init((DBFStoreParameters) this.store.getParameters()); |
638 |
} catch (InitializeException e) {
|
639 |
throw new PersistenceException(e); |
640 |
} |
641 |
} |
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 |
} |
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 |
} |
713 |
} |