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 @ 44259
History | View | Annotate | Download (41.2 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 | 43739 | jjdelcerro | import java.lang.ref.WeakReference; |
26 | 40435 | jjdelcerro | import java.text.DateFormat; |
27 | import java.util.HashMap; |
||
28 | import java.util.Iterator; |
||
29 | import java.util.List; |
||
30 | import java.util.Map; |
||
31 | import java.util.Map.Entry; |
||
32 | 44128 | jjdelcerro | import java.util.Objects; |
33 | 42563 | jjdelcerro | import org.apache.commons.lang3.ArrayUtils; |
34 | 44190 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
35 | 40435 | jjdelcerro | import org.cresques.cts.IProjection; |
36 | 44259 | jjdelcerro | import org.gvsig.expressionevaluator.Expression; |
37 | import org.gvsig.expressionevaluator.ExpressionUtils; |
||
38 | import org.gvsig.expressionevaluator.SymbolTable; |
||
39 | import org.gvsig.fmap.dal.DALLocator; |
||
40 | import org.gvsig.fmap.dal.DataManager; |
||
41 | import static org.gvsig.fmap.dal.DataManager.DAL_FOREING_CODE; |
||
42 | import static org.gvsig.fmap.dal.DataManager.DAL_FOREING_LABEL; |
||
43 | import static org.gvsig.fmap.dal.DataManager.DAL_FOREING_TABLE; |
||
44 | 44022 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
45 | 44083 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
46 | 44259 | jjdelcerro | import org.gvsig.fmap.dal.StoresRepository; |
47 | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
||
48 | import org.gvsig.fmap.dal.feature.Feature; |
||
49 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
50 | 42563 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
51 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
52 | 43739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
53 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
54 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
55 | import org.gvsig.fmap.geom.GeometryException; |
||
56 | import org.gvsig.fmap.geom.GeometryLocator; |
||
57 | 44190 | jjdelcerro | import org.gvsig.fmap.geom.GeometryUtils; |
58 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.type.GeometryType; |
59 | 44077 | jjdelcerro | import org.gvsig.timesupport.Interval; |
60 | 44190 | jjdelcerro | import org.gvsig.timesupport.RelativeInterval; |
61 | 44077 | jjdelcerro | import org.gvsig.timesupport.TimeSupportLocator; |
62 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
63 | import org.gvsig.tools.dataTypes.CoercionException; |
||
64 | import org.gvsig.tools.dataTypes.DataType; |
||
65 | import org.gvsig.tools.dynobject.DynField; |
||
66 | 41323 | jjdelcerro | import org.gvsig.tools.dynobject.DynField_LabelAttribute; |
67 | 42563 | jjdelcerro | import org.gvsig.tools.dynobject.DynField_v2; |
68 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.DynMethod; |
69 | 42606 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
70 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.DynObjectValueItem; |
71 | import org.gvsig.tools.dynobject.DynStruct; |
||
72 | 42563 | jjdelcerro | import org.gvsig.tools.dynobject.Tags; |
73 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException; |
74 | import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
||
75 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.exception.DynMethodException; |
76 | 42563 | jjdelcerro | import org.gvsig.tools.dynobject.impl.DefaultTags; |
77 | 41212 | jjdelcerro | import org.gvsig.tools.evaluator.AbstractEvaluator; |
78 | 40435 | jjdelcerro | import org.gvsig.tools.evaluator.Evaluator; |
79 | 41212 | jjdelcerro | import org.gvsig.tools.evaluator.EvaluatorData; |
80 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
81 | 44190 | jjdelcerro | import org.gvsig.tools.persistence.PersistenceManager; |
82 | 40435 | jjdelcerro | import org.gvsig.tools.persistence.Persistent; |
83 | import org.gvsig.tools.persistence.PersistentState; |
||
84 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
85 | 44190 | jjdelcerro | import org.slf4j.Logger; |
86 | import org.slf4j.LoggerFactory; |
||
87 | 40435 | jjdelcerro | |
88 | 44259 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
89 | 40435 | jjdelcerro | public class DefaultFeatureAttributeDescriptor implements |
90 | 42563 | jjdelcerro | FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute { |
91 | 40435 | jjdelcerro | |
92 | 44190 | jjdelcerro | protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureAttributeDescriptor.class); |
93 | |||
94 | 40435 | jjdelcerro | protected boolean allowNull; |
95 | protected DataType dataType;
|
||
96 | 44128 | jjdelcerro | protected String dataProfile; |
97 | 40435 | jjdelcerro | protected DateFormat dateFormat; |
98 | protected Object defaultValue; |
||
99 | protected int index; |
||
100 | protected int maximumOccurrences; |
||
101 | protected int minimumOccurrences; |
||
102 | protected int size; |
||
103 | protected String name; |
||
104 | protected Class objectClass; |
||
105 | protected int precision; |
||
106 | protected Evaluator evaluator;
|
||
107 | protected boolean primaryKey; |
||
108 | protected boolean readOnly; |
||
109 | protected IProjection SRS;
|
||
110 | protected GeometryType geomType;
|
||
111 | protected int geometryType; |
||
112 | protected int geometrySubType; |
||
113 | protected Map additionalInfo; |
||
114 | protected boolean isAutomatic; |
||
115 | 41335 | jjdelcerro | protected boolean isTime = false; |
116 | 44077 | jjdelcerro | protected Interval interval;
|
117 | 41335 | jjdelcerro | protected FeatureAttributeGetter featureAttributeGetter = null; |
118 | protected FeatureAttributeEmulator featureAttributeEmulator = null; |
||
119 | 41638 | jjdelcerro | protected boolean indexed = false; |
120 | protected boolean isIndexAscending = true; |
||
121 | protected boolean allowIndexDuplicateds = true; |
||
122 | 40435 | jjdelcerro | |
123 | 42563 | jjdelcerro | protected DynObjectValueItem[] availableValues; |
124 | protected String description; |
||
125 | protected Object minValue; |
||
126 | protected Object maxValue; |
||
127 | protected String label; |
||
128 | protected int order; |
||
129 | protected boolean hidden; |
||
130 | protected String groupName; |
||
131 | protected Tags tags = new DefaultTags(); |
||
132 | 42775 | jjdelcerro | private DynMethod availableValuesMethod;
|
133 | private DynMethod calculateMethod;
|
||
134 | 43739 | jjdelcerro | private WeakReference typeRef; |
135 | 44253 | jjdelcerro | |
136 | private int relationType = RELATION_TYPE_NONE; |
||
137 | 42563 | jjdelcerro | |
138 | 44190 | jjdelcerro | public DefaultFeatureAttributeDescriptor() {
|
139 | // Usada en la persistencia
|
||
140 | } |
||
141 | |||
142 | 43739 | jjdelcerro | protected DefaultFeatureAttributeDescriptor(FeatureType type) {
|
143 | 44259 | jjdelcerro | this();
|
144 | // LOGGER.info(String.format("Created FeatureAttributeDescriptor [%08x].", this.hashCode()));
|
||
145 | 44190 | jjdelcerro | setFeatureType(type); |
146 | 40435 | jjdelcerro | this.allowNull = true; |
147 | this.dataType = null; |
||
148 | this.dateFormat = null; |
||
149 | this.defaultValue = null; |
||
150 | this.index = -1; |
||
151 | this.maximumOccurrences = 0; |
||
152 | this.minimumOccurrences = 0; |
||
153 | this.size = 0; |
||
154 | this.name = null; |
||
155 | this.objectClass = null; |
||
156 | this.precision = 0; |
||
157 | this.evaluator = null; |
||
158 | this.primaryKey = false; |
||
159 | this.readOnly = false; |
||
160 | this.SRS = null; |
||
161 | this.geometryType = Geometry.TYPES.NULL;
|
||
162 | this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
|
||
163 | this.additionalInfo = null; |
||
164 | this.isAutomatic = false; |
||
165 | 43362 | jjdelcerro | this.hidden = false; |
166 | 44253 | jjdelcerro | this.relationType = RELATION_TYPE_NONE;
|
167 | 40435 | jjdelcerro | } |
168 | |||
169 | protected DefaultFeatureAttributeDescriptor(
|
||
170 | 43739 | jjdelcerro | DefaultFeatureAttributeDescriptor other |
171 | ) { |
||
172 | 44259 | jjdelcerro | this();
|
173 | 42775 | jjdelcerro | copyFrom(other); |
174 | 44259 | jjdelcerro | // LOGGER.info(String.format("Created FeatureAttributeDescriptor [%08x] [%s] (copy).", this.hashCode(), this.name));
|
175 | 42775 | jjdelcerro | } |
176 | |||
177 | @Override
|
||
178 | public void copyFrom(DynField other1) { |
||
179 | if( !(other1 instanceof DefaultFeatureAttributeDescriptor) ) { |
||
180 | throw new IllegalArgumentException("Can't copy from a non DefaultFeatureAttributeDescriptor"); |
||
181 | } |
||
182 | DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) other1; |
||
183 | 43739 | jjdelcerro | this.typeRef = other.typeRef;
|
184 | 40435 | jjdelcerro | this.allowNull = other.allowNull;
|
185 | this.dataType = other.dataType;
|
||
186 | this.dateFormat = other.dateFormat;
|
||
187 | this.defaultValue = other.defaultValue;
|
||
188 | this.index = other.index;
|
||
189 | this.maximumOccurrences = other.maximumOccurrences;
|
||
190 | this.minimumOccurrences = other.minimumOccurrences;
|
||
191 | this.size = other.size;
|
||
192 | this.name = other.name;
|
||
193 | this.objectClass = other.objectClass;
|
||
194 | this.precision = other.precision;
|
||
195 | this.evaluator = other.evaluator;
|
||
196 | this.primaryKey = other.primaryKey;
|
||
197 | this.readOnly = other.readOnly;
|
||
198 | this.SRS = other.SRS;
|
||
199 | this.geometryType = other.geometryType;
|
||
200 | this.geometrySubType = other.geometrySubType;
|
||
201 | this.geomType = other.geomType;
|
||
202 | if (other.additionalInfo != null) { |
||
203 | Iterator iter = other.additionalInfo.entrySet().iterator();
|
||
204 | Map.Entry entry;
|
||
205 | this.additionalInfo = new HashMap(); |
||
206 | while (iter.hasNext()) {
|
||
207 | entry = (Entry) iter.next(); |
||
208 | this.additionalInfo.put(entry.getKey(), entry.getValue());
|
||
209 | } |
||
210 | } else {
|
||
211 | this.additionalInfo = null; |
||
212 | } |
||
213 | this.isAutomatic = other.isAutomatic;
|
||
214 | 41335 | jjdelcerro | this.isTime = other.isTime;
|
215 | this.featureAttributeEmulator = other.featureAttributeEmulator;
|
||
216 | 41638 | jjdelcerro | this.indexed = other.indexed;
|
217 | this.isIndexAscending = other.isIndexAscending;
|
||
218 | this.allowIndexDuplicateds = other.allowIndexDuplicateds;
|
||
219 | 43362 | jjdelcerro | this.hidden = other.hidden;
|
220 | 44188 | jjdelcerro | this.dataProfile = other.dataProfile;
|
221 | 44202 | jjdelcerro | |
222 | this.availableValues = other.availableValues;
|
||
223 | this.description = other.description;
|
||
224 | this.minValue = other.minValue;
|
||
225 | this.maxValue = other.maxValue;
|
||
226 | this.label = other.label;
|
||
227 | this.order = other.order;
|
||
228 | this.groupName = other.groupName;
|
||
229 | if( other.tags==null ) { |
||
230 | this.tags = null; |
||
231 | } else {
|
||
232 | try {
|
||
233 | this.tags = (Tags) other.tags.clone();
|
||
234 | } catch (Exception ex) { |
||
235 | } |
||
236 | } |
||
237 | // TODO: ? Habria que clonarlos ?
|
||
238 | this.availableValuesMethod = other.availableValuesMethod;
|
||
239 | this.calculateMethod = other.calculateMethod;
|
||
240 | 44253 | jjdelcerro | this.relationType = other.relationType;
|
241 | 40435 | jjdelcerro | } |
242 | 42775 | jjdelcerro | |
243 | 44190 | jjdelcerro | public void setFeatureType(FeatureType type) { |
244 | // Usada en la persistencia
|
||
245 | if( type == null ) { |
||
246 | this.typeRef = null; |
||
247 | } else {
|
||
248 | this.typeRef = new WeakReference(type); |
||
249 | 44259 | jjdelcerro | // LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] set FeatureType [%08x], ref [%08x].", this.hashCode(), type.hashCode(), typeRef.hashCode()));
|
250 | 44190 | jjdelcerro | } |
251 | } |
||
252 | |||
253 | 42561 | jjdelcerro | @Override
|
254 | 40435 | jjdelcerro | public String getDataTypeName() { |
255 | 42561 | jjdelcerro | if (this.getDataType() == null) { |
256 | 40435 | jjdelcerro | return "(unknow)"; |
257 | } |
||
258 | 42561 | jjdelcerro | return this.getDataType().getName(); |
259 | 40435 | jjdelcerro | } |
260 | |||
261 | 42561 | jjdelcerro | @Override
|
262 | 40435 | jjdelcerro | public FeatureAttributeDescriptor getCopy() {
|
263 | return new DefaultFeatureAttributeDescriptor(this); |
||
264 | } |
||
265 | |||
266 | 42561 | jjdelcerro | @Override
|
267 | 42775 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
268 | return new DefaultFeatureAttributeDescriptor(this); |
||
269 | } |
||
270 | |||
271 | @Override
|
||
272 | 40435 | jjdelcerro | public boolean allowNull() { |
273 | return allowNull;
|
||
274 | } |
||
275 | |||
276 | 42561 | jjdelcerro | @Override
|
277 | 40435 | jjdelcerro | public DataType getDataType() {
|
278 | 42561 | jjdelcerro | if (featureAttributeGetter != null) { |
279 | return featureAttributeGetter.getDataType();
|
||
280 | } |
||
281 | 40435 | jjdelcerro | return this.dataType; |
282 | } |
||
283 | |||
284 | 43954 | jjdelcerro | public FeatureAttributeDescriptor setDataType(int type) { |
285 | this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
||
286 | return this; |
||
287 | } |
||
288 | |||
289 | 42561 | jjdelcerro | @Override
|
290 | 40435 | jjdelcerro | public DateFormat getDateFormat() { |
291 | return this.dateFormat; |
||
292 | } |
||
293 | |||
294 | 42561 | jjdelcerro | @Override
|
295 | 40435 | jjdelcerro | public Object getDefaultValue() { |
296 | return this.defaultValue; |
||
297 | } |
||
298 | |||
299 | 42561 | jjdelcerro | @Override
|
300 | 40435 | jjdelcerro | public Evaluator getEvaluator() {
|
301 | return this.evaluator; |
||
302 | } |
||
303 | |||
304 | 42561 | jjdelcerro | @Override
|
305 | 40435 | jjdelcerro | public int getGeometryType() { |
306 | 44083 | jjdelcerro | if( this.dataType.getType()!=DataTypes.GEOMETRY ) { |
307 | return Geometry.TYPES.UNKNOWN;
|
||
308 | } |
||
309 | 40435 | jjdelcerro | return this.geometryType; |
310 | } |
||
311 | |||
312 | 42561 | jjdelcerro | @Override
|
313 | 40435 | jjdelcerro | public int getGeometrySubType() { |
314 | 44083 | jjdelcerro | if( this.dataType.getType()!=DataTypes.GEOMETRY ) { |
315 | return Geometry.SUBTYPES.UNKNOWN;
|
||
316 | } |
||
317 | 40435 | jjdelcerro | return this.geometrySubType; |
318 | } |
||
319 | |||
320 | 42561 | jjdelcerro | @Override
|
321 | 40435 | jjdelcerro | public GeometryType getGeomType() {
|
322 | 44083 | jjdelcerro | if( this.dataType.getType()!=DataTypes.GEOMETRY ) { |
323 | return null; |
||
324 | } |
||
325 | 40435 | jjdelcerro | if (this.geomType == null) { |
326 | try {
|
||
327 | 42561 | jjdelcerro | this.geomType
|
328 | = GeometryLocator.getGeometryManager().getGeometryType( |
||
329 | this.geometryType, this.geometrySubType); |
||
330 | 40435 | jjdelcerro | } catch (GeometryException e) {
|
331 | throw new RuntimeException( |
||
332 | 42561 | jjdelcerro | "Error getting geometry type with type = "
|
333 | 40435 | jjdelcerro | + this.geometryType + ", subtype = " |
334 | + this.geometrySubType, e);
|
||
335 | } |
||
336 | } |
||
337 | return this.geomType; |
||
338 | } |
||
339 | |||
340 | 42561 | jjdelcerro | @Override
|
341 | 40435 | jjdelcerro | public int getIndex() { |
342 | return this.index; |
||
343 | } |
||
344 | |||
345 | protected FeatureAttributeDescriptor setIndex(int index) { |
||
346 | this.index = index;
|
||
347 | return this; |
||
348 | } |
||
349 | |||
350 | 42561 | jjdelcerro | @Override
|
351 | 40435 | jjdelcerro | public int getMaximumOccurrences() { |
352 | return this.maximumOccurrences; |
||
353 | } |
||
354 | |||
355 | 42561 | jjdelcerro | @Override
|
356 | 40435 | jjdelcerro | public int getMinimumOccurrences() { |
357 | return this.minimumOccurrences; |
||
358 | } |
||
359 | |||
360 | 42561 | jjdelcerro | @Override
|
361 | 40435 | jjdelcerro | public String getName() { |
362 | return this.name; |
||
363 | } |
||
364 | 43954 | jjdelcerro | |
365 | public FeatureAttributeDescriptor setName(String name) { |
||
366 | 44259 | jjdelcerro | // LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] set name [%s].", this.hashCode(), name));
|
367 | 43954 | jjdelcerro | this.name = name;
|
368 | return this; |
||
369 | } |
||
370 | |||
371 | 42561 | jjdelcerro | @Override
|
372 | 40435 | jjdelcerro | public Class getObjectClass() { |
373 | 42561 | jjdelcerro | if (getDataType().getType() == DataTypes.OBJECT) {
|
374 | 40435 | jjdelcerro | return objectClass;
|
375 | } |
||
376 | 42561 | jjdelcerro | return getDataType().getDefaultClass();
|
377 | 40435 | jjdelcerro | } |
378 | |||
379 | 42561 | jjdelcerro | @Override
|
380 | 40435 | jjdelcerro | public int getPrecision() { |
381 | return this.precision; |
||
382 | } |
||
383 | |||
384 | 42561 | jjdelcerro | @Override
|
385 | 40435 | jjdelcerro | public IProjection getSRS() {
|
386 | return this.SRS; |
||
387 | } |
||
388 | |||
389 | 44077 | jjdelcerro | @Override
|
390 | public Interval getInterval() {
|
||
391 | return this.interval; |
||
392 | } |
||
393 | |||
394 | 44022 | jjdelcerro | public IProjection getSRS(WeakReference storeRef) { |
395 | if( this.SRS==null ) { |
||
396 | FeatureStore store = (FeatureStore) storeRef.get(); |
||
397 | this.SRS = (IProjection) store.getDynValue(DataStore.METADATA_CRS);
|
||
398 | } |
||
399 | return this.SRS; |
||
400 | } |
||
401 | |||
402 | |||
403 | 42561 | jjdelcerro | @Override
|
404 | 40435 | jjdelcerro | public int getSize() { |
405 | return this.size; |
||
406 | } |
||
407 | |||
408 | 42561 | jjdelcerro | @Override
|
409 | 40435 | jjdelcerro | public boolean isPrimaryKey() { |
410 | return this.primaryKey; |
||
411 | } |
||
412 | |||
413 | 42561 | jjdelcerro | @Override
|
414 | 40435 | jjdelcerro | public boolean isReadOnly() { |
415 | 42561 | jjdelcerro | if (this.readOnly) { |
416 | 41335 | jjdelcerro | return true; |
417 | } |
||
418 | 42561 | jjdelcerro | if (this.getEvaluator() != null) { |
419 | 41335 | jjdelcerro | return true; |
420 | } |
||
421 | 42561 | jjdelcerro | if (this.featureAttributeEmulator != null) { |
422 | 41335 | jjdelcerro | return !this.featureAttributeEmulator.allowSetting(); |
423 | } |
||
424 | return false; |
||
425 | 40435 | jjdelcerro | } |
426 | |||
427 | 42561 | jjdelcerro | @Override
|
428 | 40435 | jjdelcerro | public Object getAdditionalInfo(String infoName) { |
429 | if (this.additionalInfo == null) { |
||
430 | return null; |
||
431 | } |
||
432 | return this.additionalInfo.get(infoName); |
||
433 | } |
||
434 | |||
435 | 42561 | jjdelcerro | @Override
|
436 | 40435 | jjdelcerro | public boolean isAutomatic() { |
437 | return this.isAutomatic; |
||
438 | } |
||
439 | |||
440 | 42561 | jjdelcerro | @Override
|
441 | 40435 | jjdelcerro | public boolean equals(Object obj) { |
442 | if (this == obj) { |
||
443 | return true; |
||
444 | } |
||
445 | if (!(obj instanceof DefaultFeatureAttributeDescriptor)) { |
||
446 | return false; |
||
447 | } |
||
448 | 42561 | jjdelcerro | DefaultFeatureAttributeDescriptor other |
449 | = (DefaultFeatureAttributeDescriptor) obj; |
||
450 | 40435 | jjdelcerro | |
451 | if (this.allowNull != other.allowNull) { |
||
452 | return false; |
||
453 | } |
||
454 | |||
455 | if (this.index != other.index) { |
||
456 | return false; |
||
457 | } |
||
458 | |||
459 | 44128 | jjdelcerro | if (!Objects.equals(this.name, other.name)) { |
460 | 40435 | jjdelcerro | return false; |
461 | } |
||
462 | |||
463 | 42561 | jjdelcerro | if (this.getDataType() != other.getDataType()) { |
464 | 40435 | jjdelcerro | return false; |
465 | } |
||
466 | |||
467 | if (this.size != other.size) { |
||
468 | return false; |
||
469 | } |
||
470 | |||
471 | 44128 | jjdelcerro | if (!Objects.equals(this.defaultValue, other.defaultValue)) { |
472 | 40435 | jjdelcerro | return false; |
473 | } |
||
474 | |||
475 | if (this.primaryKey != other.primaryKey) { |
||
476 | return false; |
||
477 | } |
||
478 | |||
479 | if (this.isAutomatic != other.isAutomatic) { |
||
480 | return false; |
||
481 | } |
||
482 | |||
483 | if (this.readOnly != other.readOnly) { |
||
484 | return false; |
||
485 | } |
||
486 | |||
487 | if (this.precision != other.precision) { |
||
488 | return false; |
||
489 | } |
||
490 | |||
491 | if (this.maximumOccurrences != other.maximumOccurrences) { |
||
492 | return false; |
||
493 | } |
||
494 | |||
495 | if (this.minimumOccurrences != other.minimumOccurrences) { |
||
496 | return false; |
||
497 | } |
||
498 | |||
499 | if (this.geometryType != other.geometryType) { |
||
500 | return false; |
||
501 | } |
||
502 | |||
503 | if (this.geometrySubType != other.geometrySubType) { |
||
504 | return false; |
||
505 | } |
||
506 | |||
507 | 44128 | jjdelcerro | if (!Objects.equals(this.evaluator, other.evaluator)) { |
508 | 40435 | jjdelcerro | return false; |
509 | } |
||
510 | |||
511 | 44128 | jjdelcerro | if (!Objects.equals(this.featureAttributeEmulator, other.featureAttributeEmulator)) { |
512 | 40435 | jjdelcerro | return false; |
513 | } |
||
514 | |||
515 | 44128 | jjdelcerro | if (!Objects.equals(this.SRS, other.SRS)) { |
516 | 40435 | jjdelcerro | return false; |
517 | } |
||
518 | |||
519 | 44128 | jjdelcerro | if (!Objects.equals(this.dateFormat, other.dateFormat)) { |
520 | 40435 | jjdelcerro | return false; |
521 | } |
||
522 | |||
523 | 44128 | jjdelcerro | if (!Objects.equals(this.objectClass, other.objectClass)) { |
524 | return false; |
||
525 | } |
||
526 | |||
527 | if (!Objects.equals(this.dataProfile, other.dataProfile)) { |
||
528 | return false; |
||
529 | } |
||
530 | |||
531 | 40435 | jjdelcerro | return true; |
532 | } |
||
533 | |||
534 | 42561 | jjdelcerro | @Override
|
535 | 40435 | jjdelcerro | public void loadFromState(PersistentState state) |
536 | 42561 | jjdelcerro | throws PersistenceException {
|
537 | 40435 | jjdelcerro | allowNull = state.getBoolean("allowNull");
|
538 | 44077 | jjdelcerro | dataType = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
|
539 | 44190 | jjdelcerro | dataProfile = state.getString("dataProfile");
|
540 | |||
541 | // FIXME: dateFormat;
|
||
542 | try {
|
||
543 | defaultValue = dataType.coerce(state.get("defaultValue"));
|
||
544 | } catch (CoercionException ex) {
|
||
545 | } |
||
546 | 40435 | jjdelcerro | |
547 | index = state.getInt("index");
|
||
548 | maximumOccurrences = state.getInt("maximumOccurrences");
|
||
549 | minimumOccurrences = state.getInt("minimumOccurrences");
|
||
550 | size = state.getInt("size");
|
||
551 | name = state.getString("name");
|
||
552 | try {
|
||
553 | 44190 | jjdelcerro | String objectClassName = state.getString("objectClass"); |
554 | if( !StringUtils.isBlank(objectClassName) ) {
|
||
555 | objectClass = Class.forName(objectClassName);
|
||
556 | } |
||
557 | } catch (Throwable e) { |
||
558 | LOGGER.warn("Can't restore the objectClass of the FeatureAttributreDescriptor", e);
|
||
559 | 40435 | jjdelcerro | } |
560 | precision = state.getInt("precision");
|
||
561 | evaluator = (Evaluator) state.get("evaluator");
|
||
562 | primaryKey = state.getBoolean("primaryKey");
|
||
563 | readOnly = state.getBoolean("readOnly");
|
||
564 | 44190 | jjdelcerro | SRS = (IProjection) state.get("SRS");
|
565 | 40435 | jjdelcerro | geometryType = state.getInt("geometryType");
|
566 | geometrySubType = state.getInt("geometrySubType");
|
||
567 | 44190 | jjdelcerro | if( geometryType!=Geometry.TYPES.UNKNOWN &&
|
568 | geometrySubType!=Geometry.SUBTYPES.UNKNOWN ) { |
||
569 | geomType = GeometryUtils.getGeometryType( |
||
570 | geometryType, |
||
571 | geometrySubType |
||
572 | ); |
||
573 | } |
||
574 | // additionalInfo = (Map) state.get("aditionalInfo");
|
||
575 | 40435 | jjdelcerro | isAutomatic = state.getBoolean("isAutomatic");
|
576 | 44077 | jjdelcerro | isTime = state.getBoolean("isTime");
|
577 | if( state.hasValue("intervalStart") ) { |
||
578 | 44190 | jjdelcerro | long intervalStart = state.getLong("interval_start"); |
579 | long intervalEnd = state.getLong("interval_end"); |
||
580 | 44077 | jjdelcerro | interval = TimeSupportLocator.getManager().createRelativeInterval(intervalStart, intervalEnd); |
581 | } else {
|
||
582 | interval = null;
|
||
583 | } |
||
584 | 44190 | jjdelcerro | featureAttributeEmulator = (FeatureAttributeEmulator) state.get("featureAttributeEmulator");
|
585 | indexed = state.getBoolean("indexed");
|
||
586 | isIndexAscending = state.getBoolean("isIndexAscending");
|
||
587 | allowIndexDuplicateds = state.getBoolean("allowIndexDuplicateds");
|
||
588 | |||
589 | 44202 | jjdelcerro | Map<String,Object> values = state.getMap("availableValues"); |
590 | if( values == null || values.isEmpty() ) { |
||
591 | this.availableValues = null; |
||
592 | } else {
|
||
593 | this.availableValues = new DynObjectValueItem[values.size()]; |
||
594 | int n = 0; |
||
595 | for (Entry<String, Object> entry : values.entrySet()) { |
||
596 | this.availableValues[n++] = new DynObjectValueItem(entry.getValue(), entry.getKey()); |
||
597 | } |
||
598 | } |
||
599 | |||
600 | 44190 | jjdelcerro | description = state.getString("description");
|
601 | minValue = state.get("minValue");
|
||
602 | maxValue = state.get("maxValue");
|
||
603 | label = state.getString("label");
|
||
604 | order = state.getInt("order");
|
||
605 | hidden = state.getBoolean("hidden");
|
||
606 | groupName = state.getString("groupName");
|
||
607 | 44253 | jjdelcerro | relationType = state.getInt("relationType");
|
608 | 40435 | jjdelcerro | } |
609 | |||
610 | 42561 | jjdelcerro | @Override
|
611 | 40435 | jjdelcerro | public void saveToState(PersistentState state) throws PersistenceException { |
612 | state.set("allowNull", allowNull);
|
||
613 | 44190 | jjdelcerro | state.set("dataType", dataType.getType());
|
614 | state.set("dataProfile", dataProfile);
|
||
615 | |||
616 | // FIXME: dateFormat;
|
||
617 | 40435 | jjdelcerro | |
618 | 44190 | jjdelcerro | state.set("defaultValue", Objects.toString(defaultValue));
|
619 | 40435 | jjdelcerro | |
620 | 44190 | jjdelcerro | state.set("index", index);
|
621 | state.set("maximumOccurrences", maximumOccurrences);
|
||
622 | state.set("minimumOccurrences", minimumOccurrences);
|
||
623 | state.set("size", size);
|
||
624 | state.set("name", name);
|
||
625 | state.set("objectClass", objectClass==null? null:objectClass.getName()); |
||
626 | state.set("precision", precision);
|
||
627 | state.set("evaluator", evaluator);
|
||
628 | |||
629 | state.set("primaryKey", primaryKey);
|
||
630 | state.set("readOnly", readOnly);
|
||
631 | state.set("SRS", SRS);
|
||
632 | GeometryType theGeomType = this.getGeomType();
|
||
633 | if( theGeomType==null ) { |
||
634 | state.set("geometryType", Geometry.TYPES.UNKNOWN);
|
||
635 | state.set("geometrySubType", Geometry.SUBTYPES.UNKNOWN);
|
||
636 | } else {
|
||
637 | state.set("geometryType", theGeomType.getType());
|
||
638 | state.set("geometrySubType", theGeomType.getSubType());
|
||
639 | 40435 | jjdelcerro | } |
640 | 44190 | jjdelcerro | |
641 | // FIXME: additionalInfo
|
||
642 | |||
643 | state.set("isAutomatic", isAutomatic);
|
||
644 | state.set("isTime", isTime);
|
||
645 | if( this.interval==null ) { |
||
646 | state.setNull("interval_start");
|
||
647 | state.setNull("interval_end");
|
||
648 | } else {
|
||
649 | state.set("interval_start", ((RelativeInterval)interval).getStart().toMillis());
|
||
650 | state.set("interval_end", ((RelativeInterval)interval).getEnd().toMillis());
|
||
651 | 40435 | jjdelcerro | } |
652 | 44190 | jjdelcerro | state.set("SRS", SRS);
|
653 | |||
654 | // FIXME: featureAttributeGetter
|
||
655 | |||
656 | if( featureAttributeEmulator instanceof Persistent ) { |
||
657 | state.set("featureAttributeEmulator", featureAttributeEmulator);
|
||
658 | } else {
|
||
659 | state.setNull("featureAttributeEmulator");
|
||
660 | } |
||
661 | |||
662 | state.set("indexed", indexed);
|
||
663 | state.set("isIndexAscending", isIndexAscending);
|
||
664 | state.set("allowIndexDuplicateds", allowIndexDuplicateds);
|
||
665 | |||
666 | 44202 | jjdelcerro | if( this.availableValues==null ) { |
667 | state.setNull("availableValues");
|
||
668 | } else {
|
||
669 | Map<String,Object> values = new HashMap<>(); |
||
670 | for (DynObjectValueItem value : availableValues) {
|
||
671 | values.put(value.getLabel(),value.getValue()); |
||
672 | } |
||
673 | state.set("availableValues", values);
|
||
674 | } |
||
675 | 44190 | jjdelcerro | state.set("description", description);
|
676 | state.set("minValue", minValue);
|
||
677 | state.set("maxValue", maxValue);
|
||
678 | state.set("label", label);
|
||
679 | state.set("order", order);
|
||
680 | state.set("hidden", hidden);
|
||
681 | state.set("groupName", groupName);
|
||
682 | 44253 | jjdelcerro | state.set("relationType",relationType);
|
683 | 44190 | jjdelcerro | |
684 | 40435 | jjdelcerro | } |
685 | 44190 | jjdelcerro | |
686 | private static final String FEATATTRDESC_PERSISTENCE_DEFINITION_NAME = "FeatureAttributeDescriptor"; |
||
687 | 40435 | jjdelcerro | |
688 | 44190 | jjdelcerro | public static void registerPersistenceDefinition() { |
689 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
690 | |||
691 | |||
692 | if (manager.getDefinition(FEATATTRDESC_PERSISTENCE_DEFINITION_NAME)
|
||
693 | == null) {
|
||
694 | DynStruct definition = manager.addDefinition(DefaultFeatureAttributeDescriptor.class, |
||
695 | FEATATTRDESC_PERSISTENCE_DEFINITION_NAME, |
||
696 | FEATATTRDESC_PERSISTENCE_DEFINITION_NAME |
||
697 | + " persistent definition",
|
||
698 | null,
|
||
699 | null
|
||
700 | ); |
||
701 | definition.addDynFieldBoolean("allowNull");
|
||
702 | definition.addDynFieldInt("dataType");
|
||
703 | definition.addDynFieldString("dataProfile");
|
||
704 | // definition.addDynFieldString("dateFormat");
|
||
705 | definition.addDynFieldString("defaultValue");
|
||
706 | definition.addDynFieldInt("index");
|
||
707 | definition.addDynFieldInt("maximumOccurrences");
|
||
708 | definition.addDynFieldInt("minimumOccurrences");
|
||
709 | definition.addDynFieldInt("size");
|
||
710 | definition.addDynFieldString("name");
|
||
711 | definition.addDynFieldString("objectClass");
|
||
712 | definition.addDynFieldInt("precision");
|
||
713 | definition.addDynFieldObject("evaluator")
|
||
714 | .setClassOfValue(Evaluator.class); |
||
715 | definition.addDynFieldBoolean("primaryKey");
|
||
716 | definition.addDynFieldBoolean("readOnly");
|
||
717 | definition.addDynFieldObject("SRS")
|
||
718 | .setClassOfValue(IProjection.class); |
||
719 | definition.addDynFieldInt("geometryType");
|
||
720 | definition.addDynFieldInt("geometrySubType");
|
||
721 | // definition.addDynFieldMap("additionalInfo");
|
||
722 | definition.addDynFieldBoolean("isAutomatic");
|
||
723 | definition.addDynFieldBoolean("isTime");
|
||
724 | definition.addDynFieldLong("interval_start");
|
||
725 | definition.addDynFieldLong("interval_end");
|
||
726 | definition.addDynFieldObject("featureAttributeEmulator")
|
||
727 | .setClassOfValue(FeatureAttributeEmulator.class); |
||
728 | definition.addDynFieldBoolean("indexed");
|
||
729 | definition.addDynFieldBoolean("isIndexAscending");
|
||
730 | definition.addDynFieldBoolean("allowIndexDuplicateds");
|
||
731 | 44202 | jjdelcerro | definition.addDynFieldMap("availableValues");
|
732 | definition.addDynFieldString("description");
|
||
733 | definition.addDynFieldObject("minValue");
|
||
734 | definition.addDynFieldObject("maxValue");
|
||
735 | definition.addDynFieldString("label");
|
||
736 | 44190 | jjdelcerro | definition.addDynFieldInt("order");
|
737 | definition.addDynFieldBoolean("hidden");
|
||
738 | 44202 | jjdelcerro | definition.addDynFieldString("groupName");
|
739 | 44253 | jjdelcerro | definition.addDynFieldInt("relationType");
|
740 | 44190 | jjdelcerro | } |
741 | } |
||
742 | |||
743 | |||
744 | 42563 | jjdelcerro | /*
|
745 | 40435 | jjdelcerro | * Start of DynField interface Implementation
|
746 | 42561 | jjdelcerro | *
|
747 | 40435 | jjdelcerro | */
|
748 | 42634 | fdiaz | |
749 | 43739 | jjdelcerro | @Override
|
750 | 42563 | jjdelcerro | public Tags getTags() {
|
751 | return tags;
|
||
752 | } |
||
753 | 42634 | fdiaz | |
754 | 42561 | jjdelcerro | @Override
|
755 | 40435 | jjdelcerro | public DynObjectValueItem[] getAvailableValues() { |
756 | 44259 | jjdelcerro | if( this.availableValues == null ) { |
757 | if( StringUtils.isBlank(this.getDataProfileName()) ) { |
||
758 | return null; |
||
759 | } |
||
760 | if( !StringUtils.equalsIgnoreCase(
|
||
761 | this.getDataProfileName(),
|
||
762 | DataManager.DAL_SELECTABLE_FOREING_KEY) |
||
763 | ) { |
||
764 | return null; |
||
765 | } |
||
766 | Tags theTags = this.getTags();
|
||
767 | if( theTags==null ) { |
||
768 | return null; |
||
769 | } |
||
770 | String foreingLabel = theTags.getString(DAL_FOREING_LABEL, null); |
||
771 | if( StringUtils.isBlank(foreingLabel) ) {
|
||
772 | return null; |
||
773 | } |
||
774 | String foreingTableName = theTags.getString(DAL_FOREING_TABLE, null); |
||
775 | if( StringUtils.isBlank(foreingTableName) ) {
|
||
776 | return null; |
||
777 | } |
||
778 | String foreingCodeName = theTags.getString(DAL_FOREING_CODE, null); |
||
779 | if( StringUtils.isBlank(foreingCodeName) ) {
|
||
780 | return null; |
||
781 | } |
||
782 | try {
|
||
783 | DataManager dataManager = DALLocator.getDataManager(); |
||
784 | StoresRepository repository = this.getStore().getStoresRepository();
|
||
785 | FeatureStore store = (FeatureStore) repository.get(foreingTableName); |
||
786 | if( store == null ) { |
||
787 | LOGGER.warn("Can't locate store '"+foreingTableName+"' to get available values of field '"+this.getName()+"'."); |
||
788 | return null; |
||
789 | } |
||
790 | |||
791 | Expression labelExpression = ExpressionUtils.createExpression(foreingLabel);
|
||
792 | FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
||
793 | SymbolTable symbolTable = featureSymbolTable.createParent(); |
||
794 | |||
795 | int count = (int) store.getFeatureCount(); |
||
796 | DynObjectValueItem[] values = new DynObjectValueItem[count]; |
||
797 | int n = 0; |
||
798 | for (Feature feature : store.getFeatureSet()) {
|
||
799 | featureSymbolTable.setFeature(feature); |
||
800 | Object code = feature.get(foreingCodeName);
|
||
801 | Object label = labelExpression.execute(symbolTable);
|
||
802 | values[n++] = new DynObjectValueItem(code, Objects.toString(label, Objects.toString(code, "##ERROR##"))); |
||
803 | } |
||
804 | this.availableValues = values;
|
||
805 | } catch (Exception ex) { |
||
806 | LOGGER.warn("Can't get values from table '" + foreingTableName + "' for field '" + this.getName() + "'.", ex); |
||
807 | return null; |
||
808 | } |
||
809 | } |
||
810 | 42563 | jjdelcerro | return this.availableValues; |
811 | 40435 | jjdelcerro | } |
812 | |||
813 | 42561 | jjdelcerro | @Override
|
814 | 40435 | jjdelcerro | public String getDescription() { |
815 | 42563 | jjdelcerro | if( this.description == null ) { |
816 | return getName();
|
||
817 | } |
||
818 | return this.description; |
||
819 | 40435 | jjdelcerro | } |
820 | |||
821 | 42561 | jjdelcerro | @Override
|
822 | 40435 | jjdelcerro | public Object getMaxValue() { |
823 | 42563 | jjdelcerro | return this.maxValue; |
824 | 40435 | jjdelcerro | } |
825 | |||
826 | 42561 | jjdelcerro | @Override
|
827 | 40435 | jjdelcerro | public Object getMinValue() { |
828 | 42563 | jjdelcerro | return this.minValue; |
829 | 40435 | jjdelcerro | } |
830 | |||
831 | 42561 | jjdelcerro | @Override
|
832 | 40435 | jjdelcerro | public int getTheTypeOfAvailableValues() { |
833 | 42563 | jjdelcerro | return 1; |
834 | 40435 | jjdelcerro | } |
835 | |||
836 | 42561 | jjdelcerro | @Override
|
837 | 40435 | jjdelcerro | public int getType() { |
838 | 42561 | jjdelcerro | if (featureAttributeGetter != null) { |
839 | 40435 | jjdelcerro | return featureAttributeGetter.getDataType().getType();
|
840 | } |
||
841 | return getDataType().getType();
|
||
842 | } |
||
843 | |||
844 | 42561 | jjdelcerro | @Override
|
845 | 40435 | jjdelcerro | public boolean isMandatory() { |
846 | return !allowNull() || isPrimaryKey();
|
||
847 | } |
||
848 | |||
849 | 42561 | jjdelcerro | @Override
|
850 | 40435 | jjdelcerro | public boolean isPersistent() { |
851 | return false; |
||
852 | } |
||
853 | |||
854 | 42561 | jjdelcerro | @Override
|
855 | 40435 | jjdelcerro | public DynField setAvailableValues(DynObjectValueItem[] values) { |
856 | 42563 | jjdelcerro | if ( ArrayUtils.isEmpty(values) ) {
|
857 | this.availableValues = null; |
||
858 | } else {
|
||
859 | this.availableValues = values;
|
||
860 | } |
||
861 | return this; |
||
862 | 40435 | jjdelcerro | } |
863 | |||
864 | 42561 | jjdelcerro | @Override
|
865 | 40435 | jjdelcerro | public DynField setDescription(String description) { |
866 | 42563 | jjdelcerro | this.description = description;
|
867 | return this; |
||
868 | 40435 | jjdelcerro | } |
869 | |||
870 | 42561 | jjdelcerro | @Override
|
871 | 40435 | jjdelcerro | public DynField setMandatory(boolean mandatory) { |
872 | throw new UnsupportedOperationException(); |
||
873 | } |
||
874 | |||
875 | 42561 | jjdelcerro | @Override
|
876 | 40435 | jjdelcerro | public DynField setMaxValue(Object maxValue) { |
877 | 42563 | jjdelcerro | try {
|
878 | this.maxValue = this.coerce(maxValue); |
||
879 | } catch (CoercionException e) {
|
||
880 | throw new IllegalArgumentException(e); |
||
881 | } |
||
882 | return this; |
||
883 | 40435 | jjdelcerro | } |
884 | |||
885 | 42561 | jjdelcerro | @Override
|
886 | 40435 | jjdelcerro | public DynField setMinValue(Object minValue) { |
887 | 42563 | jjdelcerro | try {
|
888 | this.maxValue = this.coerce(minValue); |
||
889 | } catch (CoercionException e) {
|
||
890 | throw new IllegalArgumentException(e); |
||
891 | } |
||
892 | return this; |
||
893 | 40435 | jjdelcerro | } |
894 | |||
895 | 42561 | jjdelcerro | @Override
|
896 | 40435 | jjdelcerro | public DynField setPersistent(boolean persistent) { |
897 | throw new UnsupportedOperationException(); |
||
898 | } |
||
899 | |||
900 | 42561 | jjdelcerro | @Override
|
901 | 40435 | jjdelcerro | public DynField setTheTypeOfAvailableValues(int type) { |
902 | throw new UnsupportedOperationException(); |
||
903 | } |
||
904 | |||
905 | 42561 | jjdelcerro | @Override
|
906 | 40435 | jjdelcerro | public DynField setType(int type) { |
907 | throw new UnsupportedOperationException(); |
||
908 | } |
||
909 | |||
910 | 42561 | jjdelcerro | @Override
|
911 | 40435 | jjdelcerro | public DynField setDefaultDynValue(Object defaultValue) { |
912 | throw new UnsupportedOperationException(); |
||
913 | } |
||
914 | |||
915 | 42561 | jjdelcerro | @Override
|
916 | 40435 | jjdelcerro | public Class getClassOfValue() { |
917 | return null; |
||
918 | } |
||
919 | |||
920 | 42561 | jjdelcerro | @Override
|
921 | 40435 | jjdelcerro | public DynField getElementsType() {
|
922 | return null; |
||
923 | } |
||
924 | |||
925 | 42561 | jjdelcerro | @Override
|
926 | 40435 | jjdelcerro | public DynField setClassOfValue(Class theClass) |
927 | 42561 | jjdelcerro | throws DynFieldIsNotAContainerException {
|
928 | 40435 | jjdelcerro | throw new UnsupportedOperationException(); |
929 | } |
||
930 | |||
931 | 42561 | jjdelcerro | @Override
|
932 | 40435 | jjdelcerro | public DynField setElementsType(DynStruct type)
|
933 | 42561 | jjdelcerro | throws DynFieldIsNotAContainerException {
|
934 | 40435 | jjdelcerro | throw new UnsupportedOperationException(); |
935 | } |
||
936 | |||
937 | 42561 | jjdelcerro | @Override
|
938 | 40435 | jjdelcerro | public DynField setElementsType(int type) |
939 | 42561 | jjdelcerro | throws DynFieldIsNotAContainerException {
|
940 | 40435 | jjdelcerro | throw new UnsupportedOperationException(); |
941 | } |
||
942 | |||
943 | 44128 | jjdelcerro | public FeatureAttributeDescriptor setDataProfileName(String dataProfile) { |
944 | this.dataProfile = dataProfile;
|
||
945 | return this; |
||
946 | } |
||
947 | |||
948 | 42561 | jjdelcerro | @Override
|
949 | 44128 | jjdelcerro | public String getDataProfileName() { |
950 | return dataProfile;
|
||
951 | 40435 | jjdelcerro | } |
952 | |||
953 | 42561 | jjdelcerro | @Override
|
954 | 40435 | jjdelcerro | public void validate(Object value) throws DynFieldValidateException { |
955 | 42561 | jjdelcerro | |
956 | 40435 | jjdelcerro | if (value == null && !this.allowNull()) { |
957 | throw new DynFieldValidateException(value, this, null); |
||
958 | } |
||
959 | 42561 | jjdelcerro | |
960 | 40435 | jjdelcerro | try {
|
961 | this.dataType.coerce(value);
|
||
962 | } catch (CoercionException e) {
|
||
963 | throw new DynFieldValidateException(value, this, e); |
||
964 | } |
||
965 | 42561 | jjdelcerro | |
966 | 40435 | jjdelcerro | /*
|
967 | * Other checks will be needed
|
||
968 | */
|
||
969 | } |
||
970 | |||
971 | 42561 | jjdelcerro | @Override
|
972 | 40435 | jjdelcerro | public String getSubtype() { |
973 | 42561 | jjdelcerro | if (featureAttributeGetter != null) { |
974 | 40435 | jjdelcerro | return featureAttributeGetter.getDataType().getSubtype();
|
975 | 42561 | jjdelcerro | } |
976 | 40435 | jjdelcerro | return this.dataType.getSubtype(); |
977 | } |
||
978 | |||
979 | 42561 | jjdelcerro | @Override
|
980 | 42563 | jjdelcerro | public Object coerce(Object value) throws CoercionException { |
981 | if ( value == null ) { |
||
982 | return value; // O debe devolver this.defaultValue |
||
983 | } |
||
984 | try {
|
||
985 | return this.getDataType().coerce(value); |
||
986 | } catch(Exception ex){ |
||
987 | throw new RuntimeException(ex); |
||
988 | } |
||
989 | 40435 | jjdelcerro | } |
990 | |||
991 | 42561 | jjdelcerro | @Override
|
992 | 40435 | jjdelcerro | public DynField setAvailableValues(List values) { |
993 | 42563 | jjdelcerro | if ( values == null || values.isEmpty() ) { |
994 | this.availableValues = null; |
||
995 | } else {
|
||
996 | this.availableValues = (DynObjectValueItem[]) values.toArray( |
||
997 | new DynObjectValueItem[values.size()]
|
||
998 | ); |
||
999 | } |
||
1000 | return this; |
||
1001 | 40435 | jjdelcerro | } |
1002 | |||
1003 | 42561 | jjdelcerro | @Override
|
1004 | 40435 | jjdelcerro | public String getGroup() { |
1005 | 42563 | jjdelcerro | return this.groupName; |
1006 | 40435 | jjdelcerro | } |
1007 | |||
1008 | 42561 | jjdelcerro | @Override
|
1009 | 40435 | jjdelcerro | public int getOder() { |
1010 | 42563 | jjdelcerro | return this.order; |
1011 | 40435 | jjdelcerro | } |
1012 | |||
1013 | 42561 | jjdelcerro | @Override
|
1014 | 41323 | jjdelcerro | public String getLabel() { |
1015 | 42563 | jjdelcerro | if( this.label == null ) { |
1016 | return this.getName(); |
||
1017 | } |
||
1018 | return this.label; |
||
1019 | 41323 | jjdelcerro | } |
1020 | |||
1021 | 42561 | jjdelcerro | @Override
|
1022 | 41323 | jjdelcerro | public DynField setLabel(String label) { |
1023 | 42563 | jjdelcerro | this.label = label;
|
1024 | return this; |
||
1025 | 41323 | jjdelcerro | } |
1026 | |||
1027 | 42561 | jjdelcerro | @Override
|
1028 | 40435 | jjdelcerro | public DynField setGroup(String groupName) { |
1029 | 42563 | jjdelcerro | this.groupName = groupName;
|
1030 | return this; |
||
1031 | 40435 | jjdelcerro | } |
1032 | |||
1033 | 42561 | jjdelcerro | @Override
|
1034 | 40435 | jjdelcerro | public DynField setOrder(int order) { |
1035 | 42563 | jjdelcerro | this.order = order;
|
1036 | return this; |
||
1037 | 40435 | jjdelcerro | } |
1038 | |||
1039 | 42561 | jjdelcerro | @Override
|
1040 | 40435 | jjdelcerro | public DynField setHidden(boolean hidden) { |
1041 | 42563 | jjdelcerro | this.hidden = hidden;
|
1042 | return this; |
||
1043 | 40435 | jjdelcerro | } |
1044 | |||
1045 | 42561 | jjdelcerro | @Override
|
1046 | 40435 | jjdelcerro | public boolean isHidden() { |
1047 | 42563 | jjdelcerro | return this.hidden; |
1048 | 40435 | jjdelcerro | } |
1049 | |||
1050 | 42561 | jjdelcerro | @Override
|
1051 | 40435 | jjdelcerro | public DynField setReadOnly(boolean arg0) { |
1052 | throw new UnsupportedOperationException(); |
||
1053 | } |
||
1054 | |||
1055 | 42561 | jjdelcerro | @Override
|
1056 | 40435 | jjdelcerro | public boolean isContainer() { |
1057 | return false; |
||
1058 | } |
||
1059 | |||
1060 | 42561 | jjdelcerro | @Override
|
1061 | 40435 | jjdelcerro | public Class getClassOfItems() { |
1062 | return null; |
||
1063 | } |
||
1064 | |||
1065 | 42561 | jjdelcerro | @Override
|
1066 | 40435 | jjdelcerro | public DynField setDefaultFieldValue(Object defaultValue) { |
1067 | throw new UnsupportedOperationException(); |
||
1068 | } |
||
1069 | |||
1070 | 42561 | jjdelcerro | @Override
|
1071 | 40435 | jjdelcerro | public DynField setClassOfItems(Class theClass) { |
1072 | throw new UnsupportedOperationException(); |
||
1073 | } |
||
1074 | |||
1075 | 42561 | jjdelcerro | @Override
|
1076 | 40435 | jjdelcerro | public DynField setType(DataType type) {
|
1077 | throw new UnsupportedOperationException(); |
||
1078 | } |
||
1079 | |||
1080 | 42561 | jjdelcerro | @Override
|
1081 | 44128 | jjdelcerro | public DynField setSubtype(String subtype) { |
1082 | throw new UnsupportedOperationException(); |
||
1083 | } |
||
1084 | |||
1085 | @Override
|
||
1086 | 42561 | jjdelcerro | public boolean isTime() { |
1087 | return isTime;
|
||
1088 | } |
||
1089 | 40435 | jjdelcerro | |
1090 | 42561 | jjdelcerro | @Override
|
1091 | 40435 | jjdelcerro | public FeatureAttributeGetter getFeatureAttributeGetter() {
|
1092 | 42561 | jjdelcerro | return featureAttributeGetter;
|
1093 | 40435 | jjdelcerro | } |
1094 | |||
1095 | 42561 | jjdelcerro | @Override
|
1096 | 40435 | jjdelcerro | public void setFeatureAttributeGetter( |
1097 | 42561 | jjdelcerro | FeatureAttributeGetter featureAttributeTransform) { |
1098 | this.featureAttributeGetter = featureAttributeTransform;
|
||
1099 | } |
||
1100 | 41335 | jjdelcerro | |
1101 | 42561 | jjdelcerro | @Override
|
1102 | 41335 | jjdelcerro | public FeatureAttributeEmulator getFeatureAttributeEmulator() {
|
1103 | return this.featureAttributeEmulator; |
||
1104 | } |
||
1105 | |||
1106 | 43954 | jjdelcerro | public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
1107 | this.featureAttributeEmulator = featureAttributeEmulator;
|
||
1108 | return this; |
||
1109 | } |
||
1110 | |||
1111 | 42561 | jjdelcerro | @Override
|
1112 | 41638 | jjdelcerro | public boolean isIndexed() { |
1113 | return this.indexed; |
||
1114 | } |
||
1115 | |||
1116 | 42561 | jjdelcerro | @Override
|
1117 | 41638 | jjdelcerro | public boolean allowIndexDuplicateds() { |
1118 | return this.allowIndexDuplicateds; |
||
1119 | } |
||
1120 | |||
1121 | 42561 | jjdelcerro | @Override
|
1122 | 41638 | jjdelcerro | public boolean isIndexAscending() { |
1123 | return this.isIndexAscending; |
||
1124 | } |
||
1125 | |||
1126 | 42563 | jjdelcerro | @Override
|
1127 | public DynField setClassOfValue(DynStruct dynStrct) {
|
||
1128 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
1129 | } |
||
1130 | |||
1131 | @Override
|
||
1132 | public DynField setClassOfValue(String theClassNameOfValue) { |
||
1133 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
1134 | } |
||
1135 | |||
1136 | @Override
|
||
1137 | public String getClassNameOfValue() { |
||
1138 | 42634 | fdiaz | return null; |
1139 | 42563 | jjdelcerro | } |
1140 | |||
1141 | @Override
|
||
1142 | public DynStruct getDynClassOfValue() {
|
||
1143 | 42634 | fdiaz | return null; |
1144 | 42563 | jjdelcerro | } |
1145 | |||
1146 | @Override
|
||
1147 | public DynField setTypeOfItems(int type) { |
||
1148 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
1149 | } |
||
1150 | |||
1151 | @Override
|
||
1152 | public int getTypeOfItems() { |
||
1153 | 42634 | fdiaz | return DataTypes.INVALID;
|
1154 | 42563 | jjdelcerro | } |
1155 | |||
1156 | @Override
|
||
1157 | public DynField setClassOfItems(DynStruct dynStrct) {
|
||
1158 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
1159 | } |
||
1160 | |||
1161 | @Override
|
||
1162 | public DynField setClassOfItems(String theClassNameOfValue) { |
||
1163 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
1164 | } |
||
1165 | |||
1166 | @Override
|
||
1167 | public String getClassNameOfItems() { |
||
1168 | 42634 | fdiaz | return null; |
1169 | 42563 | jjdelcerro | } |
1170 | |||
1171 | @Override
|
||
1172 | public DynStruct getDynClassOfItems() {
|
||
1173 | 42634 | fdiaz | return null; |
1174 | 42563 | jjdelcerro | } |
1175 | |||
1176 | @Override
|
||
1177 | public DynField setRelationType(int relationType) { |
||
1178 | 44253 | jjdelcerro | this.relationType = relationType;
|
1179 | return this; |
||
1180 | 42563 | jjdelcerro | } |
1181 | |||
1182 | @Override
|
||
1183 | public int getRelationType() { |
||
1184 | 44253 | jjdelcerro | return this.relationType; |
1185 | 42563 | jjdelcerro | } |
1186 | |||
1187 | 42606 | jjdelcerro | @Override
|
1188 | 42775 | jjdelcerro | public DynField setAvailableValues(DynMethod availableValuesMethod) {
|
1189 | this.availableValuesMethod = availableValuesMethod;
|
||
1190 | return this; |
||
1191 | 42606 | jjdelcerro | } |
1192 | |||
1193 | @Override
|
||
1194 | 42775 | jjdelcerro | public DynObjectValueItem[] getAvailableValues(DynObject self) { |
1195 | if( this.availableValuesMethod != null ) { |
||
1196 | DynObjectValueItem[] values;
|
||
1197 | try {
|
||
1198 | values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this}); |
||
1199 | } catch (DynMethodException ex) {
|
||
1200 | return this.availableValues; |
||
1201 | } |
||
1202 | 42606 | jjdelcerro | if( values != null ) { |
1203 | return values;
|
||
1204 | } |
||
1205 | } |
||
1206 | return this.availableValues; |
||
1207 | } |
||
1208 | |||
1209 | 42775 | jjdelcerro | @Override
|
1210 | public DynMethod getAvailableValuesMethod() {
|
||
1211 | return this.availableValuesMethod; |
||
1212 | } |
||
1213 | |||
1214 | @Override
|
||
1215 | public boolean isAvailableValuesCalculated() { |
||
1216 | return this.availableValuesMethod!=null; |
||
1217 | } |
||
1218 | |||
1219 | @Override
|
||
1220 | public DynMethod getCalculateMethod() {
|
||
1221 | return this.calculateMethod; |
||
1222 | } |
||
1223 | |||
1224 | @Override
|
||
1225 | public DynField setCalculateMethod(DynMethod method) {
|
||
1226 | this.calculateMethod = method;
|
||
1227 | return this; |
||
1228 | } |
||
1229 | |||
1230 | @Override
|
||
1231 | public boolean isCalculated() { |
||
1232 | return this.calculateMethod != null; |
||
1233 | } |
||
1234 | |||
1235 | @Override
|
||
1236 | public Object getCalculatedValue(DynObject self) { |
||
1237 | try {
|
||
1238 | return this.calculateMethod.invoke(self, new Object[] { this }); |
||
1239 | } catch (DynMethodException ex) {
|
||
1240 | throw new RuntimeException(ex); |
||
1241 | } |
||
1242 | } |
||
1243 | |||
1244 | @Override
|
||
1245 | public DynField setValidateElements(boolean validate) { |
||
1246 | return this; |
||
1247 | } |
||
1248 | |||
1249 | @Override
|
||
1250 | public boolean getValidateElements() { |
||
1251 | return false; |
||
1252 | } |
||
1253 | |||
1254 | 41212 | jjdelcerro | private class ConstantValueEvaluator extends AbstractEvaluator { |
1255 | 42561 | jjdelcerro | |
1256 | @Override
|
||
1257 | 41212 | jjdelcerro | public Object evaluate(EvaluatorData data) throws EvaluatorException { |
1258 | return defaultValue;
|
||
1259 | } |
||
1260 | 42561 | jjdelcerro | |
1261 | @Override
|
||
1262 | 41212 | jjdelcerro | public String getName() { |
1263 | 42561 | jjdelcerro | return "Constant attribute " + name; |
1264 | 41212 | jjdelcerro | } |
1265 | } |
||
1266 | 41335 | jjdelcerro | |
1267 | 41212 | jjdelcerro | public void setConstantValue(boolean isConstantValue) { |
1268 | 42561 | jjdelcerro | if (isConstantValue) {
|
1269 | 41212 | jjdelcerro | /* Cuando un attributo tiene asociado un evaluador, este se interpreta
|
1270 | 42634 | fdiaz | * como que no debe cargarse de la fuente de datos subyacente, siendo
|
1271 | 41212 | jjdelcerro | * el evaluador el que se encarga de proporcionar su valor.
|
1272 | * Nos limitamos a asignar un evaluador que retorna simpre el valor
|
||
1273 | * por defecto para ese attributo.
|
||
1274 | */
|
||
1275 | this.evaluator = new ConstantValueEvaluator(); |
||
1276 | } else {
|
||
1277 | this.evaluator = null; |
||
1278 | } |
||
1279 | } |
||
1280 | 42561 | jjdelcerro | |
1281 | 43739 | jjdelcerro | @Override
|
1282 | 43135 | jjdelcerro | public boolean isComputed() { |
1283 | 44190 | jjdelcerro | return featureAttributeEmulator!=null || evaluator!=null || isCalculated(); |
1284 | 43135 | jjdelcerro | } |
1285 | 43739 | jjdelcerro | |
1286 | @Override
|
||
1287 | public FeatureStore getStore() {
|
||
1288 | FeatureType ftype = this.getFeatureType();
|
||
1289 | if( ftype == null ) { |
||
1290 | return null; |
||
1291 | } |
||
1292 | return ftype.getStore();
|
||
1293 | } |
||
1294 | |||
1295 | @Override
|
||
1296 | public FeatureType getFeatureType() {
|
||
1297 | if( this.typeRef==null ) { |
||
1298 | return null; |
||
1299 | } |
||
1300 | 44259 | jjdelcerro | FeatureType ftype = (FeatureType) this.typeRef.get();
|
1301 | // LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] get FeatureType [%08x], ref [%08x].", this.hashCode(), ftype.hashCode(), typeRef.hashCode()));
|
||
1302 | return ftype;
|
||
1303 | 43739 | jjdelcerro | } |
1304 | 44094 | jjdelcerro | |
1305 | public FeatureAttributeDescriptor setInterval(Interval interval) {
|
||
1306 | this.interval = interval;
|
||
1307 | return this; |
||
1308 | } |
||
1309 | |||
1310 | public void fixAll() { |
||
1311 | switch(this.getType()) { |
||
1312 | case DataTypes.INSTANT:
|
||
1313 | case DataTypes.INTERVAL:
|
||
1314 | case DataTypes.DATE:
|
||
1315 | if( this.getInterval()!=null ) { |
||
1316 | this.isTime = true; |
||
1317 | } |
||
1318 | break;
|
||
1319 | } |
||
1320 | } |
||
1321 | |||
1322 | 44158 | jjdelcerro | @Override
|
1323 | public String[] getRequiredFieldNames() { |
||
1324 | FeatureAttributeEmulator emulator = this.getFeatureAttributeEmulator();
|
||
1325 | if( emulator==null ) { |
||
1326 | return null; |
||
1327 | } |
||
1328 | return emulator.getRequiredFieldNames();
|
||
1329 | } |
||
1330 | |||
1331 | 40435 | jjdelcerro | } |