Statistics
| Revision:

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 @ 44226

History | View | Annotate | Download (26.5 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.impl;
25

    
26
import java.lang.ref.WeakReference;
27
import java.util.ArrayList;
28
import java.util.Date;
29
import java.util.Iterator;
30
import java.util.List;
31
import java.util.Map;
32
import org.apache.commons.lang3.StringUtils;
33
import org.cresques.cts.IProjection;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataTypes;
36
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.DataProfile;
39
import org.gvsig.fmap.dal.feature.EditableFeature;
40
import org.gvsig.fmap.dal.feature.Feature;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
42
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
43
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
44
import org.gvsig.fmap.dal.feature.FeatureReference;
45
import org.gvsig.fmap.dal.feature.FeatureStore;
46
import org.gvsig.fmap.dal.feature.FeatureType;
47
import org.gvsig.fmap.dal.feature.exception.IllegalValueException;
48
import org.gvsig.fmap.dal.feature.exception.SetReadOnlyAttributeException;
49
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectFeatureFacade;
50
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
51
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
52
import org.gvsig.fmap.geom.Geometry;
53
import org.gvsig.fmap.geom.primitive.Envelope;
54
import org.gvsig.timesupport.Instant;
55
import org.gvsig.timesupport.Interval;
56
import org.gvsig.timesupport.Time;
57
import org.gvsig.tools.ToolsLocator;
58
import org.gvsig.tools.dataTypes.CoercionException;
59
import org.gvsig.tools.dataTypes.DataTypesManager;
60
import org.gvsig.tools.dynobject.DynObject;
61
import org.gvsig.tools.evaluator.Evaluator;
62
import org.gvsig.tools.evaluator.EvaluatorData;
63
import org.gvsig.tools.evaluator.EvaluatorException;
64
import org.gvsig.tools.exception.BaseException;
65
import org.gvsig.tools.exception.BaseRuntimeException;
66
import org.gvsig.tools.lang.Cloneable;
67

    
68
public class DefaultFeature implements Feature, EvaluatorData, Cloneable {
69

    
70
        private static DataTypesManager dataTypesManager = null;
71
        protected FeatureProvider data;
72
        protected FeatureReference reference;
73
        private WeakReference storeRef;
74

    
75
        private boolean inserted = false;
76

    
77
    /*
78
         * Usar con mucha precaucion o mejor no usar. Lo precisa el
79
         * DefaultFeatureSet en la ordenacion.
80
         */
81
        public DefaultFeature(FeatureStore store) {
82
                this.storeRef = new WeakReference(store);
83
                this.reference = null;
84
        }
85

    
86
        public DefaultFeature(FeatureStore store, FeatureProvider data) {
87
                this.data = data;
88
                this.storeRef = new WeakReference(store);
89
                this.reference = null;
90
                this.inserted = !data.isNew();
91
        }
92

    
93
        DefaultFeature(DefaultFeature feature) {
94
                this.data = feature.data.getCopy();
95
                this.storeRef = feature.storeRef;
96
                this.reference = feature.reference;
97
                this.inserted = feature.isInserted();
98
        }
99

    
100
    public DefaultFeature(FeatureType targetType, Feature sourceFeature) {
101
        DefaultFeature defaultFeature = (DefaultFeature)sourceFeature;
102
        this.data = new DefaultFeatureProvider(targetType, (DefaultFeatureProvider)defaultFeature.getData());
103
        this.storeRef = defaultFeature.storeRef;
104
        this.reference = defaultFeature.reference;
105
        this.inserted = defaultFeature.isInserted();
106

    
107
        FeatureType sourceType = sourceFeature.getType();
108

    
109
        for (FeatureAttributeDescriptor targetAttrDescriptor : targetType) {
110
            if ( targetAttrDescriptor.isAutomatic() ||
111
                 targetAttrDescriptor.isReadOnly() ||
112
                 targetAttrDescriptor.getEvaluator() != null) {
113
                 continue;
114
            }
115
            int sourceIndex = sourceType.getIndex(targetAttrDescriptor.getName());
116
            if (sourceIndex<0){
117
                continue;
118
            }
119
            Object value = sourceFeature.get(sourceIndex);
120
            if (value == null && !targetAttrDescriptor.allowNull()) {
121
                continue;
122
            }
123
            this.set(targetAttrDescriptor,value);
124
        }
125
    }
126

    
127
        public void setData(FeatureProvider data) {
128
                this.data = data;
129
                this.reference = null;
130
                this.inserted = true;
131
        }
132

    
133
        public FeatureProvider getData() {
134
                return this.data;
135
        }
136

    
137
        protected DataTypesManager getDataTypesManager() {
138
                if( dataTypesManager==null ) {
139
                        dataTypesManager = ToolsLocator.getDataTypesManager();
140
                }
141
                return dataTypesManager;
142
        }
143

    
144
    void set(FeatureAttributeDescriptor attribute, Object value) {
145
        int i = attribute.getIndex();
146

    
147
        if ( attribute.isReadOnly() ) {
148
            throw new SetReadOnlyAttributeException(attribute.getName(), this.getType());
149
        }
150
        FeatureAttributeEmulator emulator = attribute.getFeatureAttributeEmulator();
151
        if( emulator!= null ) {
152
            emulator.set((EditableFeature) this,value);
153
            return;
154
        }
155

    
156
        if ( value == null ) {
157
            if ( !attribute.allowNull() ) {
158
                if ( !attribute.isAutomatic() ) {
159
                    throw new IllegalValueException(attribute, value);
160
                }
161
            }
162
            this.data.set(i, null);
163
            return;
164

    
165
        }
166

    
167
        if ( attribute.getFeatureAttributeGetter() != null ) {
168
            value = attribute.getFeatureAttributeGetter().setter(value);
169
        }
170

    
171
        Class objectClass = attribute.getObjectClass();
172
        if( objectClass!=null ) {
173
            if ( objectClass.isInstance(value) ) {
174
                this.data.set(i, value);
175
                return;
176
            }
177

    
178
            if ( !objectClass.isInstance(value) ) {
179
                try {
180
                    value
181
                            = this.getDataTypesManager().coerce(attribute.getType(),
182
                                    value);
183
                } catch (CoercionException e) {
184
                    throw new IllegalArgumentException("Can't convert to "
185
                            + this.getDataTypesManager().getTypeName(
186
                                    attribute.getType()) + " from '"
187
                            + value.getClass().getName() + "' with value '"
188
                            + value.toString() + "'.");
189
                }
190
            }
191
        }
192
        this.data.set(i, value);
193
    }
194

    
195
    private Object get(int index,Class theClass, int type) {
196
        Object value = this.get(index);
197
        if( theClass.isInstance(value) ) {
198
            return value;
199
        }
200
        try {
201
            return this.getDataTypesManager().coerce(type, value);
202
        } catch (CoercionException e) {
203

    
204
            if (value == null) {
205
                return null;
206
            }
207
            throw new IllegalArgumentException(
208
                    "Can't convert to "+theClass.getName()+
209
                    " from '"+value.getClass().getName()+
210
                    "' with value '"+value.toString()+"'.");
211
        }
212
    }
213

    
214
//  private Object getNumberByType(Number value, int type) {
215
//      if (type==DataTypes.DOUBLE){
216
//          return new Double(value.doubleValue());
217
//      }else if (type==DataTypes.FLOAT){
218
//          return new Float(value.floatValue());
219
//      }else if (type==DataTypes.LONG){
220
//          return new Long(value.longValue());
221
//      }else if (type==DataTypes.INT){
222
//          return new Integer(value.intValue());
223
//      }else if (type==DataTypes.STRING){
224
//          return value.toString();
225
//      }
226
//      return value;
227
//  }
228

    
229
    public void initializeValues() {
230
        FeatureType type = this.getType();
231
        Iterator iterator = type.iterator();
232

    
233
        while (iterator.hasNext()) {
234
            FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor) iterator
235
            .next();
236
            if (attribute.isAutomatic() || attribute.isReadOnly()
237
                    || attribute.isComputed() ) {
238
                continue;
239
            }
240
            if (attribute.getDefaultValue() == null && !attribute.allowNull()) {
241
                continue;
242
            }
243
            this.set(attribute, attribute.getDefaultValue());
244
        }
245
    }
246

    
247
    public void clear() {
248
        initializeValues();
249
    }
250

    
251
    public void initializeValues(Feature feature) {
252
        FeatureType myType=this.getType();
253
        FeatureType type =feature.getType();
254
        Iterator iterator = type.iterator();
255

    
256
        while (iterator.hasNext()) {
257
            FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor) iterator
258
            .next();
259
            FeatureAttributeDescriptor myAttribute=myType.getAttributeDescriptor(attribute.getName());
260
            if (myAttribute != null) {
261
                this.set(myAttribute, feature.get(attribute.getIndex()));
262
            }
263
        }
264
    }
