svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / DefaultFeatureAttributeDescriptor.java @ 30079
History | View | Annotate | Download (6.18 KB)
1 |
package org.gvsig.fmap.dal.feature.impl; |
---|---|
2 |
|
3 |
import java.text.DateFormat; |
4 |
import java.util.HashMap; |
5 |
import java.util.Iterator; |
6 |
import java.util.Map; |
7 |
import java.util.Map.Entry; |
8 |
|
9 |
import org.cresques.cts.IProjection; |
10 |
import org.gvsig.fmap.dal.DataTypes; |
11 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
12 |
import org.gvsig.fmap.dal.feature.exception.UnsupportedDataTypeException; |
13 |
import org.gvsig.fmap.geom.Geometry; |
14 |
import org.gvsig.tools.evaluator.Evaluator; |
15 |
|
16 |
public class DefaultFeatureAttributeDescriptor implements |
17 |
FeatureAttributeDescriptor { |
18 |
|
19 |
protected boolean allowNull; |
20 |
protected int dataType; |
21 |
protected DateFormat dateFormat; |
22 |
protected Object defaultValue; |
23 |
protected int index; |
24 |
protected int maximumOccurrences; |
25 |
protected int minimumOccurrences; |
26 |
protected int size; |
27 |
protected String name; |
28 |
protected Class objectClass; |
29 |
protected int precision; |
30 |
protected Evaluator evaluator;
|
31 |
protected boolean primaryKey; |
32 |
protected boolean readOnly; |
33 |
protected IProjection SRS;
|
34 |
protected int geometryType; |
35 |
protected int geometrySubType; |
36 |
protected Map additionalInfo; |
37 |
protected boolean isAutomatic; |
38 |
|
39 |
|
40 |
protected DefaultFeatureAttributeDescriptor() {
|
41 |
this.allowNull = true; |
42 |
this.dataType = DataTypes.UNKNOWN;
|
43 |
this.dateFormat = null; |
44 |
this.defaultValue = null; |
45 |
this.index = -1; |
46 |
this.maximumOccurrences = 0; |
47 |
this.minimumOccurrences = 0; |
48 |
this.size = 0; |
49 |
this.name = null; |
50 |
this.objectClass = null; |
51 |
this.precision = 0; |
52 |
this.evaluator = null; |
53 |
this.primaryKey = false; |
54 |
this.readOnly = false; |
55 |
this.SRS = null; |
56 |
this.geometryType = Geometry.TYPES.NULL;
|
57 |
this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
|
58 |
this.additionalInfo = null; |
59 |
this.isAutomatic = false; |
60 |
} |
61 |
|
62 |
protected DefaultFeatureAttributeDescriptor(
|
63 |
DefaultFeatureAttributeDescriptor other) { |
64 |
this.allowNull = other.allowNull;
|
65 |
this.dataType = other.dataType;
|
66 |
this.dateFormat = other.dateFormat;
|
67 |
this.defaultValue = other.defaultValue;
|
68 |
this.index = other.index;
|
69 |
this.maximumOccurrences = other.maximumOccurrences;
|
70 |
this.minimumOccurrences = other.minimumOccurrences;
|
71 |
this.size = other.size;
|
72 |
this.name = other.name;
|
73 |
this.objectClass = other.objectClass;
|
74 |
this.precision = other.precision;
|
75 |
this.evaluator = other.evaluator;
|
76 |
this.primaryKey = other.primaryKey;
|
77 |
this.readOnly = other.readOnly;
|
78 |
this.SRS = other.SRS;
|
79 |
this.geometryType = other.geometryType;
|
80 |
this.geometrySubType = other.geometrySubType;
|
81 |
if (other.additionalInfo != null) { |
82 |
Iterator iter = other.additionalInfo.entrySet().iterator();
|
83 |
Map.Entry entry;
|
84 |
this.additionalInfo = new HashMap(); |
85 |
while (iter.hasNext()) {
|
86 |
entry = (Entry) iter.next(); |
87 |
this.additionalInfo.put(entry.getKey(), entry.getValue());
|
88 |
} |
89 |
} else {
|
90 |
this.additionalInfo = null; |
91 |
} |
92 |
this.isAutomatic = other.isAutomatic;
|
93 |
} |
94 |
|
95 |
public String getDataTypeName() { |
96 |
return DataTypes.TYPE_NAMES[this.getDataType()]; |
97 |
} |
98 |
|
99 |
public FeatureAttributeDescriptor getCopy() {
|
100 |
return new DefaultFeatureAttributeDescriptor(this); |
101 |
} |
102 |
|
103 |
public boolean allowNull() { |
104 |
return allowNull;
|
105 |
} |
106 |
|
107 |
public int getDataType() { |
108 |
return this.dataType; |
109 |
} |
110 |
|
111 |
public DateFormat getDateFormat() { |
112 |
return this.dateFormat; |
113 |
} |
114 |
|
115 |
public Object getDefaultValue() { |
116 |
return this.defaultValue; |
117 |
} |
118 |
|
119 |
public Evaluator getEvaluator() {
|
120 |
return this.evaluator; |
121 |
} |
122 |
|
123 |
public int getGeometryType() { |
124 |
return this.geometryType; |
125 |
} |
126 |
|
127 |
public int getGeometrySubType() { |
128 |
return this.geometrySubType; |
129 |
} |
130 |
|
131 |
public int getIndex() { |
132 |
return this.index; |
133 |
} |
134 |
|
135 |
protected FeatureAttributeDescriptor setIndex(int index) { |
136 |
this.index = index;
|
137 |
return this; |
138 |
} |
139 |
|
140 |
public int getMaximumOccurrences() { |
141 |
return this.maximumOccurrences; |
142 |
} |
143 |
|
144 |
public int getMinimumOccurrences() { |
145 |
return this.minimumOccurrences; |
146 |
} |
147 |
|
148 |
public String getName() { |
149 |
return this.name; |
150 |
} |
151 |
|
152 |
public Class getObjectClass() { |
153 |
if (this.dataType > DataTypes.TYPE_CLASS.length || this.dataType < 0) { |
154 |
throw new UnsupportedDataTypeException(this.name, this.dataType); |
155 |
} |
156 |
return DataTypes.TYPE_CLASS[this.dataType]; |
157 |
} |
158 |
|
159 |
public int getPrecision() { |
160 |
return this.precision; |
161 |
} |
162 |
|
163 |
public IProjection getSRS() {
|
164 |
return this.SRS; |
165 |
} |
166 |
|
167 |
public int getSize() { |
168 |
return this.size; |
169 |
} |
170 |
|
171 |
public boolean isPrimaryKey() { |
172 |
return this.primaryKey; |
173 |
} |
174 |
|
175 |
public boolean isReadOnly() { |
176 |
return this.readOnly; |
177 |
} |
178 |
|
179 |
public Object getAdditionalInfo(String infoName) { |
180 |
if (this.additionalInfo == null) { |
181 |
return null; |
182 |
} |
183 |
return this.additionalInfo.get(infoName); |
184 |
} |
185 |
|
186 |
public boolean isAutomatic() { |
187 |
return this.isAutomatic; |
188 |
} |
189 |
|
190 |
private boolean compareObject(Object a, Object b) { |
191 |
if (a != b) {
|
192 |
if (a != null) { |
193 |
return false; |
194 |
} |
195 |
return a.equals(b);
|
196 |
} |
197 |
return true; |
198 |
|
199 |
} |
200 |
|
201 |
public boolean equals(Object obj) { |
202 |
if (this == obj) { |
203 |
return true; |
204 |
} |
205 |
if (!(obj instanceof DefaultFeatureAttributeDescriptor)) { |
206 |
return false; |
207 |
} |
208 |
DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) obj; |
209 |
|
210 |
if (this.allowNull != other.allowNull) { |
211 |
return false; |
212 |
} |
213 |
|
214 |
if (this.index != other.index) { |
215 |
return false; |
216 |
} |
217 |
|
218 |
if (!compareObject(this.name, other.name)) { |
219 |
return false; |
220 |
} |
221 |
|
222 |
if (this.dataType != other.dataType) { |
223 |
return false; |
224 |
} |
225 |
|
226 |
if (this.size != other.size) { |
227 |
return false; |
228 |
} |
229 |
|
230 |
if (!compareObject(this.defaultValue, other.defaultValue)) { |
231 |
return false; |
232 |
} |
233 |
|
234 |
if (!compareObject(this.defaultValue, other.defaultValue)) { |
235 |
return false; |
236 |
} |
237 |
|
238 |
if (this.primaryKey != other.primaryKey) { |
239 |
return false; |
240 |
} |
241 |
|
242 |
if (this.isAutomatic != other.isAutomatic) { |
243 |
return false; |
244 |
} |
245 |
|
246 |
if (this.readOnly != other.readOnly) { |
247 |
return false; |
248 |
} |
249 |
|
250 |
if (this.precision != other.precision) { |
251 |
return false; |
252 |
} |
253 |
|
254 |
if (this.maximumOccurrences != other.maximumOccurrences) { |
255 |
return false; |
256 |
} |
257 |
|
258 |
if (this.minimumOccurrences != other.minimumOccurrences) { |
259 |
return false; |
260 |
} |
261 |
if (this.geometryType != other.geometryType) { |
262 |
return false; |
263 |
} |
264 |
|
265 |
if (this.geometrySubType != other.geometrySubType) { |
266 |
return false; |
267 |
} |
268 |
|
269 |
if (!compareObject(this.evaluator, other.evaluator)) { |
270 |
return false; |
271 |
} |
272 |
|
273 |
if (!compareObject(this.SRS, other.SRS)) { |
274 |
return false; |
275 |
} |
276 |
|
277 |
if (!compareObject(this.dateFormat, other.dateFormat)) { |
278 |
return false; |
279 |
} |
280 |
|
281 |
if (!compareObject(this.objectClass, other.objectClass)) { |
282 |
return false; |
283 |
} |
284 |
|
285 |
return true; |
286 |
} |
287 |
} |