svn-gvsig-desktop / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / DefaultFeatureType.java @ 20131
History | View | Annotate | Download (4.13 KB)
1 |
package org.gvsig.data.vectorial; |
---|---|
2 |
|
3 |
import java.lang.reflect.Array; |
4 |
import java.text.DateFormat; |
5 |
import java.util.ArrayList; |
6 |
import java.util.Iterator; |
7 |
import java.util.List; |
8 |
|
9 |
public class DefaultFeatureType extends ArrayList implements IFeatureType{ |
10 |
protected List featureRules=new ArrayList();//<IFeatureRule> |
11 |
private String geometryColumn; |
12 |
private List allSRS; |
13 |
private String defaultSRS; |
14 |
private int[] geometryTypes=new int[]{1}; |
15 |
private DateFormat dateFormat=DateFormat.getDateInstance(); |
16 |
private String[] fieldsId; |
17 |
|
18 |
public void addRule(IFeatureRule rule) { |
19 |
featureRules.add(rule); |
20 |
} |
21 |
|
22 |
public void clearRules() { |
23 |
featureRules.clear(); |
24 |
} |
25 |
|
26 |
|
27 |
public void validateFeatureEnd(IFeature feature, IFeatureStore featureStore) { |
28 |
Iterator rulesIterator=featureRules.iterator();
|
29 |
IFeatureRule rule; |
30 |
while(rulesIterator.hasNext()){
|
31 |
rule = (IFeatureRule)rulesIterator.next(); |
32 |
if (rule.checkAtEnd()){
|
33 |
rule.validate(feature,featureStore); |
34 |
} |
35 |
} |
36 |
} |
37 |
|
38 |
public void validateFeatureModifiction(IFeature feature, IFeatureStore featureStore) { |
39 |
Iterator rulesIterator=featureRules.iterator();
|
40 |
IFeatureRule rule; |
41 |
while(rulesIterator.hasNext()){
|
42 |
rule = (IFeatureRule)rulesIterator.next(); |
43 |
if (rule.checkAtModification()){
|
44 |
rule.validate(feature,featureStore); |
45 |
} |
46 |
} |
47 |
} |
48 |
|
49 |
public void validateFeature(IFeature feature, IFeatureStore featureStore) { |
50 |
Iterator rulesIterator=featureRules.iterator();
|
51 |
IFeatureRule rule; |
52 |
while(rulesIterator.hasNext()){
|
53 |
rule = (IFeatureRule)rulesIterator.next(); |
54 |
rule.validate(feature,featureStore); |
55 |
} |
56 |
} |
57 |
|
58 |
public void setDefaultGeometry(String name) { |
59 |
this.geometryColumn=name;
|
60 |
|
61 |
} |
62 |
|
63 |
public String getDefaultGeometry() { |
64 |
return geometryColumn;
|
65 |
} |
66 |
|
67 |
public IFeature create(IFeatureStore store) {
|
68 |
return store.createFeature(this); |
69 |
} |
70 |
|
71 |
public List getAllSRS() { |
72 |
return allSRS;
|
73 |
} |
74 |
|
75 |
public String getDefaultSRS() { |
76 |
return defaultSRS;
|
77 |
} |
78 |
|
79 |
public int[] getGeometryTypes() { |
80 |
return geometryTypes;
|
81 |
} |
82 |
|
83 |
|
84 |
public void setAllSRS(List allSRS) { |
85 |
this.allSRS = allSRS;
|
86 |
} |
87 |
|
88 |
public void setDefaultSRS(String defaultSRS) { |
89 |
this.defaultSRS = defaultSRS;
|
90 |
} |
91 |
|
92 |
public DateFormat getDateFormat() { |
93 |
return dateFormat;
|
94 |
} |
95 |
|
96 |
public void setDateFormat(DateFormat dateFormat) { |
97 |
this.dateFormat=dateFormat;
|
98 |
} |
99 |
|
100 |
public void setGeometryTypes(int[] geometryTypes) { |
101 |
this.geometryTypes=geometryTypes;
|
102 |
} |
103 |
|
104 |
public String[] getFieldsId() { |
105 |
return fieldsId;
|
106 |
} |
107 |
|
108 |
public void setFieldsId(String[] fieldsId) { |
109 |
this.fieldsId=fieldsId;
|
110 |
} |
111 |
|
112 |
public int getFieldIndex(String name) { |
113 |
int i;
|
114 |
for (i=0;i<this.size();i++){ |
115 |
if (((IFeatureAttributeDescriptor)this.get(i)).getName().equals(name)) |
116 |
return i;
|
117 |
} |
118 |
return -1; |
119 |
} |
120 |
|
121 |
public void add(int arg0, Object arg1) { |
122 |
((DefaultAttributeDescriptor)arg1).setOrdinal(arg0); |
123 |
super.add(arg0, arg1);
|
124 |
} |
125 |
|
126 |
public boolean add(Object arg0) { |
127 |
((DefaultAttributeDescriptor)arg0).setOrdinal(this.size());
|
128 |
return super.add(arg0); |
129 |
} |
130 |
|
131 |
public IFeatureType cloneFeatureType() {
|
132 |
DefaultFeatureType newFType = (DefaultFeatureType) this.newFeatureType();
|
133 |
if (this.allSRS != null){ |
134 |
newFType.allSRS = new ArrayList(); |
135 |
newFType.allSRS.addAll(this.allSRS);
|
136 |
} |
137 |
newFType.dateFormat = this.dateFormat;
|
138 |
newFType.defaultSRS = this.defaultSRS;
|
139 |
newFType.featureRules.addAll(this.featureRules);
|
140 |
if (this.fieldsId != null){ |
141 |
newFType.fieldsId = new String[this.fieldsId.length]; |
142 |
System.arraycopy(this.fieldsId, 0, newFType.fieldsId, 0, this.fieldsId.length); |
143 |
} |
144 |
newFType.geometryColumn = this.geometryColumn;
|
145 |
if (this.geometryTypes != null){ |
146 |
newFType.geometryTypes = new int[this.geometryTypes.length]; |
147 |
System.arraycopy(this.geometryTypes, 0, newFType.geometryTypes, 0, this.geometryTypes.length); |
148 |
} |
149 |
Iterator iter = this.iterator(); |
150 |
while (iter.hasNext()){
|
151 |
newFType.add(((IFeatureAttributeDescriptor)iter.next()).cloneAttribute()); |
152 |
} |
153 |
|
154 |
return newFType;
|
155 |
} |
156 |
|
157 |
protected IFeatureType newFeatureType(){
|
158 |
return new DefaultFeatureType(); |
159 |
|
160 |
} |
161 |
|
162 |
public Object get(String name){ |
163 |
return this.get(this.getFieldIndex(name)); |
164 |
} |
165 |
} |