265

    
266

    
267
    public FeatureStore getStore() {
268
        return (FeatureStore) this.storeRef.get();
269
    }
270

    
271
    public FeatureType getType() {
272
        return this.data.getType();
273
    }
274

    
275
    public EditableFeature getEditable() {
276
        return new DefaultEditableFeature(this);
277
    }
278

    
279
    public Feature getCopy() {
280
        return new DefaultFeature(this);
281
    }
282

    
283
    public Object clone() throws CloneNotSupportedException {
284
        return new DefaultFeature(this);
285
    }
286

    
287
    public FeatureReference getReference() {
288
        if (this.reference == null) {
289
            if (!isInserted()) {
290
                return null;
291
            }
292
            reference = new DefaultFeatureReference(this);
293
        }
294
        return this.reference;
295
    }
296

    
297
    class UnableToGetReferenceException extends BaseRuntimeException {
298

    
299
        /**
300
         *
301
         */
302
        private static final long serialVersionUID = 1812805035204824163L;
303

    
304
        /**
305
         * @param exception
306
         */
307
        public UnableToGetReferenceException(BaseException exception) {
308
            super("Unable to get reference", "_UnableToGetReferenceException",
309
                serialVersionUID);
310
            this.initCause(exception);
311

    
312
        }
313

    
314
    }
