svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / feature / spi / DefaultFeatureProvider.java @ 41212
History | View | Annotate | Download (6.01 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.feature.spi; |
25 |
|
26 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
27 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
28 |
import org.gvsig.fmap.dal.feature.FeatureType; |
29 |
import org.gvsig.fmap.dal.feature.exception.SetReadOnlyAttributeException; |
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.primitive.Envelope; |
32 |
|
33 |
/**
|
34 |
* Default implementation for {@link FeatureProvider}
|
35 |
*
|
36 |
*/
|
37 |
public class DefaultFeatureProvider implements FeatureProvider { |
38 |
|
39 |
protected FeatureType featureType;
|
40 |
protected boolean[] nulls; |
41 |
protected Object[] values; |
42 |
protected Geometry defaultGeometry;
|
43 |
protected Envelope envelope;
|
44 |
private Object oid; |
45 |
private boolean isNew=false; |
46 |
|
47 |
public DefaultFeatureProvider(FeatureType type) {
|
48 |
if (type instanceof EditableFeatureType) { |
49 |
throw new IllegalArgumentException("type can't by editable."); |
50 |
} |
51 |
this.featureType = type;
|
52 |
this.values = new Object[featureType.size()]; |
53 |
this.nulls = new boolean[featureType.size()]; |
54 |
|
55 |
this.envelope = null; |
56 |
this.defaultGeometry = null; |
57 |
this.oid = null; |
58 |
} |
59 |
|
60 |
public DefaultFeatureProvider(FeatureType type, Object oid) { |
61 |
this(type);
|
62 |
this.oid = oid;
|
63 |
} |
64 |
|
65 |
/*
|
66 |
* (non-Javadoc)
|
67 |
*
|
68 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(int,
|
69 |
* java.lang.Object)
|
70 |
*/
|
71 |
public void set(int i, Object value) { |
72 |
FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(i); |
73 |
if (attribute.getEvaluator() != null) { |
74 |
return;
|
75 |
} |
76 |
if (featureType.getDefaultGeometryAttributeIndex() == i) {
|
77 |
defaultGeometry = (Geometry) value; |
78 |
envelope = null;
|
79 |
} |
80 |
if (value == null) { |
81 |
nulls[i] = true;
|
82 |
values[i] = attribute.getDefaultValue(); |
83 |
} else {
|
84 |
values[i] = value; |
85 |
nulls[i] = false;
|
86 |
} |
87 |
} |
88 |
|
89 |
/*
|
90 |
* (non-Javadoc)
|
91 |
*
|
92 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(java.lang.String,
|
93 |
* java.lang.Object)
|
94 |
*/
|
95 |
public void set(String name, Object value) { |
96 |
set(featureType.getIndex(name), value); |
97 |
} |
98 |
|
99 |
/*
|
100 |
* (non-Javadoc)
|
101 |
*
|
102 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(int)
|
103 |
*/
|
104 |
public Object get(int i) { |
105 |
return values[i];
|
106 |
} |
107 |
|
108 |
/*
|
109 |
* (non-Javadoc)
|
110 |
*
|
111 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(java.lang.String)
|
112 |
*/
|
113 |
public Object get(String name) { |
114 |
FeatureAttributeDescriptor featureAttributeDescriptor = featureType.getAttributeDescriptor(name); |
115 |
return values[featureAttributeDescriptor.getIndex()];
|
116 |
} |
117 |
|
118 |
/*
|
119 |
* (non-Javadoc)
|
120 |
*
|
121 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getType()
|
122 |
*/
|
123 |
public FeatureType getType() {
|
124 |
return featureType;
|
125 |
} |
126 |
|
127 |
/*
|
128 |
* (non-Javadoc)
|
129 |
*
|
130 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getCopy()
|
131 |
*/
|
132 |
public FeatureProvider getCopy() {
|
133 |
DefaultFeatureProvider data = new DefaultFeatureProvider(
|
134 |
this.getType());
|
135 |
return getCopy(data);
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* Copy values from current instance to <code>data</code>
|
140 |
*/
|
141 |
protected FeatureProvider getCopy(DefaultFeatureProvider data) {
|
142 |
data.oid = this.oid;
|
143 |
System.arraycopy(this.values, 0, data.values, 0, this.values.length); |
144 |
data.defaultGeometry = this.defaultGeometry;
|
145 |
data.envelope = this.envelope;
|
146 |
data.isNew=this.isNew;
|
147 |
return data;
|
148 |
} |
149 |
|
150 |
/*
|
151 |
* (non-Javadoc)
|
152 |
*
|
153 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultEnvelope()
|
154 |
*/
|
155 |
public Envelope getDefaultEnvelope() {
|
156 |
if (envelope == null && getDefaultGeometry() != null) { |
157 |
envelope = getDefaultGeometry().getEnvelope(); |
158 |
} |
159 |
return envelope;
|
160 |
} |
161 |
|
162 |
/*
|
163 |
* (non-Javadoc)
|
164 |
*
|
165 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultGeometry()
|
166 |
*/
|
167 |
public Geometry getDefaultGeometry() {
|
168 |
return this.defaultGeometry; |
169 |
} |
170 |
|
171 |
/*
|
172 |
* (non-Javadoc)
|
173 |
*
|
174 |
* @see
|
175 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultEnvelope(org
|
176 |
* .gvsig.fmap.geom.primitive.Envelope)
|
177 |
*/
|
178 |
public void setDefaultEnvelope(Envelope envelope) { |
179 |
this.envelope = envelope;
|
180 |
} |
181 |
|
182 |
/*
|
183 |
* (non-Javadoc)
|
184 |
*
|
185 |
* @see
|
186 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultGeometry(org
|
187 |
* .gvsig.fmap.geom.Geometry)
|
188 |
*/
|
189 |
public void setDefaultGeometry(Geometry geom) { |
190 |
int i = featureType.getDefaultGeometryAttributeIndex();
|
191 |
this.set(i, geom);
|
192 |
} |
193 |
|
194 |
/*
|
195 |
* (non-Javadoc)
|
196 |
*
|
197 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(int)
|
198 |
*/
|
199 |
public boolean isNull(int i) { |
200 |
return nulls[i];
|
201 |
} |
202 |
|
203 |
/*
|
204 |
* (non-Javadoc)
|
205 |
*
|
206 |
* @see
|
207 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(java.lang.String)
|
208 |
*/
|
209 |
public boolean isNull(String name) { |
210 |
int i = featureType.getIndex(name);
|
211 |
return isNull(i);
|
212 |
} |
213 |
|
214 |
/*
|
215 |
* (non-Javadoc)
|
216 |
*
|
217 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getOID()
|
218 |
*/
|
219 |
public Object getOID() { |
220 |
return this.oid; |
221 |
} |
222 |
|
223 |
/*
|
224 |
* (non-Javadoc)
|
225 |
*
|
226 |
* @see
|
227 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setOID(java.lang.Object)
|
228 |
*/
|
229 |
public void setOID(Object oid) { |
230 |
this.oid = oid;
|
231 |
} |
232 |
|
233 |
/*
|
234 |
* (non-Javadoc)
|
235 |
*
|
236 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNew()
|
237 |
*/
|
238 |
public boolean isNew(){ |
239 |
return isNew;
|
240 |
} |
241 |
|
242 |
/*
|
243 |
* (non-Javadoc)
|
244 |
*
|
245 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#setNew(boolean)
|
246 |
*/
|
247 |
public void setNew(boolean isNew){ |
248 |
this.isNew=isNew;
|
249 |
} |
250 |
} |