svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultFeature.java @ 44086
History | View | Annotate | Download (25.4 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl; |
25 | |||
26 | import java.lang.ref.WeakReference; |
||
27 | 43550 | jjdelcerro | import java.util.ArrayList; |
28 | 40435 | jjdelcerro | import java.util.Date; |
29 | import java.util.Iterator; |
||
30 | import java.util.List; |
||
31 | 43550 | jjdelcerro | import java.util.Map; |
32 | 40435 | jjdelcerro | import org.cresques.cts.IProjection; |
33 | import org.gvsig.fmap.dal.DataTypes; |
||
34 | import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
||
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
37 | import org.gvsig.fmap.dal.feature.Feature; |
||
38 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
39 | 41335 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
40 | import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
||
41 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureReference; |
42 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
43 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
44 | import org.gvsig.fmap.dal.feature.exception.IllegalValueException; |
||
45 | import org.gvsig.fmap.dal.feature.exception.SetReadOnlyAttributeException; |
||
46 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectFeatureFacade; |
47 | 43729 | fdiaz | import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
48 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
49 | import org.gvsig.fmap.geom.Geometry; |
||
50 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
51 | import org.gvsig.timesupport.Instant; |
||
52 | import org.gvsig.timesupport.Interval; |
||
53 | 44086 | jjdelcerro | import org.gvsig.timesupport.Time; |
54 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
55 | import org.gvsig.tools.dataTypes.CoercionException; |
||
56 | import org.gvsig.tools.dataTypes.DataTypesManager; |
||
57 | import org.gvsig.tools.dynobject.DynObject; |
||
58 | import org.gvsig.tools.evaluator.Evaluator; |
||
59 | import org.gvsig.tools.evaluator.EvaluatorData; |
||
60 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
61 | import org.gvsig.tools.exception.BaseException; |
||
62 | import org.gvsig.tools.exception.BaseRuntimeException; |
||
63 | 40876 | jjdelcerro | import org.gvsig.tools.lang.Cloneable; |
64 | 40435 | jjdelcerro | |
65 | 40876 | jjdelcerro | public class DefaultFeature implements Feature, EvaluatorData, Cloneable { |
66 | 40435 | jjdelcerro | |
67 | 43729 | fdiaz | private static DataTypesManager dataTypesManager = null; |
68 | 40435 | jjdelcerro | protected FeatureProvider data;
|
69 | protected FeatureReference reference;
|
||
70 | private WeakReference storeRef; |
||
71 | 43729 | fdiaz | |
72 | 40435 | jjdelcerro | private boolean inserted = false; |
73 | |||
74 | /*
|
||
75 | * Usar con mucha precaucion o mejor no usar. Lo precisa el
|
||
76 | * DefaultFeatureSet en la ordenacion.
|
||
77 | */
|
||
78 | public DefaultFeature(FeatureStore store) {
|
||
79 | this.storeRef = new WeakReference(store); |
||
80 | this.reference = null; |
||
81 | } |
||
82 | |||
83 | public DefaultFeature(FeatureStore store, FeatureProvider data) {
|
||
84 | this.data = data;
|
||
85 | this.storeRef = new WeakReference(store); |
||
86 | this.reference = null; |
||
87 | this.inserted = !data.isNew();
|
||
88 | } |
||
89 | |||
90 | DefaultFeature(DefaultFeature feature) { |
||
91 | this.data = feature.data.getCopy();
|
||
92 | this.storeRef = feature.storeRef;
|
||
93 | this.reference = feature.reference;
|
||
94 | this.inserted = feature.isInserted();
|
||
95 | } |
||
96 | |||
97 | 43729 | fdiaz | public DefaultFeature(FeatureType targetType, Feature sourceFeature) {
|
98 | DefaultFeature defaultFeature = (DefaultFeature)sourceFeature; |
||
99 | this.data = new DefaultFeatureProvider(targetType, (DefaultFeatureProvider)defaultFeature.getData()); |
||
100 | this.storeRef = defaultFeature.storeRef;
|
||
101 | this.reference = defaultFeature.reference;
|
||
102 | this.inserted = defaultFeature.isInserted();
|
||
103 | |||
104 | FeatureType sourceType = sourceFeature.getType(); |
||
105 | |||
106 | for (FeatureAttributeDescriptor targetAttrDescriptor : targetType) {
|
||
107 | if ( targetAttrDescriptor.isAutomatic() ||
|
||
108 | targetAttrDescriptor.isReadOnly() || |
||
109 | targetAttrDescriptor.getEvaluator() != null) {
|
||
110 | continue;
|
||
111 | } |
||
112 | int sourceIndex = sourceType.getIndex(targetAttrDescriptor.getName());
|
||
113 | if (sourceIndex<0){ |
||
114 | continue;
|
||
115 | } |
||
116 | Object value = sourceFeature.get(sourceIndex);
|
||
117 | if (value == null && !targetAttrDescriptor.allowNull()) { |
||
118 | continue;
|
||
119 | } |
||
120 | this.set(targetAttrDescriptor,value);
|
||
121 | } |
||
122 | } |
||
123 | |||
124 | 40435 | jjdelcerro | public void setData(FeatureProvider data) { |
125 | this.data = data;
|
||
126 | this.reference = null; |
||
127 | 43729 | fdiaz | this.inserted = true; |
128 | 40435 | jjdelcerro | } |
129 | |||
130 | public FeatureProvider getData() {
|
||
131 | return this.data; |
||
132 | } |
||
133 | |||
134 | protected DataTypesManager getDataTypesManager() {
|
||
135 | if( dataTypesManager==null ) { |
||
136 | dataTypesManager = ToolsLocator.getDataTypesManager(); |
||
137 | } |
||
138 | return dataTypesManager;
|
||
139 | } |
||
140 | |||
141 | 41335 | jjdelcerro | void set(FeatureAttributeDescriptor attribute, Object value) { |
142 | int i = attribute.getIndex();
|
||
143 | 40435 | jjdelcerro | |
144 | 41335 | jjdelcerro | if ( attribute.isReadOnly() ) {
|
145 | 41823 | jjdelcerro | throw new SetReadOnlyAttributeException(attribute.getName(), this.getType()); |
146 | 41335 | jjdelcerro | } |
147 | FeatureAttributeEmulator emulator = attribute.getFeatureAttributeEmulator(); |
||
148 | if( emulator!= null ) { |
||
149 | emulator.set((EditableFeature) this,value);
|
||
150 | return;
|
||
151 | } |
||
152 | 43729 | fdiaz | |
153 | 41335 | jjdelcerro | if ( value == null ) { |
154 | if ( !attribute.allowNull() ) {
|
||
155 | if ( !attribute.isAutomatic() ) {
|
||
156 | throw new IllegalValueException(attribute, value); |
||
157 | } |
||
158 | } |
||
159 | this.data.set(i, null); |
||
160 | return;
|
||
161 | 40435 | jjdelcerro | |
162 | 41335 | jjdelcerro | } |
163 | 40435 | jjdelcerro | |
164 | 41335 | jjdelcerro | if ( attribute.getFeatureAttributeGetter() != null ) { |
165 | value = attribute.getFeatureAttributeGetter().setter(value); |
||
166 | 40435 | jjdelcerro | } |
167 | 41335 | jjdelcerro | |
168 | 42218 | jjdelcerro | Class objectClass = attribute.getObjectClass();
|
169 | if( objectClass!=null ) { |
||
170 | if ( objectClass.isInstance(value) ) {
|
||
171 | this.data.set(i, value);
|
||
172 | return;
|
||
173 | } |
||
174 | 40435 | jjdelcerro | |
175 | 42218 | jjdelcerro | if ( !objectClass.isInstance(value) ) {
|
176 | try {
|
||
177 | value |
||
178 | = this.getDataTypesManager().coerce(attribute.getType(),
|
||
179 | value); |
||
180 | } catch (CoercionException e) {
|
||
181 | throw new IllegalArgumentException("Can't convert to " |
||
182 | + this.getDataTypesManager().getTypeName(
|
||
183 | attribute.getType()) + " from '"
|
||
184 | + value.getClass().getName() + "' with value '"
|
||
185 | + value.toString() + "'.");
|
||
186 | } |
||
187 | 40435 | jjdelcerro | } |
188 | 41335 | jjdelcerro | } |
189 | 40435 | jjdelcerro | this.data.set(i, value);
|
190 | } |
||
191 | 43729 | fdiaz | |
192 | 40435 | jjdelcerro | private Object get(int index,Class theClass, int type) { |
193 | Object value = this.get(index); |
||
194 | if( theClass.isInstance(value) ) {
|
||
195 | return value;
|
||
196 | } |
||
197 | try {
|
||
198 | return this.getDataTypesManager().coerce(type, value); |
||
199 | } catch (CoercionException e) {
|
||
200 | 43729 | fdiaz | |
201 | 40435 | jjdelcerro | if (value == null) { |
202 | return null; |
||
203 | } |
||
204 | throw new IllegalArgumentException( |
||
205 | "Can't convert to "+theClass.getName()+
|
||
206 | " from '"+value.getClass().getName()+
|
||
207 | "' with value '"+value.toString()+"'."); |
||
208 | } |
||
209 | } |
||
210 | 43729 | fdiaz | |
211 | 40435 | jjdelcerro | // private Object getNumberByType(Number value, int type) {
|
212 | // if (type==DataTypes.DOUBLE){
|
||
213 | // return new Double(value.doubleValue());
|
||
214 | // }else if (type==DataTypes.FLOAT){
|
||
215 | // return new Float(value.floatValue());
|
||
216 | // }else if (type==DataTypes.LONG){
|
||
217 | // return new Long(value.longValue());
|
||
218 | // }else if (type==DataTypes.INT){
|
||
219 | // return new Integer(value.intValue());
|
||
220 | // }else if (type==DataTypes.STRING){
|
||
221 | // return value.toString();
|
||
222 | // }
|
||
223 | // return value;
|
||
224 | // }
|
||
225 | |||
226 | public void initializeValues() { |
||
227 | FeatureType type = this.getType();
|
||
228 | Iterator iterator = type.iterator();
|
||
229 | |||
230 | while (iterator.hasNext()) {
|
||
231 | FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor) iterator |
||
232 | .next(); |
||
233 | if (attribute.isAutomatic() || attribute.isReadOnly()
|
||
234 | || attribute.getEvaluator() != null) {
|
||
235 | continue;
|
||
236 | } |
||
237 | if (attribute.getDefaultValue() == null && !attribute.allowNull()) { |
||
238 | continue;
|
||
239 | } |
||
240 | this.set(attribute, attribute.getDefaultValue());
|
||
241 | } |
||
242 | } |
||
243 | |||
244 | public void clear() { |
||
245 | initializeValues(); |
||
246 | } |
||
247 | |||
248 | public void initializeValues(Feature feature) { |
||
249 | FeatureType myType=this.getType();
|
||
250 | FeatureType type =feature.getType(); |
||
251 | Iterator iterator = type.iterator();
|
||
252 | |||
253 | while (iterator.hasNext()) {
|
||
254 | FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor) iterator |
||
255 | .next(); |
||
256 | FeatureAttributeDescriptor myAttribute=myType.getAttributeDescriptor(attribute.getName()); |
||
257 | if (myAttribute != null) { |
||
258 | this.set(myAttribute, feature.get(attribute.getIndex()));
|
||
259 | } |
||
260 | } |
||
261 | } |
||
262 | |||
263 | |||
264 | public FeatureStore getStore() {
|
||
265 | return (FeatureStore) this.storeRef.get(); |
||
266 | } |
||
267 | |||
268 | public FeatureType getType() {
|
||
269 | return this.data.getType(); |
||
270 | } |
||
271 | |||
272 | public EditableFeature getEditable() {
|
||
273 | return new DefaultEditableFeature(this); |
||
274 | } |
||
275 | |||
276 | public Feature getCopy() {
|
||
277 | return new DefaultFeature(this); |
||
278 | } |
||
279 | 43729 | fdiaz | |
280 | 40876 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
281 | return new DefaultFeature(this); |
||
282 | } |
||
283 | 40435 | jjdelcerro | |
284 | public FeatureReference getReference() {
|
||
285 | if (this.reference == null) { |
||
286 | if (!isInserted()) {
|
||
287 | return null; |
||
288 | } |
||
289 | reference = new DefaultFeatureReference(this); |
||
290 | } |
||
291 | return this.reference; |
||
292 | } |
||
293 | |||
294 | class UnableToGetReferenceException extends BaseRuntimeException { |
||
295 | |||
296 | /**
|
||
297 | 43729 | fdiaz | *
|
298 | 40435 | jjdelcerro | */
|
299 | private static final long serialVersionUID = 1812805035204824163L; |
||
300 | |||
301 | /**
|
||
302 | * @param exception
|
||
303 | */
|
||
304 | public UnableToGetReferenceException(BaseException exception) {
|
||
305 | super("Unable to get reference", "_UnableToGetReferenceException", |
||
306 | serialVersionUID); |
||
307 | this.initCause(exception);
|
||
308 | 43729 | fdiaz | |
309 | 40435 | jjdelcerro | } |
310 | 43729 | fdiaz | |
311 | 40435 | jjdelcerro | } |
312 | 43729 | fdiaz | |
313 | 41251 | jjdelcerro | public void validate(int mode) throws DataException { |
314 | 40435 | jjdelcerro | ((DefaultFeatureType) this.data.getType()).validateFeature(this, mode); |
315 | } |
||
316 | |||
317 | public List getSRSs() { |
||
318 | // TODO Auto-generated method stub
|
||
319 | return null; |
||
320 | } |
||
321 | |||
322 | public Envelope getDefaultEnvelope() {
|
||
323 | 41342 | jjdelcerro | Envelope envelope = this.data.getDefaultEnvelope();
|
324 | if( envelope == null ) { |
||
325 | Geometry geom = this.getDefaultGeometry();
|
||
326 | 41348 | jjdelcerro | if( geom!=null ) { |
327 | envelope = geom.getEnvelope(); |
||
328 | } |
||
329 | 41342 | jjdelcerro | } |
330 | return envelope;
|
||
331 | 40435 | jjdelcerro | } |
332 | |||
333 | 44022 | jjdelcerro | @Override
|
334 | 40435 | jjdelcerro | public Geometry getDefaultGeometry() {
|
335 | 41058 | jjdelcerro | Geometry geom = this.data.getDefaultGeometry();
|
336 | 44022 | jjdelcerro | if( geom == null ) { |
337 | int i = this.data.getType().getDefaultGeometryAttributeIndex(); |
||
338 | Object x = this.get(i); |
||
339 | if( x instanceof Geometry ) { |
||
340 | geom = (Geometry) x; |
||
341 | } else {
|
||
342 | geom = this.getGeometry(i);
|
||
343 | } |
||
344 | 43420 | jjdelcerro | } |
345 | 44022 | jjdelcerro | if( geom != null ) { |
346 | if( geom.getProjection()==null ) { |
||
347 | FeatureType type = this.getType();
|
||
348 | DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex()); |
||
349 | IProjection proj = attrdesc.getSRS(this.storeRef);
|
||
350 | geom.setProjection(proj); |
||
351 | } |
||
352 | } |
||
353 | return geom;
|
||
354 | 40435 | jjdelcerro | } |
355 | |||
356 | 44086 | jjdelcerro | @Override
|
357 | public Time getDefaultTime() { |
||
358 | Time time = this.data.getDefaultTime(); |
||
359 | if( time == null ) { |
||
360 | int i = this.data.getType().getDefaultTimeAttributeIndex(); |
||
361 | Object x = this.get(i); |
||
362 | if( x instanceof Time ) { |
||
363 | time = (Time) x;
|
||
364 | } else {
|
||
365 | time = this.getTime(i);
|
||
366 | } |
||
367 | } |
||
368 | return time;
|
||
369 | } |
||
370 | |||
371 | 40435 | jjdelcerro | public IProjection getDefaultSRS() {
|
372 | 44022 | jjdelcerro | IProjection srs = this.data.getType().getDefaultSRS();
|
373 | if( srs == null ) { |
||
374 | FeatureType type = this.getType();
|
||
375 | DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex()); |
||
376 | srs = attrdesc.getSRS(this.storeRef);
|
||
377 | } |
||
378 | return srs;
|
||
379 | 40435 | jjdelcerro | } |
380 | |||
381 | public List getGeometries() { |
||
382 | // TODO Auto-generated method stub
|
||
383 | return null; |
||
384 | } |
||
385 | |||
386 | public Object get(String name) { |
||
387 | int index = this.data.getType().getIndex(name); |
||
388 | if( index < 0 ) { |
||
389 | throw new IllegalArgumentException("Attribute name '"+name+"' not found in the feature."); |
||
390 | } |
||
391 | return this.get(index); |
||
392 | } |
||
393 | 43729 | fdiaz | |
394 | 43550 | jjdelcerro | public boolean has_key(String key) { |
395 | Object x = this.getType().get(key); |
||
396 | return x != null; |
||
397 | } |
||
398 | 43729 | fdiaz | |
399 | 43550 | jjdelcerro | public List<String> keys() { |
400 | List<String> ks = new ArrayList<>(); |
||
401 | for( FeatureAttributeDescriptor attr : this.getType()) { |
||
402 | ks.add(attr.getName()); |
||
403 | } |
||
404 | return ks;
|
||
405 | } |
||
406 | 43729 | fdiaz | |
407 | 43550 | jjdelcerro | public Iterator<String> iterkeys() { |
408 | final Iterator it = this.getType().iterator(); |
||
409 | return new Iterator<String>() { |
||
410 | @Override
|
||
411 | public boolean hasNext() { |
||
412 | return it.hasNext();
|
||
413 | } |
||
414 | 40435 | jjdelcerro | |
415 | 43550 | jjdelcerro | @Override
|
416 | public String next() { |
||
417 | return ((FeatureAttributeDescriptor)it.next()).getName();
|
||
418 | } |
||
419 | 43561 | jjdelcerro | |
420 | @Override
|
||
421 | public void remove() { |
||
422 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
423 | } |
||
424 | 43550 | jjdelcerro | }; |
425 | } |
||
426 | 40435 | jjdelcerro | |
427 | 43550 | jjdelcerro | public Iterator iteritems() { |
428 | final Iterator it = this.getType().iterator(); |
||
429 | return new Iterator<Map.Entry>() { |
||
430 | @Override
|
||
431 | public boolean hasNext() { |
||
432 | return it.hasNext();
|
||
433 | } |
||
434 | |||
435 | @Override
|
||
436 | public Map.Entry next() { |
||
437 | final String name = ((FeatureAttributeDescriptor)it.next()).getName(); |
||
438 | return new Map.Entry<String, Object>() { |
||
439 | @Override
|
||
440 | public String getKey() { |
||
441 | return name;
|
||
442 | } |
||
443 | |||
444 | @Override
|
||
445 | public Object getValue() { |
||
446 | return get(name);
|
||
447 | } |
||
448 | |||
449 | @Override
|
||
450 | public Object setValue(Object value) { |
||
451 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
452 | } |
||
453 | 43729 | fdiaz | |
454 | 43550 | jjdelcerro | }; |
455 | } |
||
456 | 43561 | jjdelcerro | |
457 | @Override
|
||
458 | public void remove() { |
||
459 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
460 | } |
||
461 | 43729 | fdiaz | }; |
462 | 43550 | jjdelcerro | } |
463 | |||
464 | @Override
|
||
465 | 40435 | jjdelcerro | public Object get(int index) { |
466 | FeatureType type = this.data.getType();
|
||
467 | if( index <0 || index >= type.size() ) { |
||
468 | throw new IllegalArgumentException("Attribute index '"+index+"' out of range (0 to "+this.data.getType().size()+"."); |
||
469 | } |
||
470 | FeatureAttributeDescriptor attribute = type.getAttributeDescriptor(index); |
||
471 | if (!this.data.getType().hasEvaluators()) { |
||
472 | 43729 | fdiaz | return get(attribute, this.data.get(index)); |
473 | } |
||
474 | 40435 | jjdelcerro | Evaluator eval = attribute.getEvaluator(); |
475 | if (eval == null) { |
||
476 | return this.data.get(index); |
||
477 | } else {
|
||
478 | Object value = this.data.get(index); |
||
479 | if (value != null) { // FIXME: para comprobar si esta calculado usar |
||
480 | // un array
|
||
481 | // especifico.
|
||
482 | return get(attribute, this.data.get(index)); |
||
483 | } |
||
484 | try {
|
||
485 | value = eval.evaluate(this);
|
||
486 | } catch (EvaluatorException e) {
|
||
487 | throw new DataEvaluatorRuntimeException(e); |
||
488 | } |
||
489 | this.data.set(index, value);
|
||
490 | return get(attribute, value);
|
||
491 | 43729 | fdiaz | } |
492 | 40435 | jjdelcerro | } |
493 | |||
494 | private Object get(FeatureAttributeDescriptor featureAttributeDescriptor, Object value){ |
||
495 | 41335 | jjdelcerro | FeatureAttributeEmulator emulator = featureAttributeDescriptor.getFeatureAttributeEmulator(); |
496 | if( emulator != null ) { |
||
497 | 44022 | jjdelcerro | value = emulator.get(this);
|
498 | } else {
|
||
499 | FeatureAttributeGetter getter = featureAttributeDescriptor.getFeatureAttributeGetter(); |
||
500 | if( getter != null ) { |
||
501 | value = getter.getter(value); |
||
502 | } |
||
503 | 40435 | jjdelcerro | } |
504 | 44022 | jjdelcerro | if( featureAttributeDescriptor.getType()==DataTypes.GEOMETRY ) {
|
505 | if( value != null ) { |
||
506 | Geometry geom = (Geometry)value; |
||
507 | if( geom.getProjection()==null ) { |
||
508 | IProjection proj = ((DefaultFeatureAttributeDescriptor)featureAttributeDescriptor).getSRS(this.storeRef);
|
||
509 | geom.setProjection(proj); |
||
510 | } |
||
511 | } |
||
512 | 41335 | jjdelcerro | } |
513 | return value;
|
||
514 | 40435 | jjdelcerro | } |
515 | |||
516 | public Object[] getArray(String name) { |
||
517 | return this.getArray(this.data.getType().getIndex(name)); |
||
518 | } |
||
519 | |||
520 | public Object[] getArray(int index) { |
||
521 | return (Object[]) this.get(index); |
||
522 | } |
||
523 | |||
524 | public boolean getBoolean(String name) { |
||
525 | return this.getBoolean(this.data.getType().getIndex(name)); |
||
526 | } |
||
527 | |||
528 | public boolean getBoolean(int index) { |
||
529 | Boolean value = ((Boolean) this.get(index,Boolean.class,DataTypes.BOOLEAN)); |
||
530 | if (value == null) { |
||
531 | return false; |
||
532 | } |
||
533 | return value.booleanValue();
|
||
534 | } |
||
535 | |||
536 | public byte getByte(String name) { |
||
537 | return this.getByte(this.data.getType().getIndex(name)); |
||
538 | } |
||
539 | |||
540 | public byte getByte(int index) { |
||
541 | Byte value = ((Byte) this.get(index,Byte.class,DataTypes.BYTE)); |
||
542 | if (value == null) { |
||
543 | return 0; |
||
544 | } |
||
545 | return value.byteValue();
|
||
546 | } |
||
547 | |||
548 | public Date getDate(String name) { |
||
549 | return this.getDate(this.data.getType().getIndex(name)); |
||
550 | } |
||
551 | |||
552 | public Date getDate(int index) { |
||
553 | Date value = ((Date) this.get(index,Date.class,DataTypes.DATE)); |
||
554 | |||
555 | return value;
|
||
556 | } |
||
557 | |||
558 | public double getDouble(String name) { |
||
559 | return this.getDouble(this.data.getType().getIndex(name)); |
||
560 | } |
||
561 | |||
562 | public double getDouble(int index) { |
||
563 | 43729 | fdiaz | |
564 | 40435 | jjdelcerro | Double value = ((Double) this.get(index,Double.class,DataTypes.DOUBLE)); |
565 | if (value == null) { |
||
566 | return 0; |
||
567 | } |
||
568 | return value.doubleValue();
|
||
569 | } |
||
570 | |||
571 | public Feature getFeature(String name) { |
||
572 | return this.getFeature(this.data.getType().getIndex(name)); |
||
573 | } |
||
574 | |||
575 | public Feature getFeature(int index) { |
||
576 | return (Feature) this.get(index); |
||
577 | } |
||
578 | |||
579 | public float getFloat(String name) { |
||
580 | return this.getFloat(this.data.getType().getIndex(name)); |
||
581 | } |
||
582 | |||
583 | public float getFloat(int index) { |
||
584 | Float value = ((Float) this.get(index,Float.class,DataTypes.FLOAT)); |
||
585 | if (value == null) { |
||
586 | return 0; |
||
587 | } |
||
588 | return value.floatValue();
|
||
589 | } |
||
590 | |||
591 | public Geometry getGeometry(String name) { |
||
592 | return this.getGeometry(this.data.getType().getIndex(name)); |
||
593 | } |
||
594 | |||
595 | public Geometry getGeometry(int index) { |
||
596 | return (Geometry) this.get(index,Geometry.class,DataTypes.GEOMETRY); |
||
597 | } |
||
598 | |||
599 | public int getInt(String name) { |
||
600 | return this.getInt(this.data.getType().getIndex(name)); |
||
601 | } |
||
602 | |||
603 | public int getInt(int index) { |
||
604 | Integer value = ((Integer) this.get(index,Integer.class,DataTypes.INT)); |
||
605 | if (value == null) { |
||
606 | return 0; |
||
607 | } |
||
608 | return ((Integer)value).intValue(); |
||
609 | } |
||
610 | |||
611 | public long getLong(String name) { |
||
612 | return this.getLong(this.data.getType().getIndex(name)); |
||
613 | } |
||
614 | |||
615 | public long getLong(int index) { |
||
616 | Long value = ((Long) this.get(index,Long.class,DataTypes.LONG)); |
||
617 | if (value == null) { |
||
618 | return 0; |
||
619 | } |
||
620 | return value.longValue();
|
||
621 | } |
||
622 | |||
623 | public String getString(String name) { |
||
624 | return this.getString(this.data.getType().getIndex(name)); |
||
625 | } |
||
626 | |||
627 | public String getString(int index) { |
||
628 | return (String) this.get(index,String.class,DataTypes.STRING); |
||
629 | } |
||
630 | |||
631 | public Object getContextValue(String name) { |
||
632 | name = name.toLowerCase(); |
||
633 | if (name.equals("store")) { |
||
634 | return this.getStore(); |
||
635 | } |
||
636 | |||
637 | if (name.equals("featuretype")) { |
||
638 | return this.data.getType(); |
||
639 | } |
||
640 | |||
641 | if (name.equals("feature")) { |
||
642 | return this; |
||
643 | } |
||
644 | |||
645 | throw new IllegalArgumentException(name); |
||
646 | } |
||
647 | |||
648 | public Iterator getDataNames() { |
||
649 | class DataNamesIterator implements Iterator { |
||
650 | Iterator attributeIteraror;
|
||
651 | |||
652 | DataNamesIterator(DefaultFeature feature) { |
||
653 | this.attributeIteraror = feature.getType().iterator();
|
||
654 | } |
||
655 | |||
656 | public boolean hasNext() { |
||
657 | return this.attributeIteraror.hasNext(); |
||
658 | } |
||
659 | |||
660 | public Object next() { |
||
661 | return ((FeatureAttributeDescriptor) this.attributeIteraror |
||
662 | .next()).getName(); |
||
663 | } |
||
664 | |||
665 | public void remove() { |
||
666 | throw new UnsupportedOperationException(); |
||
667 | } |
||
668 | |||
669 | } |
||
670 | return new DataNamesIterator(this); |
||
671 | } |
||
672 | |||
673 | public Object getDataValue(String name) { |
||
674 | name = name.toLowerCase(); |
||
675 | 41542 | jjdelcerro | try {
|
676 | return get(name);
|
||
677 | } catch (IllegalArgumentException ex) { |
||
678 | if( "defaultgeometry".equalsIgnoreCase(name )) { |
||
679 | return this.getDefaultGeometry(); |
||
680 | } |
||
681 | throw ex;
|
||
682 | } |
||
683 | 40435 | jjdelcerro | } |
684 | |||
685 | public Iterator getDataValues() { |
||
686 | class DataValuesIterator implements Iterator { |
||
687 | DefaultFeature feature; |
||
688 | int current = 0; |
||
689 | |||
690 | DataValuesIterator(DefaultFeature feature) { |
||
691 | this.feature = feature;
|
||
692 | } |
||
693 | |||
694 | public boolean hasNext() { |
||
695 | return current < feature.getType().size() - 1; |
||
696 | } |
||
697 | |||
698 | public Object next() { |
||
699 | return feature.get(current++);
|
||
700 | } |
||
701 | |||
702 | public void remove() { |
||
703 | throw new UnsupportedOperationException(); |
||
704 | } |
||
705 | |||
706 | } |
||
707 | return new DataValuesIterator(this); |
||
708 | } |
||
709 | |||
710 | public boolean hasContextValue(String name) { |
||
711 | name = name.toLowerCase(); |
||
712 | if (name.equals("store")) { |
||
713 | return true; |
||
714 | } |
||
715 | |||
716 | if (name.equals("featuretype")) { |
||
717 | return true; |
||
718 | } |
||
719 | |||
720 | if (name.equals("feature")) { |
||
721 | return true; |
||
722 | } |
||
723 | return false; |
||
724 | } |
||
725 | |||
726 | public boolean hasDataValue(String name) { |
||
727 | name = name.toLowerCase(); |
||
728 | return this.data.getType().getIndex(name) >= 0; |
||
729 | } |
||
730 | 43729 | fdiaz | |
731 | 44086 | jjdelcerro | @Override
|
732 | public Time getTime(int index) { |
||
733 | return ((Time) this.get(index,Time.class,DataTypes.INSTANT)); |
||
734 | } |
||
735 | |||
736 | @Override
|
||
737 | public Time getTime(String name) { |
||
738 | return this.getInstant(this.data.getType().getIndex(name)); |
||
739 | } |
||
740 | |||
741 | @Override
|
||
742 | 40435 | jjdelcerro | public Instant getInstant(int index) { |
743 | 44086 | jjdelcerro | return ((Instant) this.get(index,Instant.class,DataTypes.INSTANT)); |
744 | 40435 | jjdelcerro | } |
745 | |||
746 | 44086 | jjdelcerro | @Override
|
747 | 40435 | jjdelcerro | public Instant getInstant(String name) { |
748 | return this.getInstant(this.data.getType().getIndex(name)); |
||
749 | } |
||
750 | |||
751 | 44086 | jjdelcerro | @Override
|
752 | 40435 | jjdelcerro | public Interval getInterval(int index) { |
753 | 44086 | jjdelcerro | return ((Interval) this.get(index,Interval.class,DataTypes.INTERVAL)); |
754 | 40435 | jjdelcerro | } |
755 | |||
756 | 44086 | jjdelcerro | @Override
|
757 | 40435 | jjdelcerro | public Interval getInterval(String name) { |
758 | return this.getInterval(this.data.getType().getIndex(name)); |
||
759 | } |
||
760 | |||
761 | 42775 | jjdelcerro | @Override
|
762 | 40435 | jjdelcerro | public DynObject getAsDynObject() {
|
763 | 42775 | jjdelcerro | DynObjectFeatureFacade facade = new DynObjectFeatureFacade(this); |
764 | 40435 | jjdelcerro | return facade;
|
765 | } |
||
766 | |||
767 | public String toString() { |
||
768 | 40867 | jbadia | // StringBuffer buffer = new StringBuffer("Feature with values: ");
|
769 | StringBuffer buffer = new StringBuffer(""); |
||
770 | 40435 | jjdelcerro | FeatureAttributeDescriptor[] attributeDescriptors =
|
771 | getType().getAttributeDescriptors(); |
||
772 | for (int i = 0; i < attributeDescriptors.length; i++) { |
||
773 | String name = attributeDescriptors[i].getName();
|
||
774 | 40867 | jbadia | //buffer.append(name).append("=").append(get(name));
|
775 | buffer.append(get(name)); |
||
776 | 40435 | jjdelcerro | if (i < attributeDescriptors.length - 1) { |
777 | buffer.append(", ");
|
||
778 | } |
||
779 | } |
||
780 | 40867 | jbadia | return buffer.toString();
|
781 | 40435 | jjdelcerro | } |
782 | 40867 | jbadia | |
783 | |||
784 | 43729 | fdiaz | |
785 | |||
786 | 40867 | jbadia | /**
|
787 | 40435 | jjdelcerro | * @return the inserted
|
788 | */
|
||
789 | public boolean isInserted() { |
||
790 | return inserted;
|
||
791 | } |
||
792 | |||
793 | 43729 | fdiaz | |
794 | 40435 | jjdelcerro | /**
|
795 | * @param inserted the inserted to set
|
||
796 | */
|
||
797 | public void setInserted(boolean inserted) { |
||
798 | this.inserted = inserted;
|
||
799 | } |
||
800 | |||
801 | 43983 | jjdelcerro | @Override
|
802 | 40435 | jjdelcerro | public EvaluatorData getEvaluatorData() {
|
803 | return this; |
||
804 | } |
||
805 | 43983 | jjdelcerro | |
806 | public int size() { |
||
807 | return this.data.getType().size(); |
||
808 | } |
||
809 | |||
810 | public boolean isEmpty() { |
||
811 | return false; |
||
812 | } |
||
813 | |||
814 | public Iterator<String> iterator() { |
||
815 | final Iterator<FeatureAttributeDescriptor> x = this.data.getType().iterator(); |
||
816 | return new Iterator<String>() { |
||
817 | @Override
|
||
818 | public boolean hasNext() { |
||
819 | return x.hasNext();
|
||
820 | } |
||
821 | |||
822 | @Override
|
||
823 | public String next() { |
||
824 | return x.next().getName();
|
||
825 | } |
||
826 | }; |
||
827 | } |
||
828 | |||
829 | public boolean containsKey(String key) { |
||
830 | return this.data.getType().get(key)!=null; |
||
831 | } |
||
832 | 40435 | jjdelcerro | } |