Revision 44086 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
DefaultFeatureProvider.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 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.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 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. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.fmap.dal.feature.spi; |
25 | 24 |
|
25 |
import org.gvsig.fmap.dal.DataTypes; |
|
26 | 26 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
27 | 27 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
28 | 28 |
import org.gvsig.fmap.dal.feature.FeatureType; |
29 |
import org.gvsig.fmap.geom.DataTypes; |
|
30 | 29 |
import org.gvsig.fmap.geom.Geometry; |
31 | 30 |
import org.gvsig.fmap.geom.primitive.Envelope; |
31 |
import org.gvsig.timesupport.Time; |
|
32 | 32 |
import org.gvsig.tools.ToolsLocator; |
33 | 33 |
import org.gvsig.tools.dataTypes.CoercionException; |
34 | 34 |
|
... | ... | |
38 | 38 |
*/ |
39 | 39 |
public class DefaultFeatureProvider implements FeatureProvider { |
40 | 40 |
|
41 |
protected FeatureType featureType;
|
|
42 |
protected boolean[] nulls;
|
|
43 |
protected Object[] values;
|
|
44 |
protected Geometry defaultGeometry;
|
|
45 |
protected Envelope envelope;
|
|
46 |
private Object oid;
|
|
47 |
private boolean isNew=false;
|
|
41 |
protected FeatureType featureType;
|
|
42 |
protected boolean[] nulls;
|
|
43 |
protected Object[] values;
|
|
44 |
protected Geometry defaultGeometry;
|
|
45 |
protected Envelope envelope;
|
|
46 |
private Object oid;
|
|
47 |
private boolean isNew = false;
|
|
48 | 48 |
|
49 |
public DefaultFeatureProvider(FeatureType type) {
|
|
50 |
if (type instanceof EditableFeatureType) {
|
|
51 |
throw new IllegalArgumentException("type can't by editable.");
|
|
52 |
}
|
|
53 |
this.featureType = type;
|
|
54 |
this.values = new Object[featureType.size()];
|
|
55 |
this.nulls = new boolean[featureType.size()];
|
|
49 |
public DefaultFeatureProvider(FeatureType type) {
|
|
50 |
if (type instanceof EditableFeatureType) {
|
|
51 |
throw new IllegalArgumentException("type can't by editable.");
|
|
52 |
}
|
|
53 |
this.featureType = type;
|
|
54 |
this.values = new Object[featureType.size()];
|
|
55 |
this.nulls = new boolean[featureType.size()];
|
|
56 | 56 |
|
57 |
this.envelope = null;
|
|
58 |
this.defaultGeometry = null;
|
|
59 |
this.oid = null;
|
|
60 |
}
|
|
57 |
this.envelope = null;
|
|
58 |
this.defaultGeometry = null;
|
|
59 |
this.oid = null;
|
|
60 |
}
|
|
61 | 61 |
|
62 |
public DefaultFeatureProvider(FeatureType type, Object oid) {
|
|
63 |
this(type);
|
|
64 |
this.oid = oid;
|
|
65 |
}
|
|
62 |
public DefaultFeatureProvider(FeatureType type, Object oid) {
|
|
63 |
this(type);
|
|
64 |
this.oid = oid;
|
|
65 |
}
|
|
66 | 66 |
|
67 | 67 |
public DefaultFeatureProvider(FeatureType type, DefaultFeatureProvider data) { |
68 | 68 |
this(type); |
... | ... | |
75 | 75 |
public boolean isReadOnly(int i) { |
76 | 76 |
FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(i); |
77 | 77 |
if (attribute.getEvaluator() != null) { |
78 |
return true;
|
|
78 |
return true; |
|
79 | 79 |
} |
80 | 80 |
return false; |
81 | 81 |
} |
82 | 82 |
|
83 |
/* |
|
84 |
* (non-Javadoc) |
|
85 |
* |
|
86 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(int, |
|
87 |
* java.lang.Object) |
|
88 |
*/ |
|
89 |
public void set(int i, Object value) { |
|
83 |
@Override |
|
84 |
public void set(int i, Object value) { |
|
90 | 85 |
FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(i); |
91 |
if( this.isReadOnly(i) ) {
|
|
92 |
return;
|
|
93 |
}
|
|
94 |
if (featureType.getDefaultGeometryAttributeIndex() == i) {
|
|
95 |
if( value instanceof Geometry ) {
|
|
86 |
if (this.isReadOnly(i)) {
|
|
87 |
return;
|
|
88 |
}
|
|
89 |
if (featureType.getDefaultGeometryAttributeIndex() == i) {
|
|
90 |
if (value instanceof Geometry) {
|
|
96 | 91 |
defaultGeometry = (Geometry) value; |
97 | 92 |
} else { |
98 | 93 |
try { |
... | ... | |
102 | 97 |
} |
103 | 98 |
} |
104 | 99 |
envelope = null; |
105 |
}
|
|
106 |
if (value == null) {
|
|
107 |
nulls[i] = true;
|
|
108 |
values[i] = attribute.getDefaultValue();
|
|
109 |
} else {
|
|
110 |
values[i] = value;
|
|
111 |
nulls[i] = false;
|
|
112 |
}
|
|
113 |
}
|
|
100 |
}
|
|
101 |
if (value == null) {
|
|
102 |
nulls[i] = true;
|
|
103 |
values[i] = attribute.getDefaultValue();
|
|
104 |
} else {
|
|
105 |
values[i] = value;
|
|
106 |
nulls[i] = false;
|
|
107 |
}
|
|
108 |
}
|
|
114 | 109 |
|
115 |
/*
|
|
116 |
* (non-Javadoc)
|
|
117 |
*
|
|
118 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(java.lang.String,
|
|
119 |
* java.lang.Object)
|
|
120 |
*/
|
|
121 |
public void set(String name, Object value) {
|
|
122 |
set(featureType.getIndex(name), value);
|
|
123 |
}
|
|
110 |
/*
|
|
111 |
* (non-Javadoc)
|
|
112 |
*
|
|
113 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(java.lang.String,
|
|
114 |
* java.lang.Object)
|
|
115 |
*/
|
|
116 |
public void set(String name, Object value) {
|
|
117 |
set(featureType.getIndex(name), value);
|
|
118 |
}
|
|
124 | 119 |
|
125 |
/*
|
|
126 |
* (non-Javadoc)
|
|
127 |
*
|
|
128 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(int)
|
|
129 |
*/
|
|
130 |
public Object get(int i) {
|
|
131 |
return values[i];
|
|
132 |
}
|
|
120 |
/*
|
|
121 |
* (non-Javadoc)
|
|
122 |
*
|
|
123 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(int)
|
|
124 |
*/
|
|
125 |
public Object get(int i) {
|
|
126 |
return values[i];
|
|
127 |
}
|
|
133 | 128 |
|
134 |
/*
|
|
135 |
* (non-Javadoc)
|
|
136 |
*
|
|
137 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(java.lang.String)
|
|
138 |
*/
|
|
139 |
public Object get(String name) {
|
|
140 |
FeatureAttributeDescriptor featureAttributeDescriptor = featureType.getAttributeDescriptor(name);
|
|
141 |
return values[featureAttributeDescriptor.getIndex()];
|
|
142 |
}
|
|
129 |
/*
|
|
130 |
* (non-Javadoc)
|
|
131 |
*
|
|
132 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(java.lang.String)
|
|
133 |
*/
|
|
134 |
public Object get(String name) {
|
|
135 |
FeatureAttributeDescriptor featureAttributeDescriptor = featureType.getAttributeDescriptor(name);
|
|
136 |
return values[featureAttributeDescriptor.getIndex()];
|
|
137 |
}
|
|
143 | 138 |
|
144 |
/*
|
|
145 |
* (non-Javadoc)
|
|
146 |
*
|
|
147 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getType()
|
|
148 |
*/
|
|
149 |
public FeatureType getType() {
|
|
150 |
return featureType;
|
|
151 |
}
|
|
139 |
/*
|
|
140 |
* (non-Javadoc)
|
|
141 |
*
|
|
142 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getType()
|
|
143 |
*/
|
|
144 |
public FeatureType getType() {
|
|
145 |
return featureType;
|
|
146 |
}
|
|
152 | 147 |
|
153 |
/*
|
|
154 |
* (non-Javadoc)
|
|
155 |
*
|
|
156 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getCopy()
|
|
157 |
*/
|
|
158 |
public FeatureProvider getCopy() {
|
|
159 |
DefaultFeatureProvider data = new DefaultFeatureProvider(
|
|
160 |
this.getType());
|
|
161 |
return getCopy(data);
|
|
162 |
}
|
|
148 |
/*
|
|
149 |
* (non-Javadoc)
|
|
150 |
*
|
|
151 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getCopy()
|
|
152 |
*/
|
|
153 |
public FeatureProvider getCopy() {
|
|
154 |
DefaultFeatureProvider data = new DefaultFeatureProvider(
|
|
155 |
this.getType());
|
|
156 |
return getCopy(data);
|
|
157 |
}
|
|
163 | 158 |
|
164 |
/**
|
|
165 |
* Copy values from current instance to <code>data</code>
|
|
166 |
*/
|
|
167 |
protected FeatureProvider getCopy(DefaultFeatureProvider data) {
|
|
168 |
data.oid = this.oid;
|
|
169 |
System.arraycopy(this.values, 0, data.values, 0, this.values.length);
|
|
170 |
data.defaultGeometry = this.defaultGeometry;
|
|
171 |
data.envelope = this.envelope;
|
|
172 |
data.isNew=this.isNew;
|
|
173 |
return data;
|
|
174 |
}
|
|
159 |
/**
|
|
160 |
* Copy values from current instance to <code>data</code>
|
|
161 |
*/
|
|
162 |
protected FeatureProvider getCopy(DefaultFeatureProvider data) {
|
|
163 |
data.oid = this.oid;
|
|
164 |
System.arraycopy(this.values, 0, data.values, 0, this.values.length);
|
|
165 |
data.defaultGeometry = this.defaultGeometry;
|
|
166 |
data.envelope = this.envelope;
|
|
167 |
data.isNew = this.isNew;
|
|
168 |
return data;
|
|
169 |
}
|
|
175 | 170 |
|
176 |
/*
|
|
177 |
* (non-Javadoc)
|
|
178 |
*
|
|
179 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultEnvelope()
|
|
180 |
*/
|
|
181 |
public Envelope getDefaultEnvelope() {
|
|
182 |
if (envelope == null && getDefaultGeometry() != null) {
|
|
183 |
envelope = getDefaultGeometry().getEnvelope();
|
|
184 |
}
|
|
185 |
return envelope;
|
|
186 |
}
|
|
171 |
/*
|
|
172 |
* (non-Javadoc)
|
|
173 |
*
|
|
174 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultEnvelope()
|
|
175 |
*/
|
|
176 |
public Envelope getDefaultEnvelope() {
|
|
177 |
if (envelope == null && getDefaultGeometry() != null) {
|
|
178 |
envelope = getDefaultGeometry().getEnvelope();
|
|
179 |
}
|
|
180 |
return envelope;
|
|
181 |
}
|
|
187 | 182 |
|
188 |
/*
|
|
189 |
* (non-Javadoc)
|
|
190 |
*
|
|
191 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultGeometry()
|
|
192 |
*/
|
|
193 |
public Geometry getDefaultGeometry() {
|
|
194 |
return this.defaultGeometry;
|
|
195 |
}
|
|
183 |
/*
|
|
184 |
* (non-Javadoc)
|
|
185 |
*
|
|
186 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultGeometry()
|
|
187 |
*/
|
|
188 |
public Geometry getDefaultGeometry() {
|
|
189 |
return this.defaultGeometry; |
|
190 |
}
|
|
196 | 191 |
|
197 |
/* |
|
198 |
* (non-Javadoc) |
|
199 |
* |
|
200 |
* @see |
|
201 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultEnvelope(org |
|
202 |
* .gvsig.fmap.geom.primitive.Envelope) |
|
203 |
*/ |
|
204 |
public void setDefaultEnvelope(Envelope envelope) { |
|
205 |
this.envelope = envelope; |
|
206 |
} |
|
192 |
@Override |
|
193 |
public Time getDefaultTime() { |
|
194 |
int index = featureType.getDefaultTimeAttributeIndex(); |
|
195 |
Object value = this.get(index); |
|
196 |
if (! (value instanceof Time) ) { |
|
197 |
try { |
|
198 |
value = (Time) ToolsLocator.getDataTypesManager().coerce(DataTypes.INSTANT, value); |
|
199 |
} catch (CoercionException ex) { |
|
207 | 200 |
|
208 |
/* |
|
209 |
* (non-Javadoc) |
|
210 |
* |
|
211 |
* @see |
|
212 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultGeometry(org |
|
213 |
* .gvsig.fmap.geom.Geometry) |
|
214 |
*/ |
|
215 |
public void setDefaultGeometry(Geometry geom) { |
|
216 |
int i = featureType.getDefaultGeometryAttributeIndex(); |
|
217 |
this.set(i, geom); |
|
218 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
return (Time) value; |
|
204 |
} |
|
219 | 205 |
|
220 |
/* |
|
221 |
* (non-Javadoc) |
|
222 |
* |
|
223 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(int) |
|
224 |
*/ |
|
225 |
public boolean isNull(int i) { |
|
226 |
return nulls[i]; |
|
227 |
} |
|
206 |
/* |
|
207 |
* (non-Javadoc) |
|
208 |
* |
|
209 |
* @see |
|
210 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultEnvelope(org |
|
211 |
* .gvsig.fmap.geom.primitive.Envelope) |
|
212 |
*/ |
|
213 |
public void setDefaultEnvelope(Envelope envelope) { |
|
214 |
this.envelope = envelope; |
|
215 |
} |
|
228 | 216 |
|
229 |
/* |
|
230 |
* (non-Javadoc) |
|
231 |
* |
|
232 |
* @see |
|
233 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(java.lang.String) |
|
234 |
*/ |
|
235 |
public boolean isNull(String name) { |
|
236 |
int i = featureType.getIndex(name); |
|
237 |
return isNull(i); |
|
238 |
} |
|
217 |
@Override |
|
218 |
public void setDefaultGeometry(Geometry geom) { |
|
219 |
int i = featureType.getDefaultGeometryAttributeIndex(); |
|
220 |
this.set(i, geom); |
|
221 |
} |
|
239 | 222 |
|
240 |
/* |
|
241 |
* (non-Javadoc) |
|
242 |
* |
|
243 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getOID() |
|
244 |
*/ |
|
245 |
public Object getOID() { |
|
246 |
return this.oid; |
|
247 |
} |
|
223 |
@Override |
|
224 |
public void setDefaultTime(Time time) { |
|
225 |
int i = featureType.getDefaultTimeAttributeIndex(); |
|
226 |
this.set(i, time); |
|
227 |
} |
|
248 | 228 |
|
249 |
/* |
|
250 |
* (non-Javadoc) |
|
251 |
* |
|
252 |
* @see |
|
253 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setOID(java.lang.Object) |
|
254 |
*/ |
|
255 |
public void setOID(Object oid) { |
|
256 |
this.oid = oid; |
|
257 |
} |
|
258 | 229 |
|
259 |
/* |
|
260 |
* (non-Javadoc) |
|
261 |
* |
|
262 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNew() |
|
263 |
*/ |
|
264 |
public boolean isNew(){ |
|
265 |
return isNew; |
|
266 |
} |
|
230 |
public boolean isNull(int i) { |
|
231 |
return nulls[i]; |
|
232 |
} |
|
267 | 233 |
|
268 |
/* |
|
269 |
* (non-Javadoc) |
|
270 |
* |
|
271 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#setNew(boolean) |
|
272 |
*/ |
|
273 |
public void setNew(boolean isNew){ |
|
274 |
this.isNew=isNew; |
|
275 |
} |
|
234 |
/* |
|
235 |
* (non-Javadoc) |
|
236 |
* |
|
237 |
* @see |
|
238 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(java.lang.String) |
|
239 |
*/ |
|
240 |
public boolean isNull(String name) { |
|
241 |
int i = featureType.getIndex(name); |
|
242 |
return isNull(i); |
|
243 |
} |
|
244 |
|
|
245 |
/* |
|
246 |
* (non-Javadoc) |
|
247 |
* |
|
248 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getOID() |
|
249 |
*/ |
|
250 |
public Object getOID() { |
|
251 |
return this.oid; |
|
252 |
} |
|
253 |
|
|
254 |
/* |
|
255 |
* (non-Javadoc) |
|
256 |
* |
|
257 |
* @see |
|
258 |
* org.gvsig.fmap.dal.feature.spi.FeatureProvider#setOID(java.lang.Object) |
|
259 |
*/ |
|
260 |
public void setOID(Object oid) { |
|
261 |
this.oid = oid; |
|
262 |
} |
|
263 |
|
|
264 |
/* |
|
265 |
* (non-Javadoc) |
|
266 |
* |
|
267 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNew() |
|
268 |
*/ |
|
269 |
public boolean isNew() { |
|
270 |
return isNew; |
|
271 |
} |
|
272 |
|
|
273 |
/* |
|
274 |
* (non-Javadoc) |
|
275 |
* |
|
276 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#setNew(boolean) |
|
277 |
*/ |
|
278 |
public void setNew(boolean isNew) { |
|
279 |
this.isNew = isNew; |
|
280 |
} |
|
276 | 281 |
} |
Also available in: Unified diff