Revision 29326 branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/shp/SHPStoreProvider.java

View differences:

SHPStoreProvider.java
43 43
import org.gvsig.fmap.dal.feature.Feature;
44 44
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
45 45
import org.gvsig.fmap.dal.feature.FeatureSet;
46
import org.gvsig.fmap.dal.feature.FeatureStore;
46 47
import org.gvsig.fmap.dal.feature.FeatureType;
47 48
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
48 49
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
......
53 54
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException;
54 55
import org.gvsig.fmap.dal.resource.file.FileResource;
55 56
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
57
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
58
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters;
56 59
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider;
57 60
import org.gvsig.fmap.dal.store.shp.utils.SHPFile;
58 61
import org.gvsig.fmap.geom.GeometryLocator;
......
62 65
import org.gvsig.fmap.geom.exception.CreateGeometryException;
63 66
import org.gvsig.fmap.geom.primitive.Envelope;
64 67
import org.gvsig.tools.ToolsLocator;
65
import org.gvsig.tools.dynobject.DelegatedDynObject;
66 68
import org.gvsig.tools.dynobject.DynClass;
67 69
import org.gvsig.tools.dynobject.DynField;
68 70
import org.gvsig.tools.dynobject.DynObjectManager;
69 71
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
70
import org.gvsig.tools.persistence.PersistenceException;
71
import org.gvsig.tools.persistence.PersistentState;
72 72
import org.slf4j.Logger;
73 73
import org.slf4j.LoggerFactory;
74 74

  
......
81 81
	private ResourceProvider shpResource;
82 82
	private ResourceProvider shxResource;
83 83

  
84
	private SHPStoreParameters shpParams;
84

  
85 85
	protected static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY";
86 86
	protected static final String DYNFIELD_SRSORIGINALPARAMETERS_NAME = "SRSOriginalParameters";
87 87
	private static final String DYNCLASS_NAME = "SHPStore";
......
89 89

  
90 90
	private SHPFeatureWriter writer = null;
91 91

  
92
	public SHPStoreProvider(SHPStoreParameters params)
92
	public SHPStoreProvider(SHPStoreParameters params,
93
			DataStoreProviderServices storeServices)
93 94
			throws InitializeException {
94
		super(params);
95
		this.shpParams = params;
95
		super(params, storeServices,ToolsLocator
96
				.getDynObjectManager().createDynObject(DYNCLASS));
97
	}
96 98

  
99
	protected void init(DBFStoreParameters params,
100
			DataStoreProviderServices storeServices) throws InitializeException {
101

  
102
		SHPStoreParameters shpParams = (SHPStoreParameters) params;
97 103
		shpResource = this.createResource(FileResource.NAME,
98
				new Object[] { this.shpParams.getSHPFileName() });
104
				new Object[] { shpParams.getSHPFileName() });
99 105
		shpResource.addConsumer(this);
100 106

  
101 107
		shxResource = this.createResource(FileResource.NAME,
102
				new Object[] { this.shpParams.getSHXFileName() });
108
				new Object[] { shpParams.getSHXFileName() });
103 109
		shxResource.addConsumer(this);
104 110

  
105
		// TODO .prj
111
		this.shpFile = new SHPFile(shpParams);
112
		super.init(params, storeServices);
106 113

  
107
		// FIXME
108
		this.metadata = (DelegatedDynObject) ToolsLocator
109
				.getDynObjectManager().createDynObject(DYNCLASS);
110

  
111
		this.shpFile = new SHPFile(this.shpParams);
112 114
	}
113 115

  
114 116
	protected void resourcesBegin() throws ResourceBeginException {
......
158 160
		this.shxResource.removeConsumer(this);
159 161
		this.shpResource = null;
160 162
		this.shxResource = null;
161
		this.shpParams = null;
162 163
		this.writer = null;
163 164
		this.shpFile = null;
164 165
	}
......
267 268
			// // TODO petar ??
268 269
			// srs = "EPSG:23030";
269 270
			// }
270
			IProjection srs = this.shpParams.getSRS();
271
			IProjection srs = getShpParameters().getSRS();
271 272
			if (srs == null){
272 273
				srs = CRSFactory.getCRS("EPSG:23030");
273 274
			}
......
292 293
	}
293 294

  
294 295
	protected SHPStoreParameters getShpParameters() {
295
		return shpParams;
296
		return (SHPStoreParameters) getParameters();
296 297
	}
