svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultFeatureAttributeDescriptor.java @ 43371
History | View | Annotate | Download (26.7 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 42561 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40559 | jjdelcerro | *
|
11 | 42561 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40559 | jjdelcerro | *
|
16 | 42561 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40559 | jjdelcerro | *
|
20 | 42561 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40559 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl; |
24 | |||
25 | import java.text.DateFormat; |
||
26 | import java.util.HashMap; |
||
27 | import java.util.Iterator; |
||
28 | import java.util.List; |
||
29 | import java.util.Map; |
||
30 | import java.util.Map.Entry; |
||
31 | 42563 | jjdelcerro | import org.apache.commons.lang3.ArrayUtils; |
32 | 40435 | jjdelcerro | import org.cresques.cts.IProjection; |
33 | import org.gvsig.fmap.crs.CRSFactory; |
||
34 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
35 | 42563 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
36 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
37 | import org.gvsig.fmap.geom.Geometry; |
||
38 | import org.gvsig.fmap.geom.GeometryException; |
||
39 | import org.gvsig.fmap.geom.GeometryLocator; |
||
40 | import org.gvsig.fmap.geom.type.GeometryType; |
||
41 | import org.gvsig.tools.ToolsLocator; |
||
42 | import org.gvsig.tools.dataTypes.CoercionException; |
||
43 | import org.gvsig.tools.dataTypes.DataType; |
||
44 | import org.gvsig.tools.dataTypes.DataTypes; |
||
45 | import org.gvsig.tools.dynobject.DynField; |
||
46 | 41323 | jjdelcerro | import org.gvsig.tools.dynobject.DynField_LabelAttribute; |
47 | 42563 | jjdelcerro | import org.gvsig.tools.dynobject.DynField_v2; |
48 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.DynMethod; |
49 | 42606 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
50 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.DynObjectValueItem; |
51 | import org.gvsig.tools.dynobject.DynStruct; |
||
52 | 42563 | jjdelcerro | import org.gvsig.tools.dynobject.Tags; |
53 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException; |
54 | import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
||
55 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.exception.DynMethodException; |
56 | 42563 | jjdelcerro | import org.gvsig.tools.dynobject.impl.DefaultTags; |
57 | 41212 | jjdelcerro | import org.gvsig.tools.evaluator.AbstractEvaluator; |
58 | 40435 | jjdelcerro | import org.gvsig.tools.evaluator.Evaluator; |
59 | 41212 | jjdelcerro | import org.gvsig.tools.evaluator.EvaluatorData; |
60 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
61 | 40435 | jjdelcerro | import org.gvsig.tools.persistence.Persistent; |
62 | import org.gvsig.tools.persistence.PersistentState; |
||
63 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
64 | |||
65 | public class DefaultFeatureAttributeDescriptor implements |
||
66 | 42563 | jjdelcerro | FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute { |
67 | 40435 | jjdelcerro | |
68 | protected boolean allowNull; |
||
69 | protected DataType dataType;
|
||
70 | protected DateFormat dateFormat; |
||
71 | protected Object defaultValue; |
||
72 | protected int index; |
||
73 | protected int maximumOccurrences; |
||
74 | protected int minimumOccurrences; |
||
75 | protected int size; |
||
76 | protected String name; |
||
77 | protected Class objectClass; |
||
78 | protected int precision; |
||
79 | protected Evaluator evaluator;
|
||
80 | protected boolean primaryKey; |
||
81 | protected boolean readOnly; |
||
82 | protected IProjection SRS;
|
||
83 | protected GeometryType geomType;
|
||
84 | protected int geometryType; |
||
85 | protected int geometrySubType; |
||
86 | protected Map additionalInfo; |
||
87 | protected boolean isAutomatic; |
||
88 | 41335 | jjdelcerro | protected boolean isTime = false; |
89 | protected FeatureAttributeGetter featureAttributeGetter = null; |
||
90 | protected FeatureAttributeEmulator featureAttributeEmulator = null; |
||
91 | 41638 | jjdelcerro | protected boolean indexed = false; |
92 | protected boolean isIndexAscending = true; |
||
93 | protected boolean allowIndexDuplicateds = true; |
||
94 | 40435 | jjdelcerro | |
95 | 42563 | jjdelcerro | protected DynObjectValueItem[] availableValues; |
96 | protected String description; |
||
97 | protected Object minValue; |
||
98 | protected Object maxValue; |
||
99 | protected String label; |
||
100 | protected int order; |
||
101 | protected boolean hidden; |
||
102 | protected String groupName; |
||
103 | protected Tags tags = new DefaultTags(); |
||
104 | 42775 | jjdelcerro | private DynMethod availableValuesMethod;
|
105 | private DynMethod calculateMethod;
|
||
106 | 42563 | jjdelcerro | |
107 | 40435 | jjdelcerro | protected DefaultFeatureAttributeDescriptor() {
|
108 | this.allowNull = true; |
||
109 | this.dataType = null; |
||
110 | this.dateFormat = null; |
||
111 | this.defaultValue = null; |
||
112 | this.index = -1; |
||
113 | this.maximumOccurrences = 0; |
||
114 | this.minimumOccurrences = 0; |
||
115 | this.size = 0; |
||
116 | this.name = null; |
||
117 | this.objectClass = null; |
||
118 | this.precision = 0; |
||
119 | this.evaluator = null; |
||
120 | this.primaryKey = false; |
||
121 | this.readOnly = false; |
||
122 | this.SRS = null; |
||
123 | this.geometryType = Geometry.TYPES.NULL;
|
||
124 | this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
|
||
125 | this.additionalInfo = null; |
||
126 | this.isAutomatic = false; |
||
127 | 43362 | jjdelcerro | this.hidden = false; |
128 | 40435 | jjdelcerro | } |
129 | |||
130 | protected DefaultFeatureAttributeDescriptor(
|
||
131 | 42561 | jjdelcerro | DefaultFeatureAttributeDescriptor other) { |
132 | 42775 | jjdelcerro | copyFrom(other); |
133 | } |
||
134 | |||
135 | @Override
|
||
136 | public void copyFrom(DynField other1) { |
||
137 | if( !(other1 instanceof DefaultFeatureAttributeDescriptor) ) { |
||
138 | throw new IllegalArgumentException("Can't copy from a non DefaultFeatureAttributeDescriptor"); |
||
139 | } |
||
140 | DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) other1; |
||
141 | 40435 | jjdelcerro | this.allowNull = other.allowNull;
|
142 | this.dataType = other.dataType;
|
||
143 | this.dateFormat = other.dateFormat;
|
||
144 | this.defaultValue = other.defaultValue;
|
||
145 | this.index = other.index;
|
||
146 | this.maximumOccurrences = other.maximumOccurrences;
|
||
147 | this.minimumOccurrences = other.minimumOccurrences;
|
||
148 | this.size = other.size;
|
||
149 | this.name = other.name;
|
||
150 | this.objectClass = other.objectClass;
|
||
151 | this.precision = other.precision;
|
||
152 | this.evaluator = other.evaluator;
|
||
153 | this.primaryKey = other.primaryKey;
|
||
154 | this.readOnly = other.readOnly;
|
||
155 | this.SRS = other.SRS;
|
||
156 | this.geometryType = other.geometryType;
|
||
157 | this.geometrySubType = other.geometrySubType;
|
||
158 | this.geomType = other.geomType;
|
||
159 | if (other.additionalInfo != null) { |
||
160 | Iterator iter = other.additionalInfo.entrySet().iterator();
|
||
161 | Map.Entry entry;
|
||
162 | this.additionalInfo = new HashMap(); |
||
163 | while (iter.hasNext()) {
|
||
164 | entry = (Entry) iter.next(); |
||
165 | this.additionalInfo.put(entry.getKey(), entry.getValue());
|
||
166 | } |
||
167 | } else {
|
||
168 | this.additionalInfo = null; |
||
169 | } |
||
170 | this.isAutomatic = other.isAutomatic;
|
||
171 | 41335 | jjdelcerro | this.isTime = other.isTime;
|
172 | this.featureAttributeEmulator = other.featureAttributeEmulator;
|
||
173 | 41638 | jjdelcerro | this.indexed = other.indexed;
|
174 | this.isIndexAscending = other.isIndexAscending;
|
||
175 | this.allowIndexDuplicateds = other.allowIndexDuplicateds;
|
||
176 | 43362 | jjdelcerro | this.hidden = other.hidden;
|
177 | 40435 | jjdelcerro | } |
178 | 42775 | jjdelcerro | |
179 | 42561 | jjdelcerro | @Override
|
180 | 40435 | jjdelcerro | public String getDataTypeName() { |
181 | 42561 | jjdelcerro | if (this.getDataType() == null) { |
182 | 40435 | jjdelcerro | return "(unknow)"; |
183 | } |
||
184 | 42561 | jjdelcerro | return this.getDataType().getName(); |
185 | 40435 | jjdelcerro | } |
186 | |||
187 | 42561 | jjdelcerro | @Override
|
188 | 40435 | jjdelcerro | public FeatureAttributeDescriptor getCopy() {
|
189 | return new DefaultFeatureAttributeDescriptor(this); |
||
190 | } |
||
191 | |||
192 | 42561 | jjdelcerro | @Override
|
193 | 42775 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
194 | return new DefaultFeatureAttributeDescriptor(this); |
||
195 | } |
||
196 | |||
197 | @Override
|
||
198 | 40435 | jjdelcerro | public boolean allowNull() { |
199 | return allowNull;
|
||
200 | } |
||
201 | |||
202 | 42561 | jjdelcerro | @Override
|
203 | 40435 | jjdelcerro | public DataType getDataType() {
|
204 | 42561 | jjdelcerro | if (featureAttributeGetter != null) { |
205 | return featureAttributeGetter.getDataType();
|
||
206 | } |
||
207 | 40435 | jjdelcerro | return this.dataType; |
208 | } |
||
209 | |||
210 | 42561 | jjdelcerro | @Override
|
211 | 40435 | jjdelcerro | public DateFormat getDateFormat() { |
212 | return this.dateFormat; |
||
213 | } |
||
214 | |||
215 | 42561 | jjdelcerro | @Override
|
216 | 40435 | jjdelcerro | public Object getDefaultValue() { |
217 | return this.defaultValue; |
||
218 | } |
||
219 | |||
220 | 42561 | jjdelcerro | @Override
|
221 | 40435 | jjdelcerro | public Evaluator getEvaluator() {
|
222 | return this.evaluator; |
||
223 | } |
||
224 | |||
225 | 42561 | jjdelcerro | @Override
|
226 | 40435 | jjdelcerro | public int getGeometryType() { |
227 | return this.geometryType; |
||
228 | } |
||
229 | |||
230 | 42561 | jjdelcerro | @Override
|
231 | 40435 | jjdelcerro | public int getGeometrySubType() { |
232 | return this.geometrySubType; |
||
233 | } |
||
234 | |||
235 | 42561 | jjdelcerro | @Override
|
236 | 40435 | jjdelcerro | public GeometryType getGeomType() {
|
237 | if (this.geomType == null) { |
||
238 | try {
|
||
239 | 42561 | jjdelcerro | this.geomType
|
240 | = GeometryLocator.getGeometryManager().getGeometryType( |
||
241 | this.geometryType, this.geometrySubType); |
||
242 | 40435 | jjdelcerro | } catch (GeometryException e) {
|
243 | throw new RuntimeException( |
||
244 | 42561 | jjdelcerro | "Error getting geometry type with type = "
|
245 | 40435 | jjdelcerro | + this.geometryType + ", subtype = " |
246 | + this.geometrySubType, e);
|
||
247 | } |
||
248 | } |
||
249 | return this.geomType; |
||
250 | } |
||
251 | |||
252 | 42561 | jjdelcerro | @Override
|
253 | 40435 | jjdelcerro | public int getIndex() { |
254 | return this.index; |
||
255 | } |
||
256 | |||
257 | protected FeatureAttributeDescriptor setIndex(int index) { |
||
258 | this.index = index;
|
||
259 | return this; |
||
260 | } |
||
261 | |||
262 | 42561 | jjdelcerro | @Override
|
263 | 40435 | jjdelcerro | public int getMaximumOccurrences() { |
264 | return this.maximumOccurrences; |
||
265 | } |
||
266 | |||
267 | 42561 | jjdelcerro | @Override
|
268 | 40435 | jjdelcerro | public int getMinimumOccurrences() { |
269 | return this.minimumOccurrences; |
||
270 | } |
||
271 | |||
272 | 42561 | jjdelcerro | @Override
|
273 | 40435 | jjdelcerro | public String getName() { |
274 | return this.name; |
||
275 | } |
||
276 | |||
277 | 42561 | jjdelcerro | @Override
|
278 | 40435 | jjdelcerro | public Class getObjectClass() { |
279 | 42561 | jjdelcerro | if (getDataType().getType() == DataTypes.OBJECT) {
|
280 | 40435 | jjdelcerro | return objectClass;
|
281 | } |
||
282 | 42561 | jjdelcerro | return getDataType().getDefaultClass();
|
283 | 40435 | jjdelcerro | } |
284 | |||
285 | 42561 | jjdelcerro | @Override
|
286 | 40435 | jjdelcerro | public int getPrecision() { |
287 | return this.precision; |
||
288 | } |
||
289 | |||
290 | 42561 | jjdelcerro | @Override
|
291 | 40435 | jjdelcerro | public IProjection getSRS() {
|
292 | return this.SRS; |
||
293 | } |
||
294 | |||
295 | 42561 | jjdelcerro | @Override
|
296 | 40435 | jjdelcerro | public int getSize() { |
297 | return this.size; |
||
298 | } |
||
299 | |||
300 | 42561 | jjdelcerro | @Override
|
301 | 40435 | jjdelcerro | public boolean isPrimaryKey() { |
302 | return this.primaryKey; |
||
303 | } |
||
304 | |||
305 | 42561 | jjdelcerro | @Override
|
306 | 40435 | jjdelcerro | public boolean isReadOnly() { |
307 | 42561 | jjdelcerro | if (this.readOnly) { |
308 | 41335 | jjdelcerro | return true; |
309 | } |
||
310 | 42561 | jjdelcerro | if (this.getEvaluator() != null) { |
311 | 41335 | jjdelcerro | return true; |
312 | } |
||
313 | 42561 | jjdelcerro | if (this.featureAttributeEmulator != null) { |
314 | 41335 | jjdelcerro | return !this.featureAttributeEmulator.allowSetting(); |
315 | } |
||
316 | return false; |
||
317 | 40435 | jjdelcerro | } |
318 | |||
319 | 42561 | jjdelcerro | @Override
|
320 | 40435 | jjdelcerro | public Object getAdditionalInfo(String infoName) { |
321 | if (this.additionalInfo == null) { |
||
322 | return null; |
||
323 | } |
||
324 | return this.additionalInfo.get(infoName); |
||
325 | } |
||
326 | |||
327 | 42561 | jjdelcerro | @Override
|
328 | 40435 | jjdelcerro | public boolean isAutomatic() { |
329 | return this.isAutomatic; |
||
330 | } |
||
331 | |||
332 | private boolean compareObject(Object a, Object b) { |
||
333 | if (a != b) {
|
||
334 | if (a == null) { |
||
335 | return false; |
||
336 | } |
||
337 | return a.equals(b);
|
||
338 | } |
||
339 | return true; |
||
340 | |||
341 | } |
||
342 | |||
343 | 42561 | jjdelcerro | @Override
|
344 | 40435 | jjdelcerro | public boolean equals(Object obj) { |
345 | if (this == obj) { |
||
346 | return true; |
||
347 | } |
||
348 | if (!(obj instanceof DefaultFeatureAttributeDescriptor)) { |
||
349 | return false; |
||
350 | } |
||
351 | 42561 | jjdelcerro | DefaultFeatureAttributeDescriptor other |
352 | = (DefaultFeatureAttributeDescriptor) obj; |
||
353 | 40435 | jjdelcerro | |
354 | if (this.allowNull != other.allowNull) { |
||
355 | return false; |
||
356 | } |
||
357 | |||
358 | if (this.index != other.index) { |
||
359 | return false; |
||
360 | } |
||
361 | |||
362 | if (!compareObject(this.name, other.name)) { |
||
363 | return false; |
||
364 | } |
||
365 | |||
366 | 42561 | jjdelcerro | if (this.getDataType() != other.getDataType()) { |
367 | 40435 | jjdelcerro | return false; |
368 | } |
||
369 | |||
370 | if (this.size != other.size) { |
||
371 | return false; |
||
372 | } |
||
373 | |||
374 | if (!compareObject(this.defaultValue, other.defaultValue)) { |
||
375 | return false; |
||
376 | } |
||
377 | |||
378 | if (!compareObject(this.defaultValue, other.defaultValue)) { |
||
379 | return false; |
||
380 | } |
||
381 | |||
382 | if (this.primaryKey != other.primaryKey) { |
||
383 | return false; |
||
384 | } |
||
385 | |||
386 | if (this.isAutomatic != other.isAutomatic) { |
||
387 | return false; |
||
388 | } |
||
389 | |||
390 | if (this.readOnly != other.readOnly) { |
||
391 | return false; |
||
392 | } |
||
393 | |||
394 | if (this.precision != other.precision) { |
||
395 | return false; |
||
396 | } |
||
397 | |||
398 | if (this.maximumOccurrences != other.maximumOccurrences) { |
||
399 | return false; |
||
400 | } |
||
401 | |||
402 | if (this.minimumOccurrences != other.minimumOccurrences) { |
||
403 | return false; |
||
404 | } |
||
405 | |||
406 | if (this.geometryType != other.geometryType) { |
||
407 | return false; |
||
408 | } |
||
409 | |||
410 | if (this.geometrySubType != other.geometrySubType) { |
||
411 | return false; |
||
412 | } |
||
413 | |||
414 | if (!compareObject(this.evaluator, other.evaluator)) { |
||
415 | return false; |
||
416 | } |
||
417 | |||
418 | if (!compareObject(this.SRS, other.SRS)) { |
||
419 | return false; |
||
420 | } |
||
421 | |||
422 | if (!compareObject(this.dateFormat, other.dateFormat)) { |
||
423 | return false; |
||
424 | } |
||
425 | |||
426 | if (!compareObject(this.objectClass, other.objectClass)) { |
||
427 | return false; |
||
428 | } |
||
429 | |||
430 | return true; |
||
431 | } |
||
432 | |||
433 | 42561 | jjdelcerro | @Override
|
434 | 40435 | jjdelcerro | public void loadFromState(PersistentState state) |
435 | 42561 | jjdelcerro | throws PersistenceException {
|
436 | 40435 | jjdelcerro | allowNull = state.getBoolean("allowNull");
|
437 | 42561 | jjdelcerro | dataType |
438 | = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
|
||
439 | 40435 | jjdelcerro | // FIXME how persist dateFormat ???
|
440 | // dateFormat;
|
||
441 | defaultValue = state.get("defaultValue");
|
||
442 | |||
443 | index = state.getInt("index");
|
||
444 | maximumOccurrences = state.getInt("maximumOccurrences");
|
||
445 | minimumOccurrences = state.getInt("minimumOccurrences");
|
||
446 | size = state.getInt("size");
|
||
447 | name = state.getString("name");
|
||
448 | try {
|
||
449 | objectClass = Class.forName(state.getString("objectClass")); |
||
450 | } catch (ClassNotFoundException e) { |
||
451 | throw new PersistenceException(e); |
||
452 | } |
||
453 | precision = state.getInt("precision");
|
||
454 | evaluator = (Evaluator) state.get("evaluator");
|
||
455 | primaryKey = state.getBoolean("primaryKey");
|
||
456 | readOnly = state.getBoolean("readOnly");
|
||
457 | String srsId = state.getString("srsId"); |
||
458 | if (srsId != null) { |
||
459 | SRS = CRSFactory.getCRS(srsId); |
||
460 | } |
||
461 | geometryType = state.getInt("geometryType");
|
||
462 | geometrySubType = state.getInt("geometrySubType");
|
||
463 | additionalInfo = (Map) state.get("aditionalInfo"); |
||
464 | isAutomatic = state.getBoolean("isAutomatic");
|
||
465 | } |
||
466 | |||
467 | 42561 | jjdelcerro | @Override
|
468 | 40435 | jjdelcerro | public void saveToState(PersistentState state) throws PersistenceException { |
469 | state.set("allowNull", allowNull);
|
||
470 | state.set("dataType", dataType);
|
||
471 | // FIXME how persist dateFormat ???
|
||
472 | // dateFormat;
|
||
473 | |||
474 | defaultValue = state.get("defaultValue");
|
||
475 | |||
476 | index = state.getInt("index");
|
||
477 | maximumOccurrences = state.getInt("maximumOccurrences");
|
||
478 | minimumOccurrences = state.getInt("minimumOccurrences");
|
||
479 | size = state.getInt("size");
|
||
480 | name = state.getString("name");
|
||
481 | try {
|
||
482 | objectClass = Class.forName(state.getString("objectClass")); |
||
483 | } catch (ClassNotFoundException e) { |
||
484 | throw new PersistenceException(e); |
||
485 | } |
||
486 | precision = state.getInt("precision");
|
||
487 | evaluator = (Evaluator) state.get("evaluator");
|
||
488 | primaryKey = state.getBoolean("primaryKey");
|
||
489 | readOnly = state.getBoolean("readOnly");
|
||
490 | String srsId = state.getString("srsId"); |
||
491 | if (srsId != null) { |
||
492 | SRS = CRSFactory.getCRS(srsId); |
||
493 | } |
||
494 | geometryType = state.getInt("geometryType");
|
||
495 | geometrySubType = state.getInt("geometrySubType");
|
||
496 | additionalInfo = (Map) state.get("aditionalInfo"); |
||
497 | isAutomatic = state.getBoolean("isAutomatic");
|
||
498 | } |
||
499 | |||
500 | 42563 | jjdelcerro | /*
|
501 | 40435 | jjdelcerro | * Start of DynField interface Implementation
|
502 | 42561 | jjdelcerro | *
|
503 | 40435 | jjdelcerro | */
|
504 | 42634 | fdiaz | |
505 | 42563 | jjdelcerro | public Tags getTags() {
|
506 | return tags;
|
||
507 | } |
||
508 | 42634 | fdiaz | |
509 | 42561 | jjdelcerro | @Override
|
510 | 40435 | jjdelcerro | public DynObjectValueItem[] getAvailableValues() { |
511 | 42563 | jjdelcerro | return this.availableValues; |
512 | 40435 | jjdelcerro | } |
513 | |||
514 | 42561 | jjdelcerro | @Override
|
515 | 40435 | jjdelcerro | public String getDescription() { |
516 | 42563 | jjdelcerro | if( this.description == null ) { |
517 | return getName();
|
||
518 | } |
||
519 | return this.description; |
||
520 | 40435 | jjdelcerro | } |
521 | |||
522 | 42561 | jjdelcerro | @Override
|
523 | 40435 | jjdelcerro | public Object getMaxValue() { |
524 | 42563 | jjdelcerro | return this.maxValue; |
525 | 40435 | jjdelcerro | } |
526 | |||
527 | 42561 | jjdelcerro | @Override
|
528 | 40435 | jjdelcerro | public Object getMinValue() { |
529 | 42563 | jjdelcerro | return this.minValue; |
530 | 40435 | jjdelcerro | } |
531 | |||
532 | 42561 | jjdelcerro | @Override
|
533 | 40435 | jjdelcerro | public int getTheTypeOfAvailableValues() { |
534 | 42563 | jjdelcerro | return 1; |
535 | 40435 | jjdelcerro | } |
536 | |||
537 | 42561 | jjdelcerro | @Override
|
538 | 40435 | jjdelcerro | public int getType() { |
539 | 42561 | jjdelcerro | if (featureAttributeGetter != null) { |
540 | 40435 | jjdelcerro | return featureAttributeGetter.getDataType().getType();
|
541 | } |
||
542 | return getDataType().getType();
|
||
543 | } |
||
544 | |||
545 | 42561 | jjdelcerro | @Override
|
546 | 40435 | jjdelcerro | public boolean isMandatory() { |
547 | return !allowNull() || isPrimaryKey();
|
||
548 | } |
||
549 | |||
550 | 42561 | jjdelcerro | @Override
|
551 | 40435 | jjdelcerro | public boolean isPersistent() { |
552 | return false; |
||
553 | } |
||
554 | |||
555 | 42561 | jjdelcerro | @Override
|
556 | 40435 | jjdelcerro | public DynField setAvailableValues(DynObjectValueItem[] values) { |
557 | 42563 | jjdelcerro | if ( ArrayUtils.isEmpty(values) ) {
|
558 | this.availableValues = null; |
||
559 | } else {
|
||
560 | this.availableValues = values;
|
||
561 | } |
||
562 | return this; |
||
563 | 40435 | jjdelcerro | } |
564 | |||
565 | 42561 | jjdelcerro | @Override
|
566 | 40435 | jjdelcerro | public DynField setDescription(String description) { |
567 | 42563 | jjdelcerro | this.description = description;
|
568 | return this; |
||
569 | 40435 | jjdelcerro | } |
570 | |||
571 | 42561 | jjdelcerro | @Override
|
572 | 40435 | jjdelcerro | public DynField setMandatory(boolean mandatory) { |
573 | throw new UnsupportedOperationException(); |
||
574 | } |
||
575 | |||
576 | 42561 | jjdelcerro | @Override
|
577 | 40435 | jjdelcerro | public DynField setMaxValue(Object maxValue) { |
578 | 42563 | jjdelcerro | try {
|
579 | this.maxValue = this.coerce(maxValue); |
||
580 | } catch (CoercionException e) {
|
||
581 | throw new IllegalArgumentException(e); |
||
582 | } |
||
583 | return this; |
||
584 | 40435 | jjdelcerro | } |
585 | |||
586 | 42561 | jjdelcerro | @Override
|
587 | 40435 | jjdelcerro | public DynField setMinValue(Object minValue) { |
588 | 42563 | jjdelcerro | try {
|
589 | this.maxValue = this.coerce(minValue); |
||
590 | } catch (CoercionException e) {
|
||
591 | throw new IllegalArgumentException(e); |
||
592 | } |
||
593 | return this; |
||
594 | 40435 | jjdelcerro | } |
595 | |||
596 | 42561 | jjdelcerro | @Override
|
597 | 40435 | jjdelcerro | public DynField setPersistent(boolean persistent) { |
598 | throw new UnsupportedOperationException(); |
||
599 | } |
||
600 | |||
601 | 42561 | jjdelcerro | @Override
|
602 | 40435 | jjdelcerro | public DynField setTheTypeOfAvailableValues(int type) { |
603 | throw new UnsupportedOperationException(); |
||
604 | } |
||
605 | |||
606 | 42561 | jjdelcerro | @Override
|
607 | 40435 | jjdelcerro | public DynField setType(int type) { |
608 | throw new UnsupportedOperationException(); |
||
609 | } |
||
610 | |||
611 | 42561 | jjdelcerro | @Override
|
612 | 40435 | jjdelcerro | public DynField setDefaultDynValue(Object defaultValue) { |
613 | throw new UnsupportedOperationException(); |
||
614 | } |
||
615 | |||
616 | 42561 | jjdelcerro | @Override
|
617 | 40435 | jjdelcerro | public Class getClassOfValue() { |
618 | return null; |
||
619 | } |
||
620 | |||
621 | 42561 | jjdelcerro | @Override
|
622 | 40435 | jjdelcerro | public DynField getElementsType() {
|
623 | return null; |
||
624 | } |
||
625 | |||
626 | 42561 | jjdelcerro | @Override
|
627 | 40435 | jjdelcerro | public DynField setClassOfValue(Class theClass) |
628 | 42561 | jjdelcerro | throws DynFieldIsNotAContainerException {
|
629 | 40435 | jjdelcerro | throw new UnsupportedOperationException(); |
630 | } |
||
631 | |||
632 | 42561 | jjdelcerro | @Override
|
633 | 40435 | jjdelcerro | public DynField setElementsType(DynStruct type)
|
634 | 42561 | jjdelcerro | throws DynFieldIsNotAContainerException {
|
635 | 40435 | jjdelcerro | throw new UnsupportedOperationException(); |
636 | } |
||
637 | |||
638 | 42561 | jjdelcerro | @Override
|
639 | 40435 | jjdelcerro | public DynField setElementsType(int type) |
640 | 42561 | jjdelcerro | throws DynFieldIsNotAContainerException {
|
641 | 40435 | jjdelcerro | throw new UnsupportedOperationException(); |
642 | } |
||
643 | |||
644 | 42561 | jjdelcerro | @Override
|
645 | 40435 | jjdelcerro | public DynField setSubtype(String subtype) { |
646 | throw new UnsupportedOperationException(); |
||
647 | } |
||
648 | |||
649 | 42561 | jjdelcerro | @Override
|
650 | 40435 | jjdelcerro | public void validate(Object value) throws DynFieldValidateException { |
651 | 42561 | jjdelcerro | |
652 | 40435 | jjdelcerro | if (value == null && !this.allowNull()) { |
653 | throw new DynFieldValidateException(value, this, null); |
||
654 | } |
||
655 | 42561 | jjdelcerro | |
656 | 40435 | jjdelcerro | try {
|
657 | this.dataType.coerce(value);
|
||
658 | } catch (CoercionException e) {
|
||
659 | throw new DynFieldValidateException(value, this, e); |
||
660 | } |
||
661 | 42561 | jjdelcerro | |
662 | 40435 | jjdelcerro | /*
|
663 | * Other checks will be needed
|
||
664 | */
|
||
665 | } |
||
666 | |||
667 | 42561 | jjdelcerro | @Override
|
668 | 40435 | jjdelcerro | public String getSubtype() { |
669 | 42561 | jjdelcerro | if (featureAttributeGetter != null) { |
670 | 40435 | jjdelcerro | return featureAttributeGetter.getDataType().getSubtype();
|
671 | 42561 | jjdelcerro | } |
672 | 40435 | jjdelcerro | return this.dataType.getSubtype(); |
673 | } |
||
674 | |||
675 | 42561 | jjdelcerro | @Override
|
676 | 42563 | jjdelcerro | public Object coerce(Object value) throws CoercionException { |
677 | if ( value == null ) { |
||
678 | return value; // O debe devolver this.defaultValue |
||
679 | } |
||
680 | try {
|
||
681 | return this.getDataType().coerce(value); |
||
682 | } catch(Exception ex){ |
||
683 | throw new RuntimeException(ex); |
||
684 | } |
||
685 | 40435 | jjdelcerro | } |
686 | |||
687 | 42561 | jjdelcerro | @Override
|
688 | 40435 | jjdelcerro | public DynField setAvailableValues(List values) { |
689 | 42563 | jjdelcerro | if ( values == null || values.isEmpty() ) { |
690 | this.availableValues = null; |
||
691 | } else {
|
||
692 | this.availableValues = (DynObjectValueItem[]) values.toArray( |
||
693 | new DynObjectValueItem[values.size()]
|
||
694 | ); |
||
695 | } |
||
696 | return this; |
||
697 | 40435 | jjdelcerro | } |
698 | |||
699 | 42561 | jjdelcerro | @Override
|
700 | 40435 | jjdelcerro | public String getGroup() { |
701 | 42563 | jjdelcerro | return this.groupName; |
702 | 40435 | jjdelcerro | } |
703 | |||
704 | 42561 | jjdelcerro | @Override
|
705 | 40435 | jjdelcerro | public int getOder() { |
706 | 42563 | jjdelcerro | return this.order; |
707 | 40435 | jjdelcerro | } |
708 | |||
709 | 42561 | jjdelcerro | @Override
|
710 | 41323 | jjdelcerro | public String getLabel() { |
711 | 42563 | jjdelcerro | if( this.label == null ) { |
712 | return this.getName(); |
||
713 | } |
||
714 | return this.label; |
||
715 | 41323 | jjdelcerro | } |
716 | |||
717 | 42561 | jjdelcerro | @Override
|
718 | 41323 | jjdelcerro | public DynField setLabel(String label) { |
719 | 42563 | jjdelcerro | this.label = label;
|
720 | return this; |
||
721 | 41323 | jjdelcerro | } |
722 | |||
723 | 42561 | jjdelcerro | @Override
|
724 | 40435 | jjdelcerro | public DynField setGroup(String groupName) { |
725 | 42563 | jjdelcerro | this.groupName = groupName;
|
726 | return this; |
||
727 | 40435 | jjdelcerro | } |
728 | |||
729 | 42561 | jjdelcerro | @Override
|
730 | 40435 | jjdelcerro | public DynField setOrder(int order) { |
731 | 42563 | jjdelcerro | this.order = order;
|
732 | return this; |
||
733 | 40435 | jjdelcerro | } |
734 | |||
735 | 42561 | jjdelcerro | @Override
|
736 | 40435 | jjdelcerro | public DynField setHidden(boolean hidden) { |
737 | 42563 | jjdelcerro | this.hidden = hidden;
|
738 | return this; |
||
739 | 40435 | jjdelcerro | } |
740 | |||
741 | 42561 | jjdelcerro | @Override
|
742 | 40435 | jjdelcerro | public boolean isHidden() { |
743 | 42563 | jjdelcerro | return this.hidden; |
744 | 40435 | jjdelcerro | } |
745 | |||
746 | 42561 | jjdelcerro | @Override
|
747 | 40435 | jjdelcerro | public DynField setReadOnly(boolean arg0) { |
748 | throw new UnsupportedOperationException(); |
||
749 | } |
||
750 | |||
751 | 42561 | jjdelcerro | @Override
|
752 | 40435 | jjdelcerro | public boolean isContainer() { |
753 | return false; |
||
754 | } |
||
755 | |||
756 | 42561 | jjdelcerro | @Override
|
757 | 40435 | jjdelcerro | public Class getClassOfItems() { |
758 | return null; |
||
759 | } |
||
760 | |||
761 | 42561 | jjdelcerro | @Override
|
762 | 40435 | jjdelcerro | public DynField setDefaultFieldValue(Object defaultValue) { |
763 | throw new UnsupportedOperationException(); |
||
764 | } |
||
765 | |||
766 | 42561 | jjdelcerro | @Override
|
767 | 40435 | jjdelcerro | public DynField setClassOfItems(Class theClass) { |
768 | throw new UnsupportedOperationException(); |
||
769 | } |
||
770 | |||
771 | 42561 | jjdelcerro | @Override
|
772 | 40435 | jjdelcerro | public DynField setType(DataType type) {
|
773 | throw new UnsupportedOperationException(); |
||
774 | } |
||
775 | |||
776 | 42561 | jjdelcerro | @Override
|
777 | public boolean isTime() { |
||
778 | return isTime;
|
||
779 | } |
||
780 | 40435 | jjdelcerro | |
781 | 42561 | jjdelcerro | @Override
|
782 | 40435 | jjdelcerro | public FeatureAttributeGetter getFeatureAttributeGetter() {
|
783 | 42561 | jjdelcerro | return featureAttributeGetter;
|
784 | 40435 | jjdelcerro | } |
785 | |||
786 | 42561 | jjdelcerro | @Override
|
787 | 40435 | jjdelcerro | public void setFeatureAttributeGetter( |
788 | 42561 | jjdelcerro | FeatureAttributeGetter featureAttributeTransform) { |
789 | this.featureAttributeGetter = featureAttributeTransform;
|
||
790 | } |
||
791 | 41335 | jjdelcerro | |
792 | 42561 | jjdelcerro | @Override
|
793 | 41335 | jjdelcerro | public FeatureAttributeEmulator getFeatureAttributeEmulator() {
|
794 | return this.featureAttributeEmulator; |
||
795 | } |
||
796 | |||
797 | 42561 | jjdelcerro | @Override
|
798 | 41638 | jjdelcerro | public boolean isIndexed() { |
799 | return this.indexed; |
||
800 | } |
||
801 | |||
802 | 42561 | jjdelcerro | @Override
|
803 | 41638 | jjdelcerro | public boolean allowIndexDuplicateds() { |
804 | return this.allowIndexDuplicateds; |
||
805 | } |
||
806 | |||
807 | 42561 | jjdelcerro | @Override
|
808 | 41638 | jjdelcerro | public boolean isIndexAscending() { |
809 | return this.isIndexAscending; |
||
810 | } |
||
811 | |||
812 | 42563 | jjdelcerro | @Override
|
813 | public DynField setClassOfValue(DynStruct dynStrct) {
|
||
814 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
815 | } |
||
816 | |||
817 | @Override
|
||
818 | public DynField setClassOfValue(String theClassNameOfValue) { |
||
819 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
820 | } |
||
821 | |||
822 | @Override
|
||
823 | public String getClassNameOfValue() { |
||
824 | 42634 | fdiaz | return null; |
825 | 42563 | jjdelcerro | } |
826 | |||
827 | @Override
|
||
828 | public DynStruct getDynClassOfValue() {
|
||
829 | 42634 | fdiaz | return null; |
830 | 42563 | jjdelcerro | } |
831 | |||
832 | @Override
|
||
833 | public DynField setTypeOfItems(int type) { |
||
834 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
835 | } |
||
836 | |||
837 | @Override
|
||
838 | public int getTypeOfItems() { |
||
839 | 42634 | fdiaz | return DataTypes.INVALID;
|
840 | 42563 | jjdelcerro | } |
841 | |||
842 | @Override
|
||
843 | public DynField setClassOfItems(DynStruct dynStrct) {
|
||
844 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
845 | } |
||
846 | |||
847 | @Override
|
||
848 | public DynField setClassOfItems(String theClassNameOfValue) { |
||
849 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
850 | } |
||
851 | |||
852 | @Override
|
||
853 | public String getClassNameOfItems() { |
||
854 | 42634 | fdiaz | return null; |
855 | 42563 | jjdelcerro | } |
856 | |||
857 | @Override
|
||
858 | public DynStruct getDynClassOfItems() {
|
||
859 | 42634 | fdiaz | return null; |
860 | 42563 | jjdelcerro | } |
861 | |||
862 | @Override
|
||
863 | public DynField setRelationType(int relationType) { |
||
864 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
865 | } |
||
866 | |||
867 | @Override
|
||
868 | public int getRelationType() { |
||
869 | return RELATION_TYPE_NONE;
|
||
870 | } |
||
871 | |||
872 | 42606 | jjdelcerro | @Override
|
873 | 42775 | jjdelcerro | public DynField setAvailableValues(DynMethod availableValuesMethod) {
|
874 | this.availableValuesMethod = availableValuesMethod;
|
||
875 | return this; |
||
876 | 42606 | jjdelcerro | } |
877 | |||
878 | @Override
|
||
879 | 42775 | jjdelcerro | public DynObjectValueItem[] getAvailableValues(DynObject self) { |
880 | if( this.availableValuesMethod != null ) { |
||
881 | DynObjectValueItem[] values;
|
||
882 | try {
|
||
883 | values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this}); |
||
884 | } catch (DynMethodException ex) {
|
||
885 | return this.availableValues; |
||
886 | } |
||
887 | 42606 | jjdelcerro | if( values != null ) { |
888 | return values;
|
||
889 | } |
||
890 | } |
||
891 | return this.availableValues; |
||
892 | } |
||
893 | |||
894 | 42775 | jjdelcerro | @Override
|
895 | public DynMethod getAvailableValuesMethod() {
|
||
896 | return this.availableValuesMethod; |
||
897 | } |
||
898 | |||
899 | @Override
|
||
900 | public boolean isAvailableValuesCalculated() { |
||
901 | return this.availableValuesMethod!=null; |
||
902 | } |
||
903 | |||
904 | @Override
|
||
905 | public DynMethod getCalculateMethod() {
|
||
906 | return this.calculateMethod; |
||
907 | } |
||
908 | |||
909 | @Override
|
||
910 | public DynField setCalculateMethod(DynMethod method) {
|
||
911 | this.calculateMethod = method;
|
||
912 | return this; |
||
913 | } |
||
914 | |||
915 | @Override
|
||
916 | public boolean isCalculated() { |
||
917 | return this.calculateMethod != null; |
||
918 | } |
||
919 | |||
920 | @Override
|
||
921 | public Object getCalculatedValue(DynObject self) { |
||
922 | try {
|
||
923 | return this.calculateMethod.invoke(self, new Object[] { this }); |
||
924 | } catch (DynMethodException ex) {
|
||
925 | throw new RuntimeException(ex); |
||
926 | } |
||
927 | } |
||
928 | |||
929 | @Override
|
||
930 | public DynField setValidateElements(boolean validate) { |
||
931 | return this; |
||
932 | } |
||
933 | |||
934 | @Override
|
||
935 | public boolean getValidateElements() { |
||
936 | return false; |
||
937 | } |
||
938 | |||
939 | 41212 | jjdelcerro | private class ConstantValueEvaluator extends AbstractEvaluator { |
940 | 42561 | jjdelcerro | |
941 | @Override
|
||
942 | 41212 | jjdelcerro | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
943 | return defaultValue;
|
||
944 | } |
||
945 | 42561 | jjdelcerro | |
946 | @Override
|
||
947 | 41212 | jjdelcerro | public String getName() { |
948 | 42561 | jjdelcerro | return "Constant attribute " + name; |
949 | 41212 | jjdelcerro | } |
950 | } |
||
951 | 41335 | jjdelcerro | |
952 | 41212 | jjdelcerro | public void setConstantValue(boolean isConstantValue) { |
953 | 42561 | jjdelcerro | if (isConstantValue) {
|
954 | 41212 | jjdelcerro | /* Cuando un attributo tiene asociado un evaluador, este se interpreta
|
955 | 42634 | fdiaz | * como que no debe cargarse de la fuente de datos subyacente, siendo
|
956 | 41212 | jjdelcerro | * el evaluador el que se encarga de proporcionar su valor.
|
957 | * Nos limitamos a asignar un evaluador que retorna simpre el valor
|
||
958 | * por defecto para ese attributo.
|
||
959 | */
|
||
960 | this.evaluator = new ConstantValueEvaluator(); |
||
961 | } else {
|
||
962 | this.evaluator = null; |
||
963 | } |
||
964 | } |
||
965 | 42561 | jjdelcerro | |
966 | 43135 | jjdelcerro | public boolean isComputed() { |
967 | return featureAttributeEmulator!=null || evaluator!=null; |
||
968 | } |
||
969 | 40435 | jjdelcerro | } |