315

    
316
    public void validate(int mode) throws DataException  {
317
        ((DefaultFeatureType) this.data.getType()).validateFeature(this, mode);
318
    }
319

    
320
    public List getSRSs() {
321
        // TODO Auto-generated method stub
322
        return null;
323
    }
324

    
325
    public Envelope getDefaultEnvelope() {
326
        Envelope envelope = this.data.getDefaultEnvelope();
327
        if( envelope == null ) {
328
            Geometry geom = this.getDefaultGeometry();
329
            if( geom!=null ) {
330
                envelope = geom.getEnvelope();
331
            }
332
        }
333
        return envelope;
334
    }
335

    
336
    @Override
337
    public Geometry getDefaultGeometry() {
338
            Geometry geom = this.data.getDefaultGeometry();
339
        if( geom == null ) {
340
            int i = this.data.getType().getDefaultGeometryAttributeIndex();
341
            Object x = this.get(i);
342
            if( x instanceof Geometry ) {
343
                geom = (Geometry) x;
344
            } else {
345
                geom = this.getGeometry(i);
346
            }
347
        }
348
        if( geom != null ) {
349
            if( geom.getProjection()==null ) {
350
                FeatureType type = this.getType();
351
                DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex());
352
                IProjection proj = attrdesc.getSRS(this.storeRef);
353
                geom.setProjection(proj);
354
            }
355
        }
356
        return geom;
357
    }
358

    
359
    @Override
360
    public Time getDefaultTime() {
361
            Time time = this.data.getDefaultTime();
362
        if( time == null ) {
363
            int i = this.data.getType().getDefaultTimeAttributeIndex();
364
            Object x = this.get(i);
365
            if( x instanceof Time ) {
366
                time = (Time) x;
367
            } else {
368
                time = this.getTime(i);
369
            }
370
        }
371
        return time;
372
    }
373

    
374
    public IProjection getDefaultSRS() {
375
        IProjection srs = this.data.getType().getDefaultSRS();
376
        if( srs == null ) {
377
            FeatureType type = this.getType();
378
            DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex());
379
            srs = attrdesc.getSRS(this.storeRef);
380
        }
381
        return srs;
382
    }
383

    
384
    public List getGeometries() {
385
        // TODO Auto-generated method stub
386
        return null;
387
    }
388

    
389
    @Override
390
    public Object getFromProfile(int index) {
391
        FeatureAttributeDescriptor descriptor = this.data.getType().getAttributeDescriptor(index);
392
        Object value = this.get(index);
393
        String profileName = descriptor.getDataProfileName();
394
        if( StringUtils.isBlank(profileName) ) {
395
            return value;
396
        }
397
        DataProfile profile = DALLocator.getDataManager().getDataProfile(profileName);
398
        if( profile==null ) {
399
            return value;
400
        }
401
        return profile.createData(value);
402
    }
403

    
404
    @Override
405
    public Object getFromProfile(String name) {
406
        FeatureAttributeDescriptor descriptor = this.data.getType().getAttributeDescriptor(name);
407
        return this.getFromProfile(descriptor.getIndex());
408
    }
