svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.dbf / src / main / java / org / gvsig / fmap / dal / store / dbf / DBFFeatureProvider.java @ 47436
History | View | Annotate | Download (3.66 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.store.dbf; |
25 |
|
26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
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; |
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.primitive.Envelope; |
33 |
|
34 |
public class DBFFeatureProvider extends DefaultFeatureProvider { |
35 |
|
36 |
protected DBFStoreProvider store;
|
37 |
protected boolean loading; |
38 |
protected boolean loaded; |
39 |
private final FeatureType storeFeatureType; |
40 |
|
41 |
public DBFFeatureProvider(DBFStoreProvider store, FeatureType providerFeatureType, FeatureType storeFeatureType) {
|
42 |
super(providerFeatureType);
|
43 |
this.store = store;
|
44 |
this.storeFeatureType = storeFeatureType;
|
45 |
loading = false;
|
46 |
loaded = false;
|
47 |
} |
48 |
|
49 |
protected void load() { |
50 |
if (loading || loaded || this.isNew()) { |
51 |
return;
|
52 |
} |
53 |
loading = true;
|
54 |
try {
|
55 |
this.store.loadFeatureProviderByIndex(this); |
56 |
} catch (DataException e) {
|
57 |
throw new ReadRuntimeException(getNameForMessages(), this.getOID(), e); |
58 |
} finally {
|
59 |
loading = false;
|
60 |
loaded = true;
|
61 |
} |
62 |
} |
63 |
|
64 |
protected String getNameForMessages() { |
65 |
// Solo con proposito de mostrar en mensajes de error.
|
66 |
try {
|
67 |
return this.store.getName(); |
68 |
} catch (Exception ex) { |
69 |
return "unknown"; |
70 |
} |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void set(int i, Object value) { |
75 |
this.load();
|
76 |
super.set(i, value);
|
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void set(String name, Object value) { |
81 |
this.load();
|
82 |
super.set(featureType.getIndex(name), value);
|
83 |
} |
84 |
|
85 |
@Override
|
86 |
public Object get(int i) { |
87 |
this.load();
|
88 |
return super.get(i); |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public Object get(String name) { |
93 |
this.load();
|
94 |
return super.get(name); |
95 |
} |
96 |
|
97 |
@Override
|
98 |
public Geometry getDefaultGeometry() {
|
99 |
return null; |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public Envelope getDefaultEnvelope() {
|
104 |
return null; |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public void setOID(Object oid) { |
109 |
this.loaded = false; |
110 |
super.setOID(oid);
|
111 |
} |
112 |
|
113 |
@Override
|
114 |
public FeatureProvider getCopy() {
|
115 |
this.load();
|
116 |
return super.getCopy(); |
117 |
} |
118 |
|
119 |
public void setProviderFeatureType(FeatureType featureType) { |
120 |
this.featureType = featureType;
|
121 |
} |
122 |
|
123 |
void setBroken(boolean b) { |
124 |
this.broken = b;
|
125 |
} |
126 |
|
127 |
public FeatureType getStoreFeatureType() {
|
128 |
return this.storeFeatureType; |
129 |
} |
130 |
|
131 |
public FeatureType getProviderFeatureType() {
|
132 |
return this.getType(); |
133 |
} |
134 |
|
135 |
} |