297 298

  
298 299
	public String getName() {
......
397 398
			ReadException {
398 399
		super.loadMetadataValues();
399 400

  
400
		this.metadata.setDynValue(DYNFIELD_SRSORIGINALPARAMETERS_NAME,
401
		this.setDynValue(DYNFIELD_SRSORIGINALPARAMETERS_NAME,
401 402
				this.shpFile.getSRSParameters());
402 403

  
403
		this.metadata.setDynValue("DefaultSRS", this.getShpParameters()
404
		this.setDynValue("DefaultSRS", this.getShpParameters()
404 405
				.getSRS());
405 406

  
406
		this.metadata.setDynValue("Envelope", shpFile.getFullExtent());
407
		this.setDynValue("Envelope", shpFile.getFullExtent());
407 408

  
408 409
	}
409 410

  
......
431 432
			Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
432 433
		FeatureType fType;
433 434
		try {
434
			fType = this.store.getDefaultFeatureType();
435
			fType = this.getStoreServices().getDefaultFeatureType();
435 436
		} catch (DataException e) {
436 437
			throw new PerformEditingException(this.getName(), e);
437 438
		}
......
449 450

  
450 451
		try {
451 452

  
452
			FeatureSet set = this.store.getFeatureSet();
453
			FeatureSet set = this.getFeatureStore().getFeatureSet();
453 454
			writer = new SHPFeatureWriter(this.getName());
454 455

  
455
			SHPStoreParameters tmpParams = (SHPStoreParameters) this.shpParams
456
			SHPStoreParameters shpParams = this.getShpParameters();
457
			SHPStoreParameters tmpParams = (SHPStoreParameters) shpParams
456 458
					.getCopy();
457 459
			tmpParams.setDBFFileName(tmpParams.getDBFFileName() + ".tmp");
458 460
			tmpParams.setSHPFileName(tmpParams.getSHPFileName() + ".tmp");
......
471 473
			this.close();
472 474
			this.resourceCloseRequest();
473 475

  
474
			if (!this.shpParams.getDBFFile().delete()) {
476
			if (!shpParams.getDBFFile().delete()) {
475 477
				throw new PerformEditingException(this.getName(),
476
						new IOException(this.shpParams.getDBFFileName()));
478
						new IOException(shpParams.getDBFFileName()));
477 479
			}
478
			if (!this.shpParams.getSHPFile().delete()) {
480
			if (!shpParams.getSHPFile().delete()) {
479 481
				throw new PerformEditingException(this.getName(),
480
						new IOException(this.shpParams.getSHPFileName()));
482
						new IOException(shpParams.getSHPFileName()));
481 483
			}
482
			if (!this.shpParams.getSHXFile().delete()) {
484
			if (!shpParams.getSHXFile().delete()) {
483 485
				throw new PerformEditingException(this.getName(),
484
						new IOException(this.shpParams.getSHXFileName()));
486
						new IOException(shpParams.getSHXFileName()));
485 487
			}
486
			if (!tmpParams.getDBFFile().renameTo(this.shpParams.getDBFFile())) {
488
			if (!tmpParams.getDBFFile().renameTo(shpParams.getDBFFile())) {
487 489
				throw new PerformEditingException(this.getName(),
488
						new IOException(this.shpParams.getSHPFileName()));
490
						new IOException(shpParams.getSHPFileName()));
489 491
			}
490
			if (!tmpParams.getSHPFile().renameTo(this.shpParams.getSHPFile())) {
492
			if (!tmpParams.getSHPFile().renameTo(shpParams.getSHPFile())) {
491 493
				throw new PerformEditingException(this.getName(),
492
						new IOException(this.shpParams.getSHPFileName()));
494
						new IOException(shpParams.getSHPFileName()));
493 495
			}
494
			if (!tmpParams.getSHXFile().renameTo(this.shpParams.getSHXFile())) {
496
			if (!tmpParams.getSHXFile().renameTo(shpParams.getSHXFile())) {
495 497
				throw new PerformEditingException(this.getName(),
496
						new IOException(this.shpParams.getSHXFileName()));
498
						new IOException(shpParams.getSHXFileName()));
497 499
			}
498 500

  
499 501

  
......
517 519

  
518 520
	public Envelope getEnvelope() throws DataException {
519 521
		this.open();
520
		return (Envelope) this.metadata.getDynValue("Envelope");
522
		return (Envelope) this.getDynValue("Envelope");
521 523
	}
522 524

  
523
	public void loadFromState(PersistentState state) throws PersistenceException {
524
		// TODO Auto-generated method stub
525
		super.loadFromState(state);
526
	}
527

  
528
	public PersistentState getState() throws PersistenceException {
529
		// TODO Auto-generated method stub
530
		return super.getState();
531
	}
532

  
533 525
	public void append(FeatureProvider featureProvider) throws DataException {
534 526
		this.resourcesBegin();
535 527
		try {
536
			writer.append(store.createFeature(featureProvider));
528
			writer
529
					.append(this.getStoreServices()
530
					.createFeature(
531
							featureProvider));
537 532
		} finally {
538 533
			this.resourcesEnd();
539 534
		}
......
544 539
		this.resourcesBegin();
545 540
		try {
546 541

  
547
			FeatureType fType = this.store.getDefaultFeatureType();
542
			FeatureStore store = this.getFeatureStore();
543
			FeatureType fType = store.getDefaultFeatureType();
548 544

  
549 545
			// TODO Comprobar el campo de geometria
550 546

  
551 547
			EditableFeatureType dbfFtype = fType.getEditable();
552 548

  
553 549
			removeGeometryColumn(dbfFtype);
554
			FeatureSet set = this.store.getFeatureSet();
550
			FeatureSet set = store.getFeatureSet();
555 551

  
556 552
			writer = new SHPFeatureWriter(this.getName());
557 553

  
558
			writer.begin(this.shpParams, fType, dbfFtype, set.getSize());
554
			writer.begin(getShpParameters(), fType, dbfFtype, set.getSize());
559 555
		} finally {
560 556
			this.resourcesEnd();
561 557
		}
......
573 569

  
574 570
	}
575 571

  
576
	/*
577
	 * (non-Javadoc)
578
	 *
579
	 * @see org.gvsig.metadata.Metadata#getMetadataName()
580
	 */
581
	public String getMetadataName() {
582
		return this.shpParams.getSHPFile().getName();
583
	}
584

  
585 572
	public Object getSourceId() {
586 573
		return this.getShpParameters().getFile();
587 574
	}

Also available in: Unified diff