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 / DefaultFeatureType.java @ 44036

History | View | Annotate | Download (24.8 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.Arrays;
29
import java.util.Collections;
30
import java.util.HashSet;
31
import java.util.Iterator;
32
import java.util.LinkedHashSet;
33
import java.util.List;
34
import java.util.Set;
35
import java.util.zip.CRC32;
36
import org.apache.commons.lang3.ArrayUtils;
37
import org.apache.commons.lang3.StringUtils;
38

    
39
import org.cresques.cts.IProjection;
40

    
41
import org.gvsig.fmap.dal.DataTypes;
42
import org.gvsig.fmap.dal.exception.DataException;
43
import org.gvsig.fmap.dal.feature.EditableFeatureType;
44
import org.gvsig.fmap.dal.feature.Feature;
45
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
46
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
47
import org.gvsig.fmap.dal.feature.FeatureRules;
48
import org.gvsig.fmap.dal.feature.FeatureStore;
49
import org.gvsig.fmap.dal.feature.FeatureType;
50
import org.gvsig.tools.dynobject.DynClass;
51
import org.gvsig.tools.dynobject.DynField;
52
import org.gvsig.tools.dynobject.DynMethod;
53
import org.gvsig.tools.dynobject.DynObject;
54
import org.gvsig.tools.dynobject.DynObjectValueItem;
55
import org.gvsig.tools.dynobject.DynStruct;
56
import org.gvsig.tools.dynobject.exception.DynMethodException;
57
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
58

    
59
public class DefaultFeatureType extends ArrayList<FeatureAttributeDescriptor> implements FeatureType,
60
                DynClass, org.gvsig.tools.lang.Cloneable {
61

    
62
        /**
63
         *
64
         */
65
        private static final long serialVersionUID = -7988721447349282215L;
66

    
67
        private DefaultFeatureRules rules;
68
        protected boolean hasEvaluators;
69
        protected boolean hasEmulators;
70
        protected String defaultGeometryAttributeName;
71
        protected int defaultGeometryAttributeIndex;
72
        protected int defaultTimeAttributeIndex;
73
        private String id;
74
        protected boolean hasOID;
75
        protected boolean allowAtomaticValues;
76
        protected FeatureAttributeDescriptor[] pk = null;
77
        protected String internalID = null;
78

    
79
        private List srsList = null;
80
        private WeakReference storeRef;
81
    private boolean requiredFields;
82

    
83
        protected DefaultFeatureType(FeatureStore store, String id) {
84
            if (StringUtils.isEmpty(id)) {
85
                id = "default";
86
            }
87
            if( store == null ) {
88
                this.storeRef = null; 
89
            } else {
90
                this.storeRef = new WeakReference(store);
91
            }
92
            this.internalID = Integer.toHexString((int) (Math.random() * 100000)).toUpperCase();
93
            this.id = id;
94
            this.rules = new DefaultFeatureRules();
95
            this.hasEvaluators = false;
96
            this.hasEmulators = false;
97
            this.defaultGeometryAttributeName = null;
98
            this.defaultGeometryAttributeIndex = -1;
99
            this.defaultTimeAttributeIndex = -1;
100
            this.allowAtomaticValues = false;
101
        }
102

    
103
        protected DefaultFeatureType(FeatureStore store) {
104
                this(store, (String)null);
105
        }
106

    
107
        protected DefaultFeatureType(DefaultFeatureType other) {
108
                this(other.getStore(), (String)null);
109
                initialize(other, true);
110
        }
111

    
112
        protected DefaultFeatureType(DefaultFeatureType other,
113
                        boolean copyAttributes) {
114
                this(other.getStore(), (String)null);
115
                initialize(other, copyAttributes);
116
        }
117

    
118
        protected void initialize(DefaultFeatureType other, boolean copyAttributes) {
119
                this.id = other.getId();
120
                if (copyAttributes) {
121
                    Iterator iter = other.iterator();
122
                    DefaultFeatureAttributeDescriptor attr;
123
                    while (iter.hasNext()) {
124
                            attr = (DefaultFeatureAttributeDescriptor) iter.next();
125
                            this.intitalizeAddAttibute(attr);
126
                    }
127
                    if( other.pk!=null ) {
128
                        this.pk = new FeatureAttributeDescriptor[other.pk.length];
129
                        for( int i=0; i<other.pk.length; i++ ) {
130
                            this.pk[i] = other.pk[i].getCopy();
131
                        }
132
                    }
133
                }
134
                this.defaultGeometryAttributeName = other.defaultGeometryAttributeName;
135
                this.hasEvaluators = other.hasEvaluators;
136
                this.hasEmulators = other.hasEmulators;
137
                this.rules = (DefaultFeatureRules) other.rules.getCopy();
138
                this.defaultGeometryAttributeIndex = other.defaultGeometryAttributeIndex;
139
                this.defaultTimeAttributeIndex = other.defaultTimeAttributeIndex;
140
                this.hasOID = other.hasOID;
141
                this.id = other.id; // XXX ???? copiar o no esto????
142
                this.internalID = other.internalID;
143
        }
144

    
145
        protected void intitalizeAddAttibute(DefaultFeatureAttributeDescriptor attr) {
146
                super.add(attr.getCopy());
147
        }
148

    
149
        public String getId() {
150
                return this.id;
151
        }
152

    
153
        public Object get(String name) {
154
                FeatureAttributeDescriptor attr;
155
                Iterator iter = this.iterator();
156
                while (iter.hasNext()) {
157
                        attr = (FeatureAttributeDescriptor) iter.next();
158
                        if (attr.getName().equalsIgnoreCase(name)) {
159
                                return attr;
160
                        }
161
                }
162
                return null;
163
        }
164

    
165
        public FeatureAttributeDescriptor getAttributeDescriptor(String name) {
166
                FeatureAttributeDescriptor attr;
167
                Iterator iter = this.iterator();
168
                while (iter.hasNext()) {
169
                        attr = (FeatureAttributeDescriptor) iter.next();
170
                        if (attr.getName().equalsIgnoreCase(name)) {
171
                                return attr;
172
                        }
173
                }
174
                return null;
175
        }
176

    
177
        public FeatureAttributeDescriptor getAttributeDescriptor(int index) {
178
                return (FeatureAttributeDescriptor) super.get(index);
179
        }
180

    
181
        public FeatureType getCopy() {
182
                return new DefaultFeatureType(this);
183
        }
184

    
185
        public Object clone() {
186
            return this.getCopy();
187
        }
188

    
189
        public int getDefaultGeometryAttributeIndex() {
190
                return this.defaultGeometryAttributeIndex;
191
        }
192

    
193
        public String getDefaultGeometryAttributeName() {
194
                return this.defaultGeometryAttributeName;
195
        }
196

    
197
        public EditableFeatureType getEditable() {
198
                return new DefaultEditableFeatureType(this);
199
        }
200

    
201
        public int getIndex(String name) {
202
                FeatureAttributeDescriptor attr;
203
                Iterator iter = this.iterator();
204
                while (iter.hasNext()) {
205
                        attr = (FeatureAttributeDescriptor) iter.next();
206
                        if (attr.getName().equalsIgnoreCase(name)) {
207
                                return attr.getIndex();
208
                        }
209
                }
210
                return -1;
211
        }
212

    
213
        public FeatureRules getRules() {
214
                return this.rules;
215
        }
216

    
217
        public boolean hasEvaluators() {
218
                return this.hasEvaluators;
219
        }
220

    
221
        public boolean hasEmulators() {
222
                return this.hasEmulators;
223
        }
224
        
225
        public boolean hasRequiredFields() {
226
            return this.requiredFields;
227
        }
228

    
229
        public List getSRSs() {
230
                if (this.srsList == null) {
231
                        ArrayList tmp = new ArrayList();
232
                        Iterator iter = iterator();
233
                        Iterator tmpIter;
234
                        boolean allreadyHave;
235
                        IProjection tmpSRS;
236
                        FeatureAttributeDescriptor attr;
237
                        while (iter.hasNext()){
238
                                attr = (FeatureAttributeDescriptor) iter.next();
239
                                if (attr.getDataType().getType() == DataTypes.GEOMETRY
240
                                                && attr.getSRS() != null) {
241
                                        allreadyHave = false;
242
                                        tmpIter = tmp.iterator();
243
                                        while (tmpIter.hasNext()) {
244
                                                tmpSRS = (IProjection) tmpIter.next();
245
                                                if (tmpSRS.getAbrev().equals(attr.getSRS().getAbrev())) {
246
                                                        allreadyHave = true;
247
                                                        break;
248
                                                }
249
                                        }
250
                                        if (!allreadyHave) {
251
                                                tmp.add(attr.getSRS());
252
                                        }
253
                                }
254
                        }
255
                        this.srsList = Collections.unmodifiableList(tmp);
256
                }
257
                return this.srsList;
258
        }
259

    
260
        public IProjection getDefaultSRS() {
261
                if (this.getDefaultGeometryAttributeIndex() < 0) {
262
                        return null;
263
                }
264
                return this.getAttributeDescriptor(
265
                                this.getDefaultGeometryAttributeIndex()).getSRS();
266
        }
267

    
268
        public void validateFeature(Feature feature, int mode) throws DataException {
269
            DefaultFeatureRules rules = (DefaultFeatureRules) this.getRules();
270
            rules.validate(feature,mode);
271
        }
272

    
273
        public FeatureType getSubtype(String[] names) throws DataException {
274
                if( names==null || names.length <1) {
275
                    return (FeatureType) this.clone();
276
                }
277
                return new SubtypeFeatureType(this, names, null);
278
        }
279

    
280
        public FeatureType getSubtype(String[] names, String[] constantsNames) throws DataException {
281
        if( ArrayUtils.isEmpty(names) && ArrayUtils.isEmpty(constantsNames) ) {
282
            return (FeatureType) this.clone();
283
        }
284
                return new SubtypeFeatureType(this, names,constantsNames);
285
        }
286

    
287
        public FeatureType getSubtype() throws DataException {
288
                return new SubtypeFeatureType(this, null,null);
289
        }
290

    
291
        public boolean isSubtypeOf(FeatureType featureType) {
292
                return false;
293
        }
294

    
295

    
296

    
297
        class SubtypeFeatureType extends DefaultFeatureType {
298
                /**
299
                 *
300
                 */
301
                private static final long serialVersionUID = 6913732960073922540L;
302
                WeakReference parent;
303

    
304
                SubtypeFeatureType(DefaultFeatureType parent, String[] names, String[] constantsNames)
305
                        throws DataException {
306
                    super(parent, false);
307
                    DefaultFeatureAttributeDescriptor attrcopy;
308
                    Set<String> attrnames = new LinkedHashSet<>();
309
                    Set<String> requiredAttrnames = new HashSet<>();
310
                    
311
                    if ( ArrayUtils.isEmpty(names) ) {
312
                        for (FeatureAttributeDescriptor attrdesc : parent) {
313
                            attrnames.add(attrdesc.getName());
314
                        }
315
                    } else {
316
                        attrnames.addAll(Arrays.asList(names));
317
                        requiredAttrnames.addAll(Arrays.asList(names));
318
                    }
319
                    // Add required fields for emulated fields
320
                    if ( parent.hasEmulators ) {
321
                        for (FeatureAttributeDescriptor attrdesc : parent) {
322
                            FeatureAttributeEmulator emulator = attrdesc.getFeatureAttributeEmulator();
323
                            if ( emulator != null ) {
324
                                String ss[] = emulator.getRequiredFieldNames();
325
                                if ( ss != null ) {
326
                                    attrnames.addAll(Arrays.asList(ss));
327
                                    requiredAttrnames.addAll(Arrays.asList(ss));
328
                                }
329
                            }
330
                        }
331
                    }
332
                    // Add missing pk fiels
333
                    if ( !parent.hasOID() ) {
334
                        for (FeatureAttributeDescriptor attrdesc : parent) {
335
                            if ( attrdesc.isPrimaryKey() ) {
336
                                attrnames.add(attrdesc.getName());
337
                                requiredAttrnames.add(attrdesc.getName());
338
                            }
339
                        }
340
                    }
341
                        
342
                    // Copy attributes
343
                    int i = 0;
344
                    for (String name : attrnames) {
345
                        DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) parent.get(name);
346
                        if ( attr == null ) {
347
                            throw new SubtypeFeatureTypeNameException(name, parent.getId());
348
                        }
349
                        attrcopy = new DefaultFeatureAttributeDescriptor(attr);
350
                        this.add(attrcopy);
351
                        attrcopy.index = i++;
352
                    }
353
                    
354
                    // Set the consttants attributes.
355
                    if ( !ArrayUtils.isEmpty(constantsNames) ) {
356
                        for (String name : constantsNames) {
357
                            if ( !requiredAttrnames.contains(name) ) { 
358
                                DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this.get(name);
359
                                attr.setConstantValue(true);
360
                            }
361
                        }
362
                    }
363

    
364
                    this.defaultGeometryAttributeIndex = this
365
                            .getIndex(this.defaultGeometryAttributeName);
366
                    if ( this.defaultGeometryAttributeIndex < 0 ) {
367
                        this.defaultGeometryAttributeName = null;
368
                    }
369
                    this.parent = new WeakReference(parent);
370
                }
371

    
372
                public FeatureType getSubtype(String[] names) throws DataException {
373
                        return new SubtypeFeatureType((DefaultFeatureType) this.parent
374
                                        .get(), names, null);
375
                }
376

    
377
                public boolean isSubtypeOf(FeatureType featureType) {
378
                        if (featureType == null) {
379
                                return false;
380
                        }
381
                        FeatureType parent = (FeatureType) this.parent.get();
382
                        return featureType.equals(parent);
383
                }
384

    
385
                public EditableFeatureType getEditable() {
386
                        throw new UnsupportedOperationException();
387
                }
388
        }
389

    
390
        public class SubtypeFeatureTypeNameException extends DataException {
391

    
392
                /**
393
                 *
394
                 */
395
                private static final long serialVersionUID = -4414242486723260101L;
396
                private final static String MESSAGE_FORMAT = "Attribute name '%(name)' not found in type (%(type)).";
397
                private final static String MESSAGE_KEY = "_SubtypeFeatureTypeNameException";
398

    
399
                public SubtypeFeatureTypeNameException(String name, String type) {
400
                        super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
401
                        setValue("name", name);
402
                        setValue("type", type);
403
                }
404
        }
405

    
406
        public boolean hasOID() {
407
                return hasOID;
408
        }
409
        public String toString(){
410
                StringBuffer s = new StringBuffer();
411
                s.append(this.getId());
412
                s.append(":[");
413
                String attName;
414
                for (int i = 0; i < size(); i++) {
415
                        attName =((FeatureAttributeDescriptor)get(i)).getName().toString();
416
                        s.append(attName);
417
                        if (i < size() - 1) {
418
                                s.append(',');
419
                        }
420
                }
421
                s.append(']');
422
                return s.toString();
423
        }
424

    
425
        public Iterator iterator() {
426
                return getIterator(super.iterator());
427
        }
428

    
429
        protected Iterator getIterator(Iterator iter) {
430
                return new DelegatedIterator(iter);
431
        }
432

    
433
        protected class DelegatedIterator implements Iterator {
434

    
435
                protected Iterator iterator;
436

    
437
                public DelegatedIterator(Iterator iter) {
438
                        this.iterator = iter;
439
                }
440

    
441
                public boolean hasNext() {
442
                        return iterator.hasNext();
443
                }
444

    
445
                public Object next() {
446
                        return iterator.next();
447
                }
448

    
449
                public void remove() {
450
                        throw new UnsupportedOperationException();
451
                }
452

    
453
        }
454

    
455
        public boolean allowAutomaticValues() {
456
                return this.allowAtomaticValues;
457
        }
458

    
459
        public FeatureAttributeDescriptor[] getAttributeDescriptors() {
460
                return (FeatureAttributeDescriptor[]) super
461
                                .toArray(new FeatureAttributeDescriptor[super.size()]);
462
        }
463

    
464
        public FeatureAttributeDescriptor[] getPrimaryKey() {
465
                if (pk == null) {
466
                        List pks = new ArrayList();
467
                        Iterator iter = super.iterator();
468
                        FeatureAttributeDescriptor attr;
469
                        while (iter.hasNext()){
470
                                attr = (FeatureAttributeDescriptor) iter.next();
471
                                if (attr.isPrimaryKey()){
472
                                        pks.add(attr);
473
                                }
474
                        }
475
            if( pks.isEmpty() ) {
476
                pk = new FeatureAttributeDescriptor[0];
477
            } else {
478
                pk = (FeatureAttributeDescriptor[])pks.toArray(new FeatureAttributeDescriptor[pks.size()]);
479
            }
480
                }
481
                return pk;
482
        }
483

    
484
        public FeatureAttributeDescriptor getDefaultGeometryAttribute() {
485
                if (this.defaultGeometryAttributeIndex < 0) {
486
                        return null;
487
                }
488
                return (FeatureAttributeDescriptor) super
489
                                .get(this.defaultGeometryAttributeIndex);
490
        }
491

    
492

    
493

    
494
        public boolean equals(Object other) {
495
                if (this == other) {
496
                        return true;
497
                }
498
                if (!(other instanceof DefaultFeatureType)) {
499
                        return false;
500
                }
501
                DefaultFeatureType otherType = (DefaultFeatureType) other;
502
                if (!this.id.equals(otherType.id)) {
503
                        return false;
504
                }
505
                if (this.size() != otherType.size()) {
506
                        return false;
507
                }
508
                FeatureAttributeDescriptor attr,attrOther;
509
                Iterator iter,iterOther;
510
                iter = this.iterator();
511
                iterOther = otherType.iterator();
512
                while (iter.hasNext()) {
513
                        attr = (FeatureAttributeDescriptor) iter.next();
514
                        attrOther = (FeatureAttributeDescriptor) iterOther.next();
515
                        if (!attr.equals(attrOther)) {
516
                                return false;
517
                        }
518
                }
519

    
520
                if (defaultGeometryAttributeName != otherType.defaultGeometryAttributeName) {
521
                        if (defaultGeometryAttributeName == null) {
522
                                return false;
523
                        }
524
                        return defaultGeometryAttributeName
525
                                        .equals(otherType.defaultGeometryAttributeName);
526

    
527
                }
528
                return true;
529

    
530
        }
531

    
532
        /**
533
         * Start of DynClass interface implementation
534
         * READONLY
535
         */
536

    
537
        public DynField addDynField(String name) {
538
                throw new UnsupportedOperationException();
539
        }
540

    
541
        public DynField getDeclaredDynField(String name) {
542
                return (DynField) getAttributeDescriptor(name);
543
        }
544

    
545
        public DynField[] getDeclaredDynFields() {
546
                return (DynField[]) getAttributeDescriptors();
547
        }
548

    
549
        public String getDescription() {
550
                return null;
551
        }
552

    
553
        public DynField getDynField(String name) {
554
                return (DynField) getAttributeDescriptor(name);
555
        }
556

    
557
        public DynField[] getDynFields() {
558
                return (DynField[]) getAttributeDescriptors();
559
        }
560

    
561
        public String getName() {
562
                return this.id + "_" + internalID;
563
        }
564

    
565
        public void removeDynField(String name) {
566
                throw new UnsupportedOperationException();
567

    
568
        }
569

    
570
        public void addDynMethod(DynMethod dynMethod) {
571
                throw new UnsupportedOperationException();
572

    
573
        }
574

    
575
        public void extend(DynClass dynClass) {
576
                throw new UnsupportedOperationException();
577

    
578
        }
579

    
580
        public void extend(String dynClassName) {
581
                throw new UnsupportedOperationException();
582

    
583
        }
584

    
585
        public void extend(String namespace, String dynClassName) {
586
                throw new UnsupportedOperationException();
587

    
588
        }
589

    
590
        public DynMethod getDeclaredDynMethod(String name)
591
                        throws DynMethodException {
592
                return null;
593
        }
594

    
595
        public DynMethod[] getDeclaredDynMethods() throws DynMethodException {
596
                return null;
597
        }
598

    
599
        public DynMethod getDynMethod(String name) throws DynMethodException {
600
                return null;
601
        }
602

    
603
        public DynMethod getDynMethod(int code) throws DynMethodException {
604
                return null;
605
        }
606

    
607
        public DynMethod[] getDynMethods() throws DynMethodException {
608
                return null;
609
        }
610

    
611
        public DynClass[] getSuperDynClasses() {
612
                return null;
613
        }
614

    
615
        public boolean isInstance(DynObject dynObject) {
616
                if (dynObject.getDynClass().getName() == getName()) {
617
                        return true;
618
                }
619
                return false;
620
        }
621

    
622
        public DynObject newInstance() {
623

    
624
                throw new UnsupportedOperationException();
625
        }
626

    
627
        public void removeDynMethod(String name) {
628
                throw new UnsupportedOperationException();
629

    
630
        }
631

    
632
        public DynField addDynFieldChoice(String name, int type,
633
                        Object defaultValue, DynObjectValueItem[] values,
634
                        boolean mandatory, boolean persistent) {
635
                throw new UnsupportedOperationException();
636
        }
637

    
638
        public DynField addDynFieldRange(String name, int type,
639
                        Object defaultValue, Object min, Object max, boolean mandatory,
640
                        boolean persistent) {
641
                throw new UnsupportedOperationException();
642
        }
643

    
644
        public DynField addDynFieldSingle(String name, int type,
645
                        Object defaultValue, boolean mandatory, boolean persistent) {
646
                throw new UnsupportedOperationException();
647
        }
648

    
649
        public void validate(DynObject object) throws DynObjectValidateException {
650
                //FIXME: not sure it's the correct code
651
                if (object instanceof Feature) {
652
                        Feature fea = (Feature) object;
653
                        if (fea.getType().equals(this)) {
654
                                return;
655
                        }
656
                }
657
                throw new DynObjectValidateException(this.id);
658
        }
659

    
660
        public DynField addDynFieldLong(String name) {
661
                throw new UnsupportedOperationException();
662
        }
663

    
664
        public DynField addDynFieldChoice(String name, int type,
665
                        Object defaultValue, DynObjectValueItem[] values) {
666
                throw new UnsupportedOperationException();
667
        }
668

    
669
        public DynField addDynFieldRange(String name, int type,
670
                        Object defaultValue, Object min, Object max) {
671
                throw new UnsupportedOperationException();
672
        }
673

    
674
        public DynField addDynFieldSingle(String name, int type, Object defaultValue) {
675
                throw new UnsupportedOperationException();
676
        }
677

    
678
        public DynField addDynFieldString(String name) {
679
                throw new UnsupportedOperationException();
680
        }
681

    
682
        public DynField addDynFieldInt(String name) {
683
                throw new UnsupportedOperationException();
684
        }
685

    
686
        public DynField addDynFieldDouble(String name) {
687
                throw new UnsupportedOperationException();
688
        }
689

    
690
        public DynField addDynFieldFloat(String name) {
691
                throw new UnsupportedOperationException();
692
        }
693

    
694
        public DynField addDynFieldBoolean(String name) {
695
                throw new UnsupportedOperationException();
696
        }
697

    
698
        public DynField addDynFieldList(String name) {
699
                throw new UnsupportedOperationException();
700
        }
701

    
702
        public DynField addDynFieldMap(String name) {
703
                throw new UnsupportedOperationException();
704
        }
705

    
706
        public DynField addDynFieldObject(String name) {
707
                throw new UnsupportedOperationException();
708
        }
709

    
710
        public DynField addDynFieldSet(String name) {
711
                throw new UnsupportedOperationException();
712
        }
713

    
714
        public DynField addDynFieldArray(String name) {
715
                throw new UnsupportedOperationException();
716
        }
717

    
718
        public DynField addDynFieldDate(String name) {
719
                throw new UnsupportedOperationException();
720
        }
721

    
722
        public void extend(DynStruct struct) {
723
                throw new UnsupportedOperationException();
724
        }
725

    
726
        public String getFullName() {
727
        // TODO: usar el DynClassName
728
                return this.id;
729
        }
730

    
731
        public String getNamespace() {
732
                return "DALFeature";
733
        }
734

    
735
        public DynStruct[] getSuperDynStructs() {
736
                return null;
737
        }
738

    
739
        public void setDescription(String description) {
740
                throw new UnsupportedOperationException();
741
        }
742

    
743
        public void setNamespace(String namespace) {
744
                throw new UnsupportedOperationException();
745
        }
746

    
747
        public DynField addDynFieldFile(String name) {
748
                throw new UnsupportedOperationException();
749
        }
750

    
751
        public DynField addDynFieldFolder(String name) {
752
                throw new UnsupportedOperationException();
753
        }
754

    
755
        public DynField addDynFieldURL(String name) {
756
                throw new UnsupportedOperationException();
757
        }
758

    
759
        public DynField addDynFieldURI(String name) {
760
                throw new UnsupportedOperationException();
761
        }
762

    
763
    public boolean isExtendable(DynStruct dynStruct) {
764
        return false;
765
    }
766

    
767
        public void extend(DynStruct[] structs) {
768
                // TODO Auto-generated method stub
769

    
770
        }
771

    
772
        public void remove(DynStruct superDynStruct) {
773
                // TODO Auto-generated method stub
774

    
775
        }
776

    
777
        public void removeAll(DynStruct[] superDynStruct) {
778
                // TODO Auto-generated method stub
779

    
780
        }
781

    
782
        public FeatureAttributeDescriptor getDefaultTimeAttribute() {
783
                if (this.defaultTimeAttributeIndex < 0) {
784
                        return null;
785
                }
786
                return (FeatureAttributeDescriptor) super
787
                                .get(this.defaultTimeAttributeIndex);
788
        }
789

    
790
    public void setDefaultTimeAttributeName(String name) {
791
        if (name == null || name.length() == 0) {
792
            this.defaultTimeAttributeIndex = -1;
793
            return;
794
        }
795
        DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this.get(name);
796
        if (attr == null) {
797
            throw new IllegalArgumentException("Attribute '" + name + "' not found.");
798
        }
799
        if( attr.getIndex()<0 ) {
800
            fixAll();
801
        }
802
        this.defaultTimeAttributeIndex = attr.getIndex();
803
    }
804
    
805
    protected void fixAll() {
806
        int i = 0;
807
        Iterator iter = super.iterator();
808
        DefaultFeatureAttributeDescriptor attr;
809

    
810
        while (iter.hasNext()) {
811
            attr = (DefaultFeatureAttributeDescriptor) iter.next();
812
            attr.setIndex(i++);
813
            if (attr instanceof DefaultEditableFeatureAttributeDescriptor) {
814
                ((DefaultEditableFeatureAttributeDescriptor) attr).fixAll();
815
            }
816
            if (attr.getEvaluator() != null) {
817
                this.hasEvaluators = true;
818
            }
819
            if (attr.getFeatureAttributeEmulator() != null) {
820
                this.hasEmulators = true;
821
                String[] x = attr.getFeatureAttributeEmulator().getRequiredFieldNames();
822
                if( !ArrayUtils.isEmpty(x) ) {
823
                    this.requiredFields = true;
824
                }
825
            }
826
            if (this.defaultGeometryAttributeName == null && attr.getType() == DataTypes.GEOMETRY) {
827
                this.defaultGeometryAttributeName = attr.getName();
828
            }
829
        }
830
        if (this.defaultGeometryAttributeName != null) {
831
            this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName);
832
        }
833
        this.internalID = Long.toHexString(this.getCRC());
834
        
835
    }
836
    
837
    protected long getCRC() {
838
        StringBuffer buffer = new StringBuffer();
839
        for (int i = 0; i < this.size(); i++) {
840
            FeatureAttributeDescriptor x = this.getAttributeDescriptor(i);
841
            buffer.append(x.getName());
842
            buffer.append(x.getDataTypeName());
843
            buffer.append(x.getSize());
844
        }
845
        CRC32 crc = new CRC32();
846
        byte[] data = buffer.toString().getBytes();
847
        crc.update(data);
848
        return crc.getValue();
849
    }
850

    
851
    @Override
852
    public FeatureStore getStore() {
853
        if( this.storeRef == null ) {
854
            return null;
855
        }
856
        return (FeatureStore) this.storeRef.get();
857
    }
858

    
859
}