root / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / DefaultFeatureType.java @ 20599
History | View | Annotate | Download (4.75 KB)
1 | 19399 | vcaballero | 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 | 20599 | jmvivo | import org.gvsig.data.exception.InitializeException; |
9 | |||
10 | 19399 | vcaballero | public class DefaultFeatureType extends ArrayList implements IFeatureType{ |
11 | protected List featureRules=new ArrayList();//<IFeatureRule> |
||
12 | private String geometryColumn; |
||
13 | private List allSRS; |
||
14 | 19414 | vcaballero | private String defaultSRS; |
15 | 19908 | vcaballero | private int[] geometryTypes=new int[]{1}; |
16 | 19399 | vcaballero | private DateFormat dateFormat=DateFormat.getDateInstance(); |
17 | 20131 | jmvivo | private String[] fieldsId; |
18 | 19399 | vcaballero | |
19 | 20599 | jmvivo | private int count=0; |
20 | 20440 | vcaballero | |
21 | public DefaultFeatureType(){
|
||
22 | |||
23 | } |
||
24 | 19399 | vcaballero | public void addRule(IFeatureRule rule) { |
25 | featureRules.add(rule); |
||
26 | } |
||
27 | |||
28 | public void clearRules() { |
||
29 | featureRules.clear(); |
||
30 | } |
||
31 | |||
32 | |||
33 | public void validateFeatureEnd(IFeature feature, IFeatureStore featureStore) { |
||
34 | Iterator rulesIterator=featureRules.iterator();
|
||
35 | IFeatureRule rule; |
||
36 | while(rulesIterator.hasNext()){
|
||
37 | rule = (IFeatureRule)rulesIterator.next(); |
||
38 | if (rule.checkAtEnd()){
|
||
39 | rule.validate(feature,featureStore); |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | |||
44 | public void validateFeatureModifiction(IFeature feature, IFeatureStore featureStore) { |
||
45 | Iterator rulesIterator=featureRules.iterator();
|
||
46 | IFeatureRule rule; |
||
47 | while(rulesIterator.hasNext()){
|
||
48 | rule = (IFeatureRule)rulesIterator.next(); |
||
49 | if (rule.checkAtModification()){
|
||
50 | rule.validate(feature,featureStore); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | |||
55 | public void validateFeature(IFeature feature, IFeatureStore featureStore) { |
||
56 | Iterator rulesIterator=featureRules.iterator();
|
||
57 | IFeatureRule rule; |
||
58 | while(rulesIterator.hasNext()){
|
||
59 | rule = (IFeatureRule)rulesIterator.next(); |
||
60 | rule.validate(feature,featureStore); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | public void setDefaultGeometry(String name) { |
||
65 | this.geometryColumn=name;
|
||
66 | |||
67 | } |
||
68 | |||
69 | public String getDefaultGeometry() { |
||
70 | return geometryColumn;
|
||
71 | } |
||
72 | |||
73 | 20599 | jmvivo | public IFeature create(IFeatureStore store) throws InitializeException { |
74 | 19399 | vcaballero | return store.createFeature(this); |
75 | } |
||
76 | |||
77 | public List getAllSRS() { |
||
78 | return allSRS;
|
||
79 | } |
||
80 | |||
81 | 19414 | vcaballero | public String getDefaultSRS() { |
82 | 19399 | vcaballero | return defaultSRS;
|
83 | } |
||
84 | |||
85 | public int[] getGeometryTypes() { |
||
86 | return geometryTypes;
|
||
87 | } |
||
88 | |||
89 | |||
90 | public void setAllSRS(List allSRS) { |
||
91 | this.allSRS = allSRS;
|
||
92 | } |
||
93 | |||
94 | 19414 | vcaballero | public void setDefaultSRS(String defaultSRS) { |
95 | 19399 | vcaballero | this.defaultSRS = defaultSRS;
|
96 | } |
||
97 | |||
98 | public DateFormat getDateFormat() { |
||
99 | return dateFormat;
|
||
100 | } |
||
101 | |||
102 | public void setDateFormat(DateFormat dateFormat) { |
||
103 | this.dateFormat=dateFormat;
|
||
104 | } |
||
105 | |||
106 | public void setGeometryTypes(int[] geometryTypes) { |
||
107 | this.geometryTypes=geometryTypes;
|
||
108 | } |
||
109 | 19548 | vcaballero | |
110 | 20131 | jmvivo | public String[] getFieldsId() { |
111 | return fieldsId;
|
||
112 | 19548 | vcaballero | } |
113 | |||
114 | 20131 | jmvivo | public void setFieldsId(String[] fieldsId) { |
115 | this.fieldsId=fieldsId;
|
||
116 | 19548 | vcaballero | } |
117 | 19608 | jmvivo | |
118 | public int getFieldIndex(String name) { |
||
119 | int i;
|
||
120 | for (i=0;i<this.size();i++){ |
||
121 | if (((IFeatureAttributeDescriptor)this.get(i)).getName().equals(name)) |
||
122 | return i;
|
||
123 | } |
||
124 | return -1; |
||
125 | } |
||
126 | 19665 | jmvivo | |
127 | public void add(int arg0, Object arg1) { |
||
128 | 20440 | vcaballero | throw new RuntimeException("Not supported!"); |
129 | 19665 | jmvivo | } |
130 | |||
131 | public boolean add(Object arg0) { |
||
132 | 20599 | jmvivo | ((DefaultAttributeDescriptor)arg0).setOrdinal(count); |
133 | 20440 | vcaballero | count++; |
134 | 19665 | jmvivo | return super.add(arg0); |
135 | } |
||
136 | 19692 | jmvivo | |
137 | 20469 | vcaballero | public boolean addWithoutOrdinal(Object arg0) { |
138 | int max=((IFeatureAttributeDescriptor)arg0).ordinal();
|
||
139 | if (count<max){
|
||
140 | count=max; |
||
141 | } |
||
142 | return super.add(arg0); |
||
143 | } |
||
144 | |||
145 | 19695 | jmvivo | public IFeatureType cloneFeatureType() {
|
146 | DefaultFeatureType newFType = (DefaultFeatureType) this.newFeatureType();
|
||
147 | if (this.allSRS != null){ |
||
148 | newFType.allSRS = new ArrayList(); |
||
149 | newFType.allSRS.addAll(this.allSRS);
|
||
150 | } |
||
151 | newFType.dateFormat = this.dateFormat;
|
||
152 | newFType.defaultSRS = this.defaultSRS;
|
||
153 | newFType.featureRules.addAll(this.featureRules);
|
||
154 | 20131 | jmvivo | if (this.fieldsId != null){ |
155 | newFType.fieldsId = new String[this.fieldsId.length]; |
||
156 | System.arraycopy(this.fieldsId, 0, newFType.fieldsId, 0, this.fieldsId.length); |
||
157 | } |
||
158 | 19695 | jmvivo | newFType.geometryColumn = this.geometryColumn;
|
159 | if (this.geometryTypes != null){ |
||
160 | newFType.geometryTypes = new int[this.geometryTypes.length]; |
||
161 | System.arraycopy(this.geometryTypes, 0, newFType.geometryTypes, 0, this.geometryTypes.length); |
||
162 | } |
||
163 | Iterator iter = this.iterator(); |
||
164 | while (iter.hasNext()){
|
||
165 | 20469 | vcaballero | newFType.addWithoutOrdinal(((IFeatureAttributeDescriptor)iter.next()).cloneAttribute()); |
166 | 19695 | jmvivo | } |
167 | 20440 | vcaballero | newFType.count=this.count;
|
168 | 19695 | jmvivo | return newFType;
|
169 | 19692 | jmvivo | } |
170 | 19695 | jmvivo | |
171 | protected IFeatureType newFeatureType(){
|
||
172 | return new DefaultFeatureType(); |
||
173 | |||
174 | } |
||
175 | 20030 | jmvivo | |
176 | public Object get(String name){ |
||
177 | return this.get(this.getFieldIndex(name)); |
||
178 | } |
||
179 | 20469 | vcaballero | public int getCount() { |
180 | return count;
|
||
181 | } |
||
182 | public IFeatureAttributeDescriptor getByOrder(int i) { |
||
183 | Iterator iterator=this.iterator(); |
||
184 | while (iterator.hasNext()) {
|
||
185 | IFeatureAttributeDescriptor fad = (IFeatureAttributeDescriptor) iterator.next(); |
||
186 | if (i==fad.ordinal()){
|
||
187 | return fad;
|
||
188 | } |
||
189 | } |
||
190 | return null; |
||
191 | } |
||
192 | 19399 | vcaballero | } |