409

    
410
    public Object get(String name) {
411
        int index = this.data.getType().getIndex(name);
412
        if( index < 0 ) {
413
            throw new IllegalArgumentException("Attribute name '"+name+"' not found in the feature.");
414
        }
415
        return this.get(index);
416
    }
417

    
418
    public boolean has_key(String key) {
419
        Object x = this.getType().get(key);
420
        return x != null;
421
    }
422

    
423
    public List<String> keys() {
424
        List<String> ks = new ArrayList<>();
425
        for( FeatureAttributeDescriptor attr : this.getType()) {
426
            ks.add(attr.getName());
427
        }
428
        return ks;
429
    }
430

    
431
    public Iterator<String> iterkeys() {
432
        final Iterator it = this.getType().iterator();
433
        return new Iterator<String>() {
434
            @Override
435
            public boolean hasNext() {
436
                return it.hasNext();
437
            }
438

    
439
            @Override
440
            public String next() {
441
                return ((FeatureAttributeDescriptor)it.next()).getName();
442
            }
443

    
444
            @Override
445
            public void remove() {
446
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
447
            }
448
        };
449
    }
450

    
451
    public Iterator iteritems() {
452
        final Iterator it = this.getType().iterator();
453
        return new Iterator<Map.Entry>() {
454
            @Override
455
            public boolean hasNext() {
456
                return it.hasNext();
457
            }
458

    
459
            @Override
460
            public Map.Entry next() {
461
                final String name = ((FeatureAttributeDescriptor)it.next()).getName();
462
                return new Map.Entry<String, Object>() {
463
                    @Override
464
                    public String getKey() {
465
                        return name;
466
                    }
467

    
468
                    @Override
469
                    public Object getValue() {
470
                        return get(name);
471
                    }
472

    
473
                    @Override
474
                    public Object setValue(Object value) {
475
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
476
                    }
477

    
478
                };
479
            }
480

    
481
            @Override
482
            public void remove() {
483
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
484
            }
485
        };
486
    }
487

    
488
    @Override
489
    public Object get(int index) {
490
        FeatureType type = this.data.getType();
491
        if( index <0 || index >= type.size() ) {
492
            throw new IllegalArgumentException("Attribute index '"+index+"' out of range (0 to "+this.data.getType().size()+".");
493
        }
494
        FeatureAttributeDescriptor attribute = type.getAttributeDescriptor(index);
495
        if (!this.data.getType().hasEvaluators()) {
496
            return get(attribute, this.data.get(index));
497
        }
498
        Evaluator eval = attribute.getEvaluator();
499
        if (eval == null) {
500
            return this.data.get(index);
501
        } else {
502
            Object value = this.data.get(index);
503
            if (value != null) { // FIXME: para comprobar si esta calculado usar
504
                // un array
505
                // especifico.
506
                return get(attribute, this.data.get(index));
507
            }
508
            try {
509
                value = eval.evaluate(this);
510
            } catch (EvaluatorException e) {
511
                throw new DataEvaluatorRuntimeException(e);
512
            }
513
            this.data.set(index, value);
514
            return  get(attribute, value);
515
        }
516
    }
517

    
518
    private Object get(FeatureAttributeDescriptor featureAttributeDescriptor, Object value){
519
        FeatureAttributeEmulator emulator = featureAttributeDescriptor.getFeatureAttributeEmulator();
520
        if( emulator != null ) {
521
//            int index = featureAttributeDescriptor.getIndex();
522
//            value = this.data.get(index);
523
//            if( value==null ) {
524
                value = emulator.get(this);
525
//                this.data.set(index,value);
526
//            }
527
        } else {
528
            FeatureAttributeGetter getter = featureAttributeDescriptor.getFeatureAttributeGetter();
529
            if( getter != null ) {
530
                value = getter.getter(value);
531
            }
532
        }
533
        if( featureAttributeDescriptor.getType()==DataTypes.GEOMETRY ) {
534
            if( value != null ) {
535
                Geometry geom = (Geometry)value;
536
                if( geom.getProjection()==null ) {
537
                    IProjection proj = ((DefaultFeatureAttributeDescriptor)featureAttributeDescriptor).getSRS(this.storeRef);
538
                    geom.setProjection(proj);
539
                }
540
            }
541
        }
542
        return value;
543
    }
544

    
545
    public Object[] getArray(String name) {
546
        return this.getArray(this.data.getType().getIndex(name));
547
    }
548

    
549
    public Object[] getArray(int index) {
550
        return (Object[]) this.get(index);
551
    }
