svn-gvsig-desktop / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / FeatureType.java @ 20606
History | View | Annotate | Download (4.71 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.exception.InitializeException; |
9 |
|
10 |
public class FeatureType extends ArrayList implements IFeatureType{ |
11 |
protected List featureRules=new ArrayList();//<IFeatureRule> |
12 |
private String geometryColumn; |
13 |
private List allSRS; |
14 |
private String defaultSRS; |
15 |
private int[] geometryTypes=new int[]{1}; |
16 |
private DateFormat dateFormat=DateFormat.getDateInstance(); |
17 |
private String[] fieldsId; |
18 |
|
19 |
private int count=0; |
20 |
|
21 |
public FeatureType(){
|
22 |
|
23 |
} |
24 |
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 |
public IFeature create(IFeatureStore store) throws InitializeException { |
74 |
return store.createFeature(this); |
75 |
} |
76 |
|
77 |
public List getAllSRS() { |
78 |
return allSRS;
|
79 |
} |
80 |
|
81 |
public String getDefaultSRS() { |
82 |
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 |
public void setDefaultSRS(String defaultSRS) { |
95 |
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 |
|
110 |
public String[] getFieldsId() { |
111 |
return fieldsId;
|
112 |
} |
113 |
|
114 |
public void setFieldsId(String[] fieldsId) { |
115 |
this.fieldsId=fieldsId;
|
116 |
} |
117 |
|
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 |
|
127 |
public void add(int arg0, Object arg1) { |
128 |
throw new RuntimeException("Not supported!"); |
129 |
} |
130 |
|
131 |
public boolean add(Object arg0) { |
132 |
((AttributeDescriptor)arg0).setOrdinal(count); |
133 |
count++; |
134 |
return super.add(arg0); |
135 |
} |
136 |
|
137 |
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 |
public IFeatureType cloneFeatureType() {
|
146 |
FeatureType newFType = (FeatureType) 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 |
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 |
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 |
newFType.addWithoutOrdinal(((IFeatureAttributeDescriptor)iter.next()).cloneAttribute()); |
166 |
} |
167 |
newFType.count=this.count;
|
168 |
return newFType;
|
169 |
} |
170 |
|
171 |
protected IFeatureType newFeatureType(){
|
172 |
return new FeatureType(); |
173 |
|
174 |
} |
175 |
|
176 |
public Object get(String name){ |
177 |
return this.get(this.getFieldIndex(name)); |
178 |
} |
179 |
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 |
} |