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

History | View | Annotate | Download (24.6 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

    
33
import org.cresques.cts.IProjection;
34

    
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.EditableFeature;
39
import org.gvsig.fmap.dal.feature.Feature;
40
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
42
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
43
import org.gvsig.fmap.dal.feature.FeatureReference;
44
import org.gvsig.fmap.dal.feature.FeatureStore;
45
import org.gvsig.fmap.dal.feature.FeatureType;
46
import org.gvsig.fmap.dal.feature.exception.IllegalValueException;
47
import org.gvsig.fmap.dal.feature.exception.SetReadOnlyAttributeException;
48
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectFeatureFacade;
49
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
50
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
51
import org.gvsig.fmap.geom.Geometry;
52
import org.gvsig.fmap.geom.primitive.Envelope;
53
import org.gvsig.timesupport.Instant;
54
import org.gvsig.timesupport.Interval;
55
import org.gvsig.tools.ToolsLocator;
56
import org.gvsig.tools.dataTypes.CoercionException;
57
import org.gvsig.tools.dataTypes.DataTypesManager;
58
import org.gvsig.tools.dynobject.DynObject;
59
import org.gvsig.tools.evaluator.Evaluator;
60
import org.gvsig.tools.evaluator.EvaluatorData;
61
import org.gvsig.tools.evaluator.EvaluatorException;
62
import org.gvsig.tools.exception.BaseException;
63
import org.gvsig.tools.exception.BaseRuntimeException;
64
import org.gvsig.tools.lang.Cloneable;
65

    
66
public class DefaultFeature implements Feature, EvaluatorData, Cloneable {
67

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

    
73
        private boolean inserted = false;
74

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

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

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

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

    
105
        FeatureType sourceType = sourceFeature.getType();
106

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

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

    
131
        public FeatureProvider getData() {
132
                return this.data;
133
        }
134

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

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

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

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

    
163
        }
164

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

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

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

    
193
    private Object get(int index,Class theClass, int type) {
194
        Object value = this.get(index);
195
        if( theClass.isInstance(value) ) {
196
            return value;
197
        }
198

    
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.getEvaluator() != null) {
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
    public IProjection getDefaultSRS() {
360
        IProjection srs = this.data.getType().getDefaultSRS();
361
        if( srs == null ) {
362
            FeatureType type = this.getType();
363
            DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex());
364
            srs = attrdesc.getSRS(this.storeRef);
365
        }
366
        return srs;
367
    }
368

    
369
    public List getGeometries() {
370
        // TODO Auto-generated method stub
371
        return null;
372
    }
373

    
374
    public Object get(String name) {
375
        int index = this.data.getType().getIndex(name);
376
        if( index < 0 ) {
377
            throw new IllegalArgumentException("Attribute name '"+name+"' not found in the feature.");
378
        }
379
        return this.get(index);
380
    }
381

    
382
    public boolean has_key(String key) {
383
        Object x = this.getType().get(key);
384
        return x != null;
385
    }
386

    
387
    public List<String> keys() {
388
        List<String> ks = new ArrayList<>();
389
        for( FeatureAttributeDescriptor attr : this.getType()) {
390
            ks.add(attr.getName());
391
        }
392
        return ks;
393
    }
394

    
395
    public Iterator<String> iterkeys() {
396
        final Iterator it = this.getType().iterator();
397
        return new Iterator<String>() {
398
            @Override
399
            public boolean hasNext() {
400
                return it.hasNext();
401
            }
402

    
403
            @Override
404
            public String next() {
405
                return ((FeatureAttributeDescriptor)it.next()).getName();
406
            }
407

    
408
            @Override
409
            public void remove() {
410
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
411
            }
412
        };
413
    }
414

    
415
    public Iterator iteritems() {
416
        final Iterator it = this.getType().iterator();
417
        return new Iterator<Map.Entry>() {
418
            @Override
419
            public boolean hasNext() {
420
                return it.hasNext();
421
            }
422

    
423
            @Override
424
            public Map.Entry next() {
425
                final String name = ((FeatureAttributeDescriptor)it.next()).getName();
426
                return new Map.Entry<String, Object>() {
427
                    @Override
428
                    public String getKey() {
429
                        return name;
430
                    }
431

    
432
                    @Override
433
                    public Object getValue() {
434
                        return get(name);
435
                    }
436

    
437
                    @Override
438
                    public Object setValue(Object value) {
439
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
440
                    }
441

    
442
                };
443
            }
444

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

    
452
    @Override
453
    public Object get(int index) {
454
        FeatureType type = this.data.getType();
455
        if( index <0 || index >= type.size() ) {
456
            throw new IllegalArgumentException("Attribute index '"+index+"' out of range (0 to "+this.data.getType().size()+".");
457
        }
458
        FeatureAttributeDescriptor attribute = type.getAttributeDescriptor(index);
459
        if (!this.data.getType().hasEvaluators()) {
460
            return get(attribute, this.data.get(index));
461
        }
462
        Evaluator eval = attribute.getEvaluator();
463
        if (eval == null) {
464
            return this.data.get(index);
465
        } else {
466
            Object value = this.data.get(index);
467
            if (value != null) { // FIXME: para comprobar si esta calculado usar
468
                // un array
469
                // especifico.
470
                return get(attribute, this.data.get(index));
471
            }
472
            try {
473
                value = eval.evaluate(this);
474
            } catch (EvaluatorException e) {
475
                throw new DataEvaluatorRuntimeException(e);
476
            }
477
            this.data.set(index, value);
478
            return  get(attribute, value);
479
        }
480
    }
481

    
482
    private Object get(FeatureAttributeDescriptor featureAttributeDescriptor, Object value){
483
        FeatureAttributeEmulator emulator = featureAttributeDescriptor.getFeatureAttributeEmulator();
484
        if( emulator != null ) {
485
            value = emulator.get(this);
486
        } else {
487
            FeatureAttributeGetter getter = featureAttributeDescriptor.getFeatureAttributeGetter();
488
            if( getter != null ) {
489
                value = getter.getter(value);
490
            }
491
        }
492
        if( featureAttributeDescriptor.getType()==DataTypes.GEOMETRY ) {
493
            if( value != null ) {
494
                Geometry geom = (Geometry)value;
495
                if( geom.getProjection()==null ) {
496
                    IProjection proj = ((DefaultFeatureAttributeDescriptor)featureAttributeDescriptor).getSRS(this.storeRef);
497
                    geom.setProjection(proj);
498
                }
499
            }
500
        }
501
        return value;
502
    }
503

    
504
    public Object[] getArray(String name) {
505
        return this.getArray(this.data.getType().getIndex(name));
506
    }
507

    
508
    public Object[] getArray(int index) {
509
        return (Object[]) this.get(index);
510
    }
511

    
512
    public boolean getBoolean(String name) {
513
        return this.getBoolean(this.data.getType().getIndex(name));
514
    }
515

    
516
    public boolean getBoolean(int index) {
517
        Boolean value = ((Boolean) this.get(index,Boolean.class,DataTypes.BOOLEAN));
518
        if (value == null) {
519
            return false;
520
        }
521
        return value.booleanValue();
522
    }
523

    
524
    public byte getByte(String name) {
525
        return this.getByte(this.data.getType().getIndex(name));
526
    }
527

    
528
    public byte getByte(int index) {
529
        Byte value = ((Byte) this.get(index,Byte.class,DataTypes.BYTE));
530
        if (value == null) {
531
            return 0;
532
        }
533
        return value.byteValue();
534
    }
535

    
536
    public Date getDate(String name) {
537
        return this.getDate(this.data.getType().getIndex(name));
538
    }
539

    
540
    public Date getDate(int index) {
541
        Date value = ((Date) this.get(index,Date.class,DataTypes.DATE));
542

    
543
        return value;
544
    }
545

    
546
    public double getDouble(String name) {
547
        return this.getDouble(this.data.getType().getIndex(name));
548
    }
549

    
550
    public double getDouble(int index) {
551

    
552
        Double value = ((Double) this.get(index,Double.class,DataTypes.DOUBLE));
553
        if (value == null) {
554
            return 0;
555
        }
556
        return value.doubleValue();
557
    }
558

    
559
    public Feature getFeature(String name) {
560
        return this.getFeature(this.data.getType().getIndex(name));
561
    }
562

    
563
    public Feature getFeature(int index) {
564
        return (Feature) this.get(index);
565
    }
566

    
567
    public float getFloat(String name) {
568
        return this.getFloat(this.data.getType().getIndex(name));
569
    }
570

    
571
    public float getFloat(int index) {
572
        Float value = ((Float) this.get(index,Float.class,DataTypes.FLOAT));
573
        if (value == null) {
574
            return 0;
575
        }
576
        return value.floatValue();
577
    }
578

    
579
    public Geometry getGeometry(String name) {
580
        return this.getGeometry(this.data.getType().getIndex(name));
581
    }
582

    
583
    public Geometry getGeometry(int index) {
584
        return (Geometry) this.get(index,Geometry.class,DataTypes.GEOMETRY);
585
    }
586

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

    
591
    public int getInt(int index) {
592
        Integer value = ((Integer) this.get(index,Integer.class,DataTypes.INT));
593
        if (value == null) {
594
            return 0;
595
        }
596
        return ((Integer)value).intValue();
597
    }
598

    
599
    public long getLong(String name) {
600
        return this.getLong(this.data.getType().getIndex(name));
601
    }
602

    
603
    public long getLong(int index) {
604
        Long value = ((Long) this.get(index,Long.class,DataTypes.LONG));
605
        if (value == null) {
606
            return 0;
607
        }
608
        return value.longValue();
609
    }
610

    
611
    public String getString(String name) {
612
        return this.getString(this.data.getType().getIndex(name));
613
    }
614

    
615
    public String getString(int index) {
616
        return (String) this.get(index,String.class,DataTypes.STRING);
617
    }
618

    
619
    public Object getContextValue(String name) {
620
        name = name.toLowerCase();
621
        if (name.equals("store")) {
622
            return this.getStore();
623
        }
624

    
625
        if (name.equals("featuretype")) {
626
            return this.data.getType();
627
        }
628

    
629
        if (name.equals("feature")) {
630
            return this;
631
        }
632

    
633
        throw new IllegalArgumentException(name);
634
    }
635

    
636
    public Iterator getDataNames() {
637
        class DataNamesIterator implements Iterator {
638
            Iterator attributeIteraror;
639

    
640
            DataNamesIterator(DefaultFeature feature) {
641
                this.attributeIteraror = feature.getType().iterator();
642
            }
643

    
644
            public boolean hasNext() {
645
                return this.attributeIteraror.hasNext();
646
            }
647

    
648
            public Object next() {
649
                return ((FeatureAttributeDescriptor) this.attributeIteraror
650
                        .next()).getName();
651
            }
652

    
653
            public void remove() {
654
                throw new UnsupportedOperationException();
655
            }
656

    
657
        }
658
        return new DataNamesIterator(this);
659
    }
660

    
661
    public Object getDataValue(String name) {
662
        name = name.toLowerCase();
663
        try {
664
            return get(name);
665
        } catch (IllegalArgumentException ex) {
666
            if( "defaultgeometry".equalsIgnoreCase(name )) {
667
                return this.getDefaultGeometry();
668
            }
669
            throw ex;
670
        }
671
    }
672

    
673
    public Iterator getDataValues() {
674
        class DataValuesIterator implements Iterator {
675
            DefaultFeature feature;
676
            int current = 0;
677

    
678
            DataValuesIterator(DefaultFeature feature) {
679
                this.feature = feature;
680
            }
681

    
682
            public boolean hasNext() {
683
                return current < feature.getType().size() - 1;
684
            }
685

    
686
            public Object next() {
687
                return feature.get(current++);
688
            }
689

    
690
            public void remove() {
691
                throw new UnsupportedOperationException();
692
            }
693

    
694
        }
695
        return new DataValuesIterator(this);
696
    }
697

    
698
    public boolean hasContextValue(String name) {
699
        name = name.toLowerCase();
700
        if (name.equals("store")) {
701
            return true;
702
        }
703

    
704
        if (name.equals("featuretype")) {
705
            return true;
706
        }
707

    
708
        if (name.equals("feature")) {
709
            return true;
710
        }
711
        return false;
712
    }
713

    
714
    public boolean hasDataValue(String name) {
715
        name = name.toLowerCase();
716
        return this.data.getType().getIndex(name) >= 0;
717
    }
718

    
719
    public Instant getInstant(int index) {
720
        return ((Instant) this.get(index,Date.class,DataTypes.INSTANT));
721
    }
722

    
723
    public Instant getInstant(String name) {
724
        return this.getInstant(this.data.getType().getIndex(name));
725
    }
726

    
727
    public Interval getInterval(int index) {
728
        return ((Interval) this.get(index,Date.class,DataTypes.INTERVAL));
729
    }
730

    
731
    public Interval getInterval(String name) {
732
        return this.getInterval(this.data.getType().getIndex(name));
733
    }
734

    
735
    @Override
736
    public DynObject getAsDynObject() {
737
        DynObjectFeatureFacade facade = new DynObjectFeatureFacade(this);
738
        return facade;
739
    }
740

    
741
    public String toString() {
742
       // StringBuffer buffer = new StringBuffer("Feature with values: ");
743
            StringBuffer buffer = new StringBuffer("");
744
        FeatureAttributeDescriptor[] attributeDescriptors =
745
            getType().getAttributeDescriptors();
746
        for (int i = 0; i < attributeDescriptors.length; i++) {
747
            String name = attributeDescriptors[i].getName();
748
            //buffer.append(name).append("=").append(get(name));
749
            buffer.append(get(name));
750
            if (i < attributeDescriptors.length - 1) {
751
                buffer.append(", ");
752
            }
753
        }
754
        return buffer.toString();
755
    }
756

    
757

    
758

    
759

    
760
        /**
761
     * @return the inserted
762
     */
763
    public boolean isInserted() {
764
        return inserted;
765
    }
766

    
767

    
768
    /**
769
     * @param inserted the inserted to set
770
     */
771
    public void setInserted(boolean inserted) {
772
        this.inserted = inserted;
773
    }
774

    
775
        @Override
776
    public EvaluatorData getEvaluatorData() {
777
        return this;
778
    }
779

    
780
    public int size() {
781
        return this.data.getType().size();
782
    }
783
    
784
    public boolean isEmpty() {
785
        return false;
786
    }
787

    
788
    public Iterator<String> iterator() {
789
        final Iterator<FeatureAttributeDescriptor> x = this.data.getType().iterator();
790
        return new Iterator<String>() {
791
            @Override
792
            public boolean hasNext() {
793
                return x.hasNext();
794
            }
795

    
796
            @Override
797
            public String next() {
798
                return x.next().getName();
799
            }
800
        };
801
    }
802
    
803
    public boolean containsKey(String key) {
804
        return this.data.getType().get(key)!=null;
805
    }
806
}