552

    
553
    public boolean getBoolean(String name) {
554
        return this.getBoolean(this.data.getType().getIndex(name));
555
    }
556

    
557
    public boolean getBoolean(int index) {
558
        Boolean value = ((Boolean) this.get(index,Boolean.class,DataTypes.BOOLEAN));
559
        if (value == null) {
560
            return false;
561
        }
562
        return value.booleanValue();
563
    }
564

    
565
    public byte getByte(String name) {
566
        return this.getByte(this.data.getType().getIndex(name));
567
    }
568

    
569
    public byte getByte(int index) {
570
        Byte value = ((Byte) this.get(index,Byte.class,DataTypes.BYTE));
571
        if (value == null) {
572
            return 0;
573
        }
574
        return value.byteValue();
575
    }
576

    
577
    public Date getDate(String name) {
578
        return this.getDate(this.data.getType().getIndex(name));
579
    }
580

    
581
    public Date getDate(int index) {
582
        Date value = ((Date) this.get(index,Date.class,DataTypes.DATE));
583

    
584
        return value;
585
    }
586

    
587
    public double getDouble(String name) {
588
        return this.getDouble(this.data.getType().getIndex(name));
589
    }
590

    
591
    public double getDouble(int index) {
592

    
593
        Double value = ((Double) this.get(index,Double.class,DataTypes.DOUBLE));
594
        if (value == null) {
595
            return 0;
596
        }
597
        return value.doubleValue();
598
    }
599

    
600
    public Feature getFeature(String name) {
601
        return this.getFeature(this.data.getType().getIndex(name));
602
    }
603

    
604
    public Feature getFeature(int index) {
605
        return (Feature) this.get(index);
606
    }
607

    
608
    public float getFloat(String name) {
609
        return this.getFloat(this.data.getType().getIndex(name));
610
    }
611

    
612
    public float getFloat(int index) {
613
        Float value = ((Float) this.get(index,Float.class,DataTypes.FLOAT));
614
        if (value == null) {
615
            return 0;
616
        }
617
        return value.floatValue();
618
    }
619

    
620
    public Geometry getGeometry(String name) {
621
        return this.getGeometry(this.data.getType().getIndex(name));
622
    }
623

    
624
    public Geometry getGeometry(int index) {
625
        return (Geometry) this.get(index,Geometry.class,DataTypes.GEOMETRY);
626
    }
627

    
628
    public int getInt(String name) {
629
        return this.getInt(this.data.getType().getIndex(name));
630
    }
631

    
632
    public int getInt(int index) {
633
        Integer value = ((Integer) this.get(index,Integer.class,DataTypes.INT));
634
        if (value == null) {
635
            return 0;
636
        }
637
        return ((Integer)value).intValue();
638
    }
639

    
640
    public long getLong(String name) {
641
        return this.getLong(this.data.getType().getIndex(name));
642
    }
643

    
644
    public long getLong(int index) {
645
        Long value = ((Long) this.get(index,Long.class,DataTypes.LONG));
646
        if (value == null) {
647
            return 0;
648
        }
649
        return value.longValue();
650
    }
651

    
652
    public String getString(String name) {
653
        return this.getString(this.data.getType().getIndex(name));
654
    }
655

    
656
    public String getString(int index) {
657
        return (String) this.get(index,String.class,DataTypes.STRING);
658
    }
659

    
660
    public Object getContextValue(String name) {
661
        name = name.toLowerCase();
662
        if (name.equals("store")) {
663
            return this.getStore();
664
        }
665

    
666
        if (name.equals("featuretype")) {
667
            return this.data.getType();
668
        }
669

    
670
        if (name.equals("feature")) {
671
            return this;
672
        }
673

    
674
        throw new IllegalArgumentException(name);
675
    }
676

    
677
    public Iterator getDataNames() {
678
        class DataNamesIterator implements Iterator {
679
            Iterator attributeIteraror;
680

    
681
            DataNamesIterator(DefaultFeature feature) {
682
                this.attributeIteraror = feature.getType().iterator();
683
            }
684

    
685
            public boolean hasNext() {
686
                return this.attributeIteraror.hasNext();
687
            }
688

    
689
            public Object next() {
690
                return ((FeatureAttributeDescriptor) this.attributeIteraror
691
                        .next()).getName();
692
            }
693

    
694
            public void remove() {
695
                throw new UnsupportedOperationException();
696
            }
697

    
698
        }
699
        return new DataNamesIterator(this);
700
    }
