Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / data / vectorial / FeatureType.java @ 20972

History | View | Annotate | Download (5.64 KB)

1
package org.gvsig.data.vectorial;
2

    
3
import java.text.DateFormat;
4
import java.util.ArrayList;
5
import java.util.Iterator;
6
import java.util.List;
7

    
8
import org.gvsig.data.DataException;
9
import org.gvsig.data.InitializeException;
10

    
11
public class FeatureType extends ArrayList implements IFeatureType{
12
        /**
13
         *
14
         */
15
        private static final long serialVersionUID = 5120922022663837016L;
16
        protected List featureRules=new ArrayList();//<IFeatureRule>
17
        private String geometryColumn;
18
        private List allSRS;
19
        private String defaultSRS;
20
        private int[] geometryTypes = new int[0];
21
        private DateFormat dateFormat=DateFormat.getDateInstance();
22
        private String[] fieldsId;
23

    
24
        private int count=0;
25

    
26
        public FeatureType(){
27

    
28
        }
29
        public void addRule(IFeatureRule rule) {
30
                featureRules.add(rule);
31
        }
32

    
33
        public void clearRules() {
34
                featureRules.clear();
35
        }
36

    
37

    
38
        public void validateFeatureEnd(IFeature feature, IFeatureStore featureStore) {
39
                Iterator rulesIterator=featureRules.iterator();
40
                IFeatureRule rule;
41
                while(rulesIterator.hasNext()){
42
                        rule = (IFeatureRule)rulesIterator.next();
43
                        if (rule.checkAtEnd()){
44
                                rule.validate(feature,featureStore);
45
                        }
46
                }
47
        }
48

    
49
        public void validateFeatureModifiction(IFeature feature, IFeatureStore featureStore) {
50
                Iterator rulesIterator=featureRules.iterator();
51
                IFeatureRule rule;
52
                while(rulesIterator.hasNext()){
53
                        rule = (IFeatureRule)rulesIterator.next();
54
                        if (rule.checkAtModification()){
55
                                rule.validate(feature,featureStore);
56
                        }
57
                }
58
        }
59

    
60
        public void validateFeature(IFeature feature, IFeatureStore featureStore) {
61
                Iterator rulesIterator=featureRules.iterator();
62
                IFeatureRule rule;
63
                while(rulesIterator.hasNext()){
64
                        rule = (IFeatureRule)rulesIterator.next();
65
                        rule.validate(feature,featureStore);
66
                }
67
        }
68

    
69
        public void setDefaultGeometry(String name) {
70
                this.geometryColumn=name;
71

    
72
        }
73

    
74
        public String getDefaultGeometry() {
75
                return geometryColumn;
76
        }
77

    
78
        public IFeature create(IFeatureStore store) throws InitializeException {
79
                return store.createFeature(this);
80
        }
81

    
82
        public List getAllSRS() {
83
                return allSRS;
84
        }
85

    
86
        public String getDefaultSRS() {
87
                return defaultSRS;
88
        }
89

    
90
        public int[] getGeometryTypes() {
91
                return geometryTypes;
92
        }
93

    
94

    
95
        public void setAllSRS(List allSRS) {
96
                this.allSRS = allSRS;
97
        }
98

    
99
        public void setDefaultSRS(String defaultSRS) {
100
                this.defaultSRS = defaultSRS;
101
        }
102

    
103
        public DateFormat getDateFormat() {
104
                return dateFormat;
105
        }
106

    
107
        public void setDateFormat(DateFormat dateFormat) {
108
                this.dateFormat=dateFormat;
109
        }
110

    
111
        public void setGeometryTypes(int[] geometryTypes) {
112
                this.geometryTypes=geometryTypes;
113
        }
114

    
115
        public String[] getFieldsId() {
116
                return fieldsId;
117
        }
118

    
119
        public void setFieldsId(String[] fieldsId) throws DataException {
120
                this.fieldsId = fieldsId;
121
                if (fieldsId != null) {
122
                        AttributeDescriptor attr = null;
123
                        int index = -1;
124
                        for (int i = 0; i < fieldsId.length; i++) {
125
                                index = this.getFieldIndex(fieldsId[i]);
126
                                if (!(index < 0 || index >= this.size())) {
127
                                        attr = (AttributeDescriptor) this.get(index);
128
                                        attr.loading();
129
                                        attr.setPrimaryKey(true);
130
                                        attr.stopLoading();
131
                                } else {
132
                                        throw new DataException("Field '" +fieldsId[i] + "' not found");
133
                                }
134
                        }
135
                }
136
        }
137

    
138
        public int getFieldIndex(String name) {
139
                int i;
140
                for (i=0;i<this.size();i++){
141
                        if (((IFeatureAttributeDescriptor)this.get(i)).getName().equals(name))
142
                                return i;
143
                }
144
                return -1;
145
        }
146

    
147
        public void add(int arg0, Object arg1) {
148
                throw new RuntimeException("Not supported!");
149
        }
150

    
151
        public boolean add(Object arg0) {
152
                ((AttributeDescriptor)arg0).setOrdinal(count);
153
                count++;
154
                return super.add(arg0);
155
        }
156

    
157
        public boolean addWithoutOrdinal(Object arg0) {
158
                int max=((IFeatureAttributeDescriptor)arg0).ordinal();
159
                if (count<=max){
160
                        count=max+1;
161
                }
162
                return super.add(arg0);
163
        }
164

    
165
        public IFeatureType cloneFeatureType() {
166
                FeatureType newFType = (FeatureType) this.newFeatureType();
167
                if (this.allSRS != null){
168
                        newFType.allSRS = new ArrayList();
169
                        newFType.allSRS.addAll(this.allSRS);
170
                }
171
                newFType.dateFormat = this.dateFormat;
172
                newFType.defaultSRS = this.defaultSRS;
173
                newFType.featureRules.addAll(this.featureRules);
174
                if (this.fieldsId != null){
175
                        newFType.fieldsId = new String[this.fieldsId.length];
176
                        System.arraycopy(this.fieldsId, 0, newFType.fieldsId, 0, this.fieldsId.length);
177
                }
178
                newFType.geometryColumn = this.geometryColumn;
179
                if (this.geometryTypes != null){
180
                        newFType.geometryTypes = new int[this.geometryTypes.length];
181
                        System.arraycopy(this.geometryTypes, 0, newFType.geometryTypes, 0, this.geometryTypes.length);
182
                }
183
                Iterator iter = this.iterator();
184
                while (iter.hasNext()){
185
                        newFType.addWithoutOrdinal(((IFeatureAttributeDescriptor)iter.next()).cloneAttribute());
186
                }
187
                newFType.count=this.count;
188
                return newFType;
189
        }
190

    
191
        protected IFeatureType newFeatureType(){
192
                return new FeatureType();
193

    
194
        }
195

    
196
        public Object get(String name){
197
                return this.get(this.getFieldIndex(name));
198
        }
199
        public int getCount() {
200
                return count;
201
        }
202
        public IFeatureAttributeDescriptor getByOrder(int i) {
203
                Iterator iterator=this.iterator();
204
                while (iterator.hasNext()) {
205
                        IFeatureAttributeDescriptor fad = (IFeatureAttributeDescriptor) iterator.next();
206
                        if (i==fad.ordinal()){
207
                                return fad;
208
                        }
209
                }
210
                return null;
211
        }
212

    
213
        /* (non-Javadoc)
214
         * @see org.gvsig.data.vectorial.IFeatureType#createNewAttributeDescriptor()
215
         */
216
        public IFeatureAttributeDescriptor createNewAttributeDescriptor() {
217
                return new AttributeDescriptor(this,true);
218
        }
219

    
220

    
221
        public IFeatureAttributeDescriptor createAttributeDescriptor() {
222
                return new AttributeDescriptor(this,false);
223
        }
224

    
225
}