Revision 47436 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPFeatureProvider.java
SHPFeatureProvider.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* gvSIG. Desktop Geographic Information System. |
3 | 3 |
* |
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
|
4 |
* Copyright (C) 2007-2023 gvSIG Association.
|
|
5 | 5 |
* |
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
... | ... | |
26 | 26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 | 27 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
28 | 28 |
import org.gvsig.fmap.dal.feature.FeatureType; |
29 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
|
30 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
29 |
import org.gvsig.fmap.dal.store.dbf.DBFFeatureProvider; |
|
31 | 30 |
import org.gvsig.fmap.geom.Geometry; |
32 | 31 |
import org.gvsig.fmap.geom.primitive.Envelope; |
33 | 32 |
|
34 |
public class SHPFeatureProvider extends DefaultFeatureProvider { |
|
35 |
protected SHPStoreProvider store; |
|
36 |
protected boolean loading; |
|
37 |
protected boolean loaded; |
|
33 |
public class SHPFeatureProvider extends DBFFeatureProvider { |
|
38 | 34 |
|
35 |
public SHPFeatureProvider(SHPStoreProvider store, FeatureType providerFeatureType, FeatureType storeFeatureType) { |
|
36 |
super(store, providerFeatureType, storeFeatureType); |
|
37 |
} |
|
39 | 38 |
|
40 |
public SHPFeatureProvider(SHPStoreProvider store, FeatureType type) { |
|
41 |
super(type); |
|
42 |
this.store = store; |
|
43 |
loading = false; |
|
44 |
loaded = false; |
|
45 |
} |
|
46 |
|
|
47 |
protected void load() { |
|
48 |
if (loading || loaded || this.isNew()) { |
|
49 |
return; |
|
50 |
} |
|
51 |
loading = true; |
|
52 |
try { |
|
53 |
this.store.loadFeatureProviderByIndex(this); |
|
54 |
} catch (DataException e) { |
|
55 |
throw new ReadRuntimeException(getNameForMessages(), this.getOID(), e); |
|
56 |
} finally { |
|
57 |
loading = false; |
|
58 |
loaded = true; |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
protected String getNameForMessages() { |
|
63 |
// Solo con proposito de mostrar en mensajes de error. |
|
64 |
try { |
|
65 |
return this.store.getName(); |
|
66 |
} catch(Exception ex) { |
|
67 |
return "unknown"; |
|
68 |
} |
|
39 |
@Override |
|
40 |
protected void load() { |
|
41 |
if (loading || loaded || this.isNew()) { |
|
42 |
return; |
|
69 | 43 |
} |
44 |
loading = true; |
|
45 |
try { |
|
46 |
((SHPStoreProvider)this.store).loadFeatureProviderByIndex(this); |
|
47 |
} catch (DataException e) { |
|
48 |
throw new ReadRuntimeException(getNameForMessages(), this.getOID(), e); |
|
49 |
} finally { |
|
50 |
loading = false; |
|
51 |
loaded = true; |
|
52 |
} |
|
53 |
} |
|
70 | 54 |
|
71 |
public void set(int i, Object value) { |
|
72 |
this.load(); |
|
73 |
super.set(i, value); |
|
74 |
} |
|
75 | 55 |
|
76 |
public void set(String name, Object value) { |
|
77 |
this.load(); |
|
78 |
super.set(featureType.getIndex(name), value); |
|
79 |
} |
|
56 |
@Override |
|
57 |
public Geometry getDefaultGeometry() { |
|
58 |
this.load(); |
|
59 |
Geometry geom = this.defaultGeometry; |
|
60 |
if (geom != null && geom.getProjection() == null) { |
|
61 |
geom.setProjection(((SHPStoreProvider) this.store).getProjection()); |
|
62 |
} |
|
63 |
return geom; |
|
64 |
} |
|
80 | 65 |
|
81 |
public Object get(int i) {
|
|
82 |
this.load();
|
|
83 |
return super.get(i);
|
|
84 |
}
|
|
66 |
@Override
|
|
67 |
public Envelope getDefaultEnvelope() {
|
|
68 |
return this.envelope;
|
|
69 |
}
|
|
85 | 70 |
|
86 |
public Object get(String name) { |
|
87 |
this.load(); |
|
88 |
return super.get(name); |
|
89 |
} |
|
90 |
|
|
91 |
public Geometry getDefaultGeometry() { |
|
92 |
this.load(); |
|
93 |
Geometry geom = this.defaultGeometry; |
|
94 |
if( geom!=null && geom.getProjection()==null ) { |
|
95 |
geom.setProjection(this.store.getProjection()); |
|
96 |
} |
|
97 |
return geom; |
|
98 |
} |
|
99 |
|
|
100 |
public Envelope getDefaultEnvelope() { |
|
101 |
return this.envelope; |
|
102 |
} |
|
103 |
|
|
104 |
public void setOID(Object oid) { |
|
105 |
this.loaded = false; |
|
106 |
super.setOID(oid); |
|
107 |
} |
|
108 |
|
|
109 |
public FeatureProvider getCopy() { |
|
110 |
this.load(); |
|
111 |
return super.getCopy(); |
|
112 |
} |
|
113 |
|
|
114 | 71 |
} |
Also available in: Unified diff