701

    
702
    public Object getDataValue(String name) {
703
        name = name.toLowerCase();
704
        try {
705
            return get(name);
706
        } catch (IllegalArgumentException ex) {
707
            if( "defaultgeometry".equalsIgnoreCase(name )) {
708
                return this.getDefaultGeometry();
709
            }
710
            throw ex;
711
        }
712
    }
713

    
714
    public Iterator getDataValues() {
715
        class DataValuesIterator implements Iterator {
716
            DefaultFeature feature;
717
            int current = 0;
718

    
719
            DataValuesIterator(DefaultFeature feature) {
720
                this.feature = feature;
721
            }
722

    
723
            public boolean hasNext() {
724
                return current < feature.getType().size() - 1;
725
            }
726

    
727
            public Object next() {
728
                return feature.get(current++);
729
            }
730

    
731
            public void remove() {
732
                throw new UnsupportedOperationException();
733
            }
734

    
735
        }
736
        return new DataValuesIterator(this);
737
    }
738

    
739
    public boolean hasContextValue(String name) {
740
        name = name.toLowerCase();
741
        if (name.equals("store")) {
742
            return true;
743
        }
744

    
745
        if (name.equals("featuretype")) {
746
            return true;
747
        }
748

    
749
        if (name.equals("feature")) {
750
            return true;
751
        }
752
        return false;
753
    }
754

    
755
    public boolean hasDataValue(String name) {
756
        name = name.toLowerCase();
757
        return this.data.getType().getIndex(name) >= 0;
758
    }
759

    
760
        @Override
761
    public Time getTime(int index) {
762
        return ((Time) this.get(index,Time.class,DataTypes.INSTANT));
763
    }
764

    
765
        @Override
766
    public Time getTime(String name) {
767
        return this.getInstant(this.data.getType().getIndex(name));
768
    }
769

    
770
        @Override
771
    public Instant getInstant(int index) {
772
        return ((Instant) this.get(index,Instant.class,DataTypes.INSTANT));
773
    }
774

    
775
        @Override
776
    public Instant getInstant(String name) {
777
        return this.getInstant(this.data.getType().getIndex(name));
778
    }
779

    
780
        @Override
781
    public Interval getInterval(int index) {
782
        return ((Interval) this.get(index,Interval.class,DataTypes.INTERVAL));
783
    }
784

    
785
        @Override
786
    public Interval getInterval(String name) {
787
        return this.getInterval(this.data.getType().getIndex(name));
788
    }
789

    
790
    @Override
791
    public DynObject getAsDynObject() {
792
        DynObjectFeatureFacade facade = new DynObjectFeatureFacade(this);
793
        return facade;
794
    }
795

    
796
    public String toString() {
797
       // StringBuffer buffer = new StringBuffer("Feature with values: ");
798
            StringBuffer buffer = new StringBuffer("");
799
        FeatureAttributeDescriptor[] attributeDescriptors =
800
            getType().getAttributeDescriptors();
801
        for (int i = 0; i < attributeDescriptors.length; i++) {
802
            String name = attributeDescriptors[i].getName();
803
            //buffer.append(name).append("=").append(get(name));
804
            buffer.append(get(name));
805
            if (i < attributeDescriptors.length - 1) {
806
                buffer.append(", ");
807
            }
808
        }
809
        return buffer.toString();
810
    }
811

    
812

    
813

    
814

    
815
        /**
816
     * @return the inserted
817
     */
818
    public boolean isInserted() {
819
        return inserted;
820
    }
821

    
822

    
823
    /**
824
     * @param inserted the inserted to set
825
     */
826
    public void setInserted(boolean inserted) {
827
        this.inserted = inserted;
828
    }
829

    
830
        @Override
831
    public EvaluatorData getEvaluatorData() {
832
        return this;
833
    }
834

    
835
    public int size() {
836
        return this.data.getType().size();
837
    }
838
    
839
    public boolean isEmpty() {
840
        return false;
841
    }
842

    
843
    public Iterator<String> iterator() {
844
        final Iterator<FeatureAttributeDescriptor> x = this.data.getType().iterator();
845
        return new Iterator<String>() {
846
            @Override
847
            public boolean hasNext() {
848
                return x.hasNext();
849
            }
850

    
851
            @Override
852
            public String next() {
853
                return x.next().getName();
854
            }
855
        };
856
    }
857
    
858
    public boolean containsKey(String key) {
859
        return this.data.getType().get(key)!=null;
860
    }
861
}