Revision 45581 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/DefaultFeature.java
DefaultFeature.java | ||
---|---|---|
35 | 35 |
import java.util.List; |
36 | 36 |
import java.util.Map; |
37 | 37 |
import java.util.Objects; |
38 |
import org.gvsig.json.Json; |
|
39 | 38 |
import javax.json.JsonObject; |
40 |
import org.gvsig.json.JsonObjectBuilder; |
|
41 | 39 |
import org.apache.commons.lang3.ArrayUtils; |
42 | 40 |
import org.apache.commons.lang3.StringUtils; |
43 | 41 |
import org.cresques.cts.IProjection; |
... | ... | |
53 | 51 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
54 | 52 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
55 | 53 |
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
54 |
import org.gvsig.fmap.dal.feature.FeatureExtraColumns; |
|
56 | 55 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
57 | 56 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
58 | 57 |
import org.gvsig.fmap.dal.feature.FeatureType; |
... | ... | |
63 | 62 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
64 | 63 |
import org.gvsig.fmap.geom.Geometry; |
65 | 64 |
import org.gvsig.fmap.geom.primitive.Envelope; |
65 |
import org.gvsig.json.Json; |
|
66 |
import org.gvsig.json.JsonObjectBuilder; |
|
66 | 67 |
import org.gvsig.tools.ToolsLocator; |
67 | 68 |
import org.gvsig.tools.dataTypes.Coercion; |
68 | 69 |
import org.gvsig.tools.dataTypes.CoercionException; |
70 |
import org.gvsig.tools.dataTypes.DataType; |
|
69 | 71 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
72 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToString; |
|
70 | 73 |
import org.gvsig.tools.dynobject.DynObject; |
71 | 74 |
import org.gvsig.tools.evaluator.Evaluator; |
72 | 75 |
import org.gvsig.tools.evaluator.EvaluatorData; |
... | ... | |
74 | 77 |
import org.gvsig.tools.exception.BaseException; |
75 | 78 |
import org.gvsig.tools.exception.BaseRuntimeException; |
76 | 79 |
import org.gvsig.tools.lang.Cloneable; |
77 |
import org.gvsig.fmap.dal.feature.FeatureExtraColumns;
|
|
78 |
import org.gvsig.tools.dataTypes.DataType;
|
|
80 |
import org.slf4j.Logger;
|
|
81 |
import org.slf4j.LoggerFactory;
|
|
79 | 82 |
|
80 | 83 |
@SuppressWarnings("UseSpecificCatch") |
81 | 84 |
public class DefaultFeature implements Feature, EvaluatorData, Cloneable { |
82 | 85 |
|
83 |
private static DataTypesManager dataTypesManager = null; |
|
84 |
protected FeatureProvider data; |
|
85 |
protected FeatureReference reference; |
|
86 |
private WeakReference storeRef; |
|
86 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeature.class); |
|
87 | 87 |
|
88 |
private boolean inserted = false; |
|
89 |
private Object[] extraValuesData; |
|
90 |
private Map<String,Object> extraValues; // not persistent |
|
88 |
private static DataTypesManager dataTypesManager = null; |
|
89 |
protected FeatureProvider data; |
|
90 |
protected FeatureReference reference; |
|
91 |
private WeakReference storeRef; |
|
91 | 92 |
|
93 |
private boolean inserted = false; |
|
94 |
private Object[] extraValuesData; |
|
95 |
private Map<String, Object> extraValues; // not persistent |
|
96 |
|
|
92 | 97 |
/* |
93 | 98 |
* Usar con mucha precaucion o mejor no usar. Lo precisa el |
94 | 99 |
* DefaultFeatureSet en la ordenacion. |
95 |
*/
|
|
96 |
public DefaultFeature(FeatureStore store) {
|
|
97 |
this.storeRef = new WeakReference(store);
|
|
98 |
this.reference = null;
|
|
99 |
}
|
|
100 |
*/
|
|
101 |
public DefaultFeature(FeatureStore store) {
|
|
102 |
this.storeRef = new WeakReference(store);
|
|
103 |
this.reference = null;
|
|
104 |
}
|
|
100 | 105 |
|
101 |
public DefaultFeature(FeatureStore store, FeatureProvider data) {
|
|
102 |
this.data = data;
|
|
103 |
this.extraValuesData = null;
|
|
104 |
this.storeRef = new WeakReference(store);
|
|
105 |
this.reference = null;
|
|
106 |
this.inserted = !data.isNew();
|
|
107 |
}
|
|
106 |
public DefaultFeature(FeatureStore store, FeatureProvider data) {
|
|
107 |
this.data = data;
|
|
108 |
this.extraValuesData = null; |
|
109 |
this.storeRef = new WeakReference(store);
|
|
110 |
this.reference = null;
|
|
111 |
this.inserted = !data.isNew();
|
|
112 |
}
|
|
108 | 113 |
|
109 |
DefaultFeature(DefaultFeature feature) {
|
|
110 |
this.data = feature.data.getCopy();
|
|
111 |
this.extraValuesData = ArrayUtils.clone(feature.extraValuesData);
|
|
112 |
this.storeRef = feature.storeRef;
|
|
113 |
this.reference = feature.reference;
|
|
114 |
this.inserted = feature.isInserted();
|
|
115 |
}
|
|
114 |
DefaultFeature(DefaultFeature feature) {
|
|
115 |
this.data = feature.data.getCopy();
|
|
116 |
this.extraValuesData = ArrayUtils.clone(feature.extraValuesData); |
|
117 |
this.storeRef = feature.storeRef;
|
|
118 |
this.reference = feature.reference;
|
|
119 |
this.inserted = feature.isInserted();
|
|
120 |
}
|
|
116 | 121 |
|
117 | 122 |
public DefaultFeature(FeatureType targetType, Feature sourceFeature) { |
118 |
DefaultFeature defaultFeature = (DefaultFeature)sourceFeature; |
|
119 |
this.data = new DefaultFeatureProvider(targetType, (DefaultFeatureProvider)defaultFeature.getData()); |
|
123 |
DefaultFeature defaultFeature = (DefaultFeature) sourceFeature;
|
|
124 |
this.data = new DefaultFeatureProvider(targetType, (DefaultFeatureProvider) defaultFeature.getData());
|
|
120 | 125 |
this.extraValuesData = null; |
121 | 126 |
this.storeRef = defaultFeature.storeRef; |
122 | 127 |
this.reference = defaultFeature.reference; |
... | ... | |
125 | 130 |
FeatureType sourceType = sourceFeature.getType(); |
126 | 131 |
|
127 | 132 |
for (FeatureAttributeDescriptor targetAttrDescriptor : targetType) { |
128 |
if ( targetAttrDescriptor.isComputed() ) {
|
|
129 |
continue;
|
|
133 |
if (targetAttrDescriptor.isComputed()) {
|
|
134 |
continue; |
|
130 | 135 |
} |
131 | 136 |
int sourceIndex = sourceType.getIndex(targetAttrDescriptor.getName()); |
132 |
if (sourceIndex<0){
|
|
137 |
if (sourceIndex < 0) {
|
|
133 | 138 |
continue; |
134 | 139 |
} |
135 | 140 |
Object value = sourceFeature.get(sourceIndex); |
136 | 141 |
if (value == null && !targetAttrDescriptor.allowNull()) { |
137 | 142 |
continue; |
138 | 143 |
} |
139 |
this.setforced(targetAttrDescriptor.getIndex(), targetAttrDescriptor,value); |
|
144 |
this.setforced(targetAttrDescriptor.getIndex(), targetAttrDescriptor, value);
|
|
140 | 145 |
} |
141 | 146 |
} |
142 | 147 |
|
143 |
public void setData(FeatureProvider data) {
|
|
144 |
this.data = data;
|
|
145 |
this.extraValuesData = null;
|
|
146 |
this.reference = null;
|
|
147 |
this.inserted = true;
|
|
148 |
}
|
|
148 |
public void setData(FeatureProvider data) {
|
|
149 |
this.data = data;
|
|
150 |
this.extraValuesData = null; |
|
151 |
this.reference = null;
|
|
152 |
this.inserted = true;
|
|
153 |
}
|
|
149 | 154 |
|
150 |
public FeatureProvider getData() {
|
|
151 |
return this.data;
|
|
152 |
}
|
|
155 |
public FeatureProvider getData() {
|
|
156 |
return this.data;
|
|
157 |
}
|
|
153 | 158 |
|
154 |
protected DataTypesManager getDataTypesManager() {
|
|
155 |
if( dataTypesManager==null ) {
|
|
156 |
dataTypesManager = ToolsLocator.getDataTypesManager();
|
|
157 |
}
|
|
158 |
return dataTypesManager;
|
|
159 |
}
|
|
159 |
protected DataTypesManager getDataTypesManager() {
|
|
160 |
if (dataTypesManager == null) {
|
|
161 |
dataTypesManager = ToolsLocator.getDataTypesManager();
|
|
162 |
}
|
|
163 |
return dataTypesManager;
|
|
164 |
}
|
|
160 | 165 |
|
161 | 166 |
protected void set(FeatureAttributeDescriptor attribute, Object value) { |
162 | 167 |
int i = attribute.getIndex(); |
163 | 168 |
|
164 |
if ( attribute.isReadOnly() ) {
|
|
169 |
if (attribute.isReadOnly()) {
|
|
165 | 170 |
throw new SetReadOnlyAttributeException(attribute.getName(), this.getType()); |
166 | 171 |
} |
167 | 172 |
FeatureAttributeEmulator emulator = attribute.getFeatureAttributeEmulator(); |
168 |
if( emulator!= null ) {
|
|
169 |
emulator.set((EditableFeature) this,value); |
|
173 |
if (emulator != null) {
|
|
174 |
emulator.set((EditableFeature) this, value);
|
|
170 | 175 |
return; |
171 | 176 |
} |
172 | 177 |
|
173 |
if ( value == null ) {
|
|
174 |
if ( !attribute.allowNull() ) {
|
|
175 |
if ( !attribute.isAutomatic() ) {
|
|
178 |
if (value == null) {
|
|
179 |
if (!attribute.allowNull()) {
|
|
180 |
if (!attribute.isAutomatic()) {
|
|
176 | 181 |
throw new IllegalValueException(attribute, value); |
177 | 182 |
} |
178 | 183 |
} |
... | ... | |
181 | 186 |
|
182 | 187 |
} |
183 | 188 |
|
184 |
if ( attribute.getFeatureAttributeGetter() != null ) {
|
|
189 |
if (attribute.getFeatureAttributeGetter() != null) {
|
|
185 | 190 |
value = attribute.getFeatureAttributeGetter().setter(value); |
186 | 191 |
} |
187 | 192 |
this.setforced(i, attribute, value); |
... | ... | |
190 | 195 |
private void setforced(int i, FeatureAttributeDescriptor attribute, Object value) { |
191 | 196 |
|
192 | 197 |
Class objectClass = attribute.getObjectClass(); |
193 |
if( objectClass!=null ) { |
|
194 |
if ( objectClass.isInstance(value) ) { |
|
195 |
if( attribute.getType()==DataTypes.DECIMAL ) { |
|
196 |
BigDecimal d = (BigDecimal) value; |
|
197 |
if( d.scale()==attribute.getScale() && d.precision()<=attribute.getPrecision() ) { |
|
198 |
if (objectClass != null) { |
|
199 |
if (objectClass.isInstance(value)) { |
|
200 |
if (attribute.getType() == DataTypes.DECIMAL) { |
|
201 |
BigDecimal d = (BigDecimal) value; |
|
202 |
if (d.scale() == attribute.getScale() && d.precision() <= attribute.getPrecision()) { |
|
203 |
this.data.set(i, value); |
|
204 |
return; |
|
205 |
} |
|
206 |
} else { |
|
198 | 207 |
this.data.set(i, value); |
199 | 208 |
return; |
200 |
} |
|
201 |
} else { |
|
202 |
this.data.set(i, value); |
|
203 |
return; |
|
204 | 209 |
} |
205 | 210 |
} |
206 | 211 |
DataProfile dataProfile = attribute.getDataProfile(); |
207 |
if( dataProfile!=null ) {
|
|
212 |
if (dataProfile != null) {
|
|
208 | 213 |
try { |
209 | 214 |
value = dataProfile.coerce( |
210 | 215 |
attribute.getDataType(), |
211 |
value,
|
|
216 |
value, |
|
212 | 217 |
attribute.getTags() |
213 | 218 |
); |
214 | 219 |
} catch (CoercionException e) { |
215 | 220 |
|
216 | 221 |
} |
217 |
}
|
|
222 |
} |
|
218 | 223 |
try { |
219 | 224 |
Coercion coercer = attribute.getDataType().getCoercion(); |
220 |
if(attribute.getType()==DataTypes.STRING && value instanceof Boolean ){
|
|
225 |
if (attribute.getType() == DataTypes.STRING && value instanceof Boolean) {
|
|
221 | 226 |
value = coercer.coerce(value, attribute.getCoercionContext()); |
222 | 227 |
value = StringUtils.left((String) value, attribute.getSize()); |
223 | 228 |
} else { |
224 |
value= coercer.coerce(value, attribute.getCoercionContext()); |
|
229 |
value = coercer.coerce(value, attribute.getCoercionContext());
|
|
225 | 230 |
} |
226 | 231 |
} catch (CoercionException e) { |
227 | 232 |
throw new IllegalArgumentException("Can't convert to " |
228 | 233 |
+ attribute.getDataType().getName() |
229 | 234 |
+ " from '" |
230 |
+ value==null? "NULL":value.getClass().getName()
|
|
231 |
+ "' with value '" |
|
232 |
+ Objects.toString(value) |
|
233 |
+ "' and context '" |
|
234 |
+ attribute.getCoercionContext() |
|
235 |
+ "'."); |
|
235 |
+ value == null ? "NULL" : value.getClass().getName()
|
|
236 |
+ "' with value '"
|
|
237 |
+ Objects.toString(value)
|
|
238 |
+ "' and context '"
|
|
239 |
+ attribute.getCoercionContext()
|
|
240 |
+ "'.");
|
|
236 | 241 |
} |
237 | 242 |
} |
238 | 243 |
this.data.set(i, value); |
239 | 244 |
} |
240 | 245 |
|
241 |
private Object get(int index,Class theClass, int type) { |
|
246 |
private Object get(int index, Class theClass, int type) {
|
|
242 | 247 |
Object value = this.get(index); |
243 |
if( theClass.isInstance(value) ) {
|
|
248 |
if (theClass.isInstance(value)) {
|
|
244 | 249 |
return value; |
245 | 250 |
} |
246 | 251 |
try { |
... | ... | |
251 | 256 |
return null; |
252 | 257 |
} |
253 | 258 |
throw new IllegalArgumentException( |
254 |
"Can't convert to "+theClass.getName()+
|
|
255 |
" from '"+value.getClass().getName()+
|
|
256 |
"' with value '"+value.toString()+"'.");
|
|
259 |
"Can't convert to " + theClass.getName()
|
|
260 |
+ " from '" + value.getClass().getName()
|
|
261 |
+ "' with value '" + value.toString() + "'.");
|
|
257 | 262 |
} |
258 | 263 |
} |
259 | 264 |
|
... | ... | |
261 | 266 |
FeatureType type = this.getType(); |
262 | 267 |
for (FeatureAttributeDescriptor attribute : type) { |
263 | 268 |
if (attribute.isAutomatic() || attribute.isReadOnly() |
264 |
|| attribute.isComputed() ) {
|
|
269 |
|| attribute.isComputed()) { |
|
265 | 270 |
continue; |
266 | 271 |
} |
267 | 272 |
if (attribute.getDefaultValue() == null && !attribute.allowNull()) { |
268 | 273 |
continue; |
269 | 274 |
} |
270 |
Object value = attribute.getDefaultValue(); |
|
271 |
if( value instanceof CharSequence ) { |
|
272 |
String s = ((CharSequence)value).toString(); |
|
273 |
if( ExpressionUtils.isDynamicText(s) ) { |
|
274 |
try { |
|
275 |
value = ExpressionUtils.evaluateDynamicText(s); |
|
276 |
} catch(Throwable th) { |
|
277 |
value = null; |
|
275 |
Object value = attribute.getDefaultValue(); |
|
276 |
if (value instanceof CharSequence) { |
|
277 |
String s = ((CharSequence) value).toString(); |
|
278 |
if (ExpressionUtils.isDynamicText(s)) { |
|
279 |
try { |
|
280 |
value = ExpressionUtils.evaluateDynamicText(s); |
|
281 |
} catch (Throwable th) { |
|
282 |
value = null; |
|
283 |
} |
|
278 | 284 |
} |
279 |
} |
|
280 | 285 |
} |
281 | 286 |
this.set(attribute, value); |
282 | 287 |
} |
... | ... | |
287 | 292 |
} |
288 | 293 |
|
289 | 294 |
public void initializeValues(Feature feature) { |
290 |
FeatureType myType=this.getType();
|
|
291 |
FeatureType type =feature.getType(); |
|
295 |
FeatureType myType = this.getType();
|
|
296 |
FeatureType type = feature.getType();
|
|
292 | 297 |
extraValuesData = null; |
293 | 298 |
for (FeatureAttributeDescriptor attribute : type) { |
294 |
FeatureAttributeDescriptor myAttribute=myType.getAttributeDescriptor(attribute.getName());
|
|
299 |
FeatureAttributeDescriptor myAttribute = myType.getAttributeDescriptor(attribute.getName());
|
|
295 | 300 |
if (myAttribute != null) { |
296 | 301 |
this.set(myAttribute, feature.get(attribute.getIndex())); |
297 | 302 |
} |
298 | 303 |
} |
299 | 304 |
} |
300 | 305 |
|
301 |
|
|
302 | 306 |
@Override |
303 | 307 |
public FeatureStore getStore() { |
304 | 308 |
return (FeatureStore) this.storeRef.get(); |
... | ... | |
339 | 343 |
@Override |
340 | 344 |
public Object getOrDefault(String name, Object defaultValue) { |
341 | 345 |
int index = this.data.getType().getIndex(name); |
342 |
if( index < 0 ) {
|
|
346 |
if (index < 0) {
|
|
343 | 347 |
return defaultValue; |
344 | 348 |
} |
345 | 349 |
return this.get(index); |
... | ... | |
348 | 352 |
@Override |
349 | 353 |
public String getStringOrDefault(String name, String defaultValue) { |
350 | 354 |
int index = this.data.getType().getIndex(name); |
351 |
if( index < 0 ) {
|
|
355 |
if (index < 0) {
|
|
352 | 356 |
return defaultValue; |
353 | 357 |
} |
354 | 358 |
try { |
355 | 359 |
return (String) this.get(index); |
356 |
} catch(Throwable th) { |
|
360 |
} catch (Throwable th) {
|
|
357 | 361 |
return defaultValue; |
358 | 362 |
} |
359 | 363 |
} |
... | ... | |
361 | 365 |
@Override |
362 | 366 |
public boolean getBooleanOrDefault(String name, boolean defaultValue) { |
363 | 367 |
int index = this.data.getType().getIndex(name); |
364 |
if( index < 0 ) {
|
|
368 |
if (index < 0) {
|
|
365 | 369 |
return defaultValue; |
366 | 370 |
} |
367 | 371 |
try { |
368 | 372 |
return this.getBoolean(index); |
369 |
} catch(Throwable th) { |
|
373 |
} catch (Throwable th) {
|
|
370 | 374 |
return defaultValue; |
371 | 375 |
} |
372 | 376 |
} |
... | ... | |
374 | 378 |
@Override |
375 | 379 |
public int getIntOrDefault(String name, int defaultValue) { |
376 | 380 |
int index = this.data.getType().getIndex(name); |
377 |
if( index < 0 ) {
|
|
381 |
if (index < 0) {
|
|
378 | 382 |
return defaultValue; |
379 | 383 |
} |
380 | 384 |
try { |
381 | 385 |
return this.getInt(index); |
382 |
} catch(Throwable th) { |
|
386 |
} catch (Throwable th) {
|
|
383 | 387 |
return defaultValue; |
384 | 388 |
} |
385 | 389 |
} |
... | ... | |
387 | 391 |
@Override |
388 | 392 |
public long getLongOrDefault(String name, long defaultValue) { |
389 | 393 |
int index = this.data.getType().getIndex(name); |
390 |
if( index < 0 ) {
|
|
394 |
if (index < 0) {
|
|
391 | 395 |
return defaultValue; |
392 | 396 |
} |
393 | 397 |
try { |
394 | 398 |
return this.getLong(index); |
395 |
} catch(Throwable th) { |
|
399 |
} catch (Throwable th) {
|
|
396 | 400 |
return defaultValue; |
397 | 401 |
} |
398 | 402 |
} |
... | ... | |
400 | 404 |
@Override |
401 | 405 |
public float getFloatOrDefault(String name, float defaultValue) { |
402 | 406 |
int index = this.data.getType().getIndex(name); |
403 |
if( index < 0 ) {
|
|
407 |
if (index < 0) {
|
|
404 | 408 |
return defaultValue; |
405 | 409 |
} |
406 | 410 |
try { |
407 | 411 |
return this.getFloat(index); |
408 |
} catch(Throwable th) { |
|
412 |
} catch (Throwable th) {
|
|
409 | 413 |
return defaultValue; |
410 | 414 |
} |
411 | 415 |
} |
... | ... | |
413 | 417 |
@Override |
414 | 418 |
public double getDoubleOrDefault(String name, double defaultValue) { |
415 | 419 |
int index = this.data.getType().getIndex(name); |
416 |
if( index < 0 ) {
|
|
420 |
if (index < 0) {
|
|
417 | 421 |
return defaultValue; |
418 | 422 |
} |
419 | 423 |
try { |
420 | 424 |
return this.getDouble(index); |
421 |
} catch(Throwable th) { |
|
425 |
} catch (Throwable th) {
|
|
422 | 426 |
return defaultValue; |
423 | 427 |
} |
424 | 428 |
} |
... | ... | |
426 | 430 |
@Override |
427 | 431 |
public BigDecimal getDecimalOrDefault(String name, BigDecimal defaultValue) { |
428 | 432 |
int index = this.data.getType().getIndex(name); |
429 |
if( index < 0 ) {
|
|
433 |
if (index < 0) {
|
|
430 | 434 |
return defaultValue; |
431 | 435 |
} |
432 | 436 |
try { |
433 | 437 |
return this.getDecimal(index); |
434 |
} catch(Throwable th) { |
|
438 |
} catch (Throwable th) {
|
|
435 | 439 |
return defaultValue; |
436 | 440 |
} |
437 | 441 |
} |
... | ... | |
439 | 443 |
@Override |
440 | 444 |
public Date getDateOrDefault(String name, Date defaultValue) { |
441 | 445 |
int index = this.data.getType().getIndex(name); |
442 |
if( index < 0 ) {
|
|
446 |
if (index < 0) {
|
|
443 | 447 |
return defaultValue; |
444 | 448 |
} |
445 | 449 |
try { |
446 | 450 |
return this.getDate(index); |
447 |
} catch(Throwable th) { |
|
451 |
} catch (Throwable th) {
|
|
448 | 452 |
return defaultValue; |
449 | 453 |
} |
450 | 454 |
} |
451 | 455 |
|
452 | 456 |
@Override |
453 | 457 |
public Object getOrDefault(int index, Object defaultValue) { |
454 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
458 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
455 | 459 |
return defaultValue; |
456 | 460 |
} |
457 | 461 |
try { |
458 | 462 |
return this.get(index); |
459 |
} catch(Throwable th) { |
|
463 |
} catch (Throwable th) {
|
|
460 | 464 |
return defaultValue; |
461 | 465 |
} |
462 | 466 |
} |
463 | 467 |
|
464 | 468 |
@Override |
465 | 469 |
public String getStringOrDefault(int index, String defaultValue) { |
466 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
470 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
467 | 471 |
return defaultValue; |
468 | 472 |
} |
469 | 473 |
try { |
470 | 474 |
return this.getString(index); |
471 |
} catch(Throwable th) { |
|
475 |
} catch (Throwable th) {
|
|
472 | 476 |
return defaultValue; |
473 | 477 |
} |
474 | 478 |
} |
475 | 479 |
|
476 | 480 |
@Override |
477 | 481 |
public boolean getBooleanOrDefault(int index, boolean defaultValue) { |
478 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
482 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
479 | 483 |
return defaultValue; |
480 | 484 |
} |
481 | 485 |
try { |
482 | 486 |
return this.getBoolean(index); |
483 |
} catch(Throwable th) { |
|
487 |
} catch (Throwable th) {
|
|
484 | 488 |
return defaultValue; |
485 | 489 |
} |
486 | 490 |
} |
487 | 491 |
|
488 |
|
|
489 | 492 |
@Override |
490 | 493 |
public int getIntOrDefault(int index, int defaultValue) { |
491 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
494 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
492 | 495 |
return defaultValue; |
493 | 496 |
} |
494 | 497 |
try { |
495 | 498 |
return this.getInt(index); |
496 |
} catch(Throwable th) { |
|
499 |
} catch (Throwable th) {
|
|
497 | 500 |
return defaultValue; |
498 | 501 |
} |
499 | 502 |
} |
500 | 503 |
|
501 | 504 |
@Override |
502 | 505 |
public long getLongOrDefault(int index, long defaultValue) { |
503 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
506 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
504 | 507 |
return defaultValue; |
505 | 508 |
} |
506 | 509 |
try { |
507 | 510 |
return this.getLong(index); |
508 |
} catch(Throwable th) { |
|
511 |
} catch (Throwable th) {
|
|
509 | 512 |
return defaultValue; |
510 | 513 |
} |
511 | 514 |
} |
512 | 515 |
|
513 | 516 |
@Override |
514 | 517 |
public float getFloatOrDefault(int index, float defaultValue) { |
515 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
518 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
516 | 519 |
return defaultValue; |
517 | 520 |
} |
518 | 521 |
try { |
519 | 522 |
return this.getFloat(index); |
520 |
} catch(Throwable th) { |
|
523 |
} catch (Throwable th) {
|
|
521 | 524 |
return defaultValue; |
522 | 525 |
} |
523 | 526 |
} |
524 | 527 |
|
525 | 528 |
@Override |
526 | 529 |
public double getDoubleOrDefault(int index, double defaultValue) { |
527 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
530 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
528 | 531 |
return defaultValue; |
529 | 532 |
} |
530 | 533 |
try { |
531 | 534 |
return this.getDouble(index); |
532 |
} catch(Throwable th) { |
|
535 |
} catch (Throwable th) {
|
|
533 | 536 |
return defaultValue; |
534 | 537 |
} |
535 | 538 |
} |
536 | 539 |
|
537 | 540 |
@Override |
538 | 541 |
public BigDecimal getDecimalOrDefault(int index, BigDecimal defaultValue) { |
539 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
542 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
540 | 543 |
return defaultValue; |
541 | 544 |
} |
542 | 545 |
try { |
543 | 546 |
return this.getDecimal(index); |
544 |
} catch(Throwable th) { |
|
547 |
} catch (Throwable th) {
|
|
545 | 548 |
return defaultValue; |
546 | 549 |
} |
547 | 550 |
} |
548 | 551 |
|
549 | 552 |
@Override |
550 | 553 |
public Date getDateOrDefault(int index, Date defaultValue) { |
551 |
if( index < 0 || index >= this.data.getType().size() ) {
|
|
554 |
if (index < 0 || index >= this.data.getType().size()) {
|
|
552 | 555 |
return defaultValue; |
553 | 556 |
} |
554 | 557 |
try { |
555 | 558 |
return this.getDate(index); |
556 |
} catch(Throwable th) { |
|
559 |
} catch (Throwable th) {
|
|
557 | 560 |
return defaultValue; |
558 | 561 |
} |
559 | 562 |
} |
... | ... | |
571 | 574 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
572 | 575 |
public UnableToGetReferenceException(BaseException exception) { |
573 | 576 |
super("Unable to get reference", "_UnableToGetReferenceException", |
574 |
serialVersionUID); |
|
577 |
serialVersionUID);
|
|
575 | 578 |
this.initCause(exception); |
576 | 579 |
|
577 | 580 |
} |
... | ... | |
579 | 582 |
} |
580 | 583 |
|
581 | 584 |
@Override |
582 |
public void validate(int mode) throws DataException {
|
|
585 |
public void validate(int mode) throws DataException { |
|
583 | 586 |
((DefaultFeatureType) this.data.getType()).validateFeature(this, mode); |
584 | 587 |
} |
585 | 588 |
|
... | ... | |
592 | 595 |
@Override |
593 | 596 |
public Envelope getDefaultEnvelope() { |
594 | 597 |
Envelope envelope = this.data.getDefaultEnvelope(); |
595 |
if( envelope == null ) {
|
|
598 |
if (envelope == null) {
|
|
596 | 599 |
int i = this.data.getType().getDefaultGeometryAttributeIndex(); |
597 |
if( i<0 ) {
|
|
600 |
if (i < 0) {
|
|
598 | 601 |
return null; |
599 | 602 |
} |
600 | 603 |
Geometry geom = this.getDefaultGeometry(); |
601 |
if( geom!=null ) {
|
|
604 |
if (geom != null) {
|
|
602 | 605 |
envelope = geom.getEnvelope(); |
603 | 606 |
} |
604 | 607 |
} |
... | ... | |
607 | 610 |
|
608 | 611 |
@Override |
609 | 612 |
public Geometry getDefaultGeometry() { |
610 |
Geometry geom = this.data.getDefaultGeometry();
|
|
611 |
if( geom == null ) {
|
|
613 |
Geometry geom = this.data.getDefaultGeometry();
|
|
614 |
if (geom == null) {
|
|
612 | 615 |
int i = this.data.getType().getDefaultGeometryAttributeIndex(); |
613 |
if( i<0 ) {
|
|
616 |
if (i < 0) {
|
|
614 | 617 |
return null; |
615 | 618 |
} |
616 | 619 |
Object x = this.get(i); |
617 |
if( x instanceof Geometry ) {
|
|
620 |
if (x instanceof Geometry) {
|
|
618 | 621 |
geom = (Geometry) x; |
619 | 622 |
} else { |
620 | 623 |
geom = this.getGeometry(i); |
621 | 624 |
} |
622 | 625 |
} |
623 |
if( geom != null ) {
|
|
624 |
if( geom.getProjection()==null ) {
|
|
626 |
if (geom != null) {
|
|
627 |
if (geom.getProjection() == null) {
|
|
625 | 628 |
FeatureType type = this.getType(); |
626 | 629 |
DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex()); |
627 | 630 |
IProjection proj = attrdesc.getSRS(this.storeRef); |
... | ... | |
649 | 652 |
@Override |
650 | 653 |
public IProjection getDefaultSRS() { |
651 | 654 |
IProjection srs = this.data.getType().getDefaultSRS(); |
652 |
if( srs == null ) {
|
|
655 |
if (srs == null) {
|
|
653 | 656 |
FeatureType type = this.getType(); |
654 | 657 |
DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex()); |
655 | 658 |
srs = attrdesc.getSRS(this.storeRef); |
... | ... | |
668 | 671 |
FeatureAttributeDescriptor descriptor = this.data.getType().getAttributeDescriptor(index); |
669 | 672 |
Object value = this.get(index); |
670 | 673 |
String profileName = descriptor.getDataProfileName(); |
671 |
if( StringUtils.isBlank(profileName) ) {
|
|
674 |
if (StringUtils.isBlank(profileName)) {
|
|
672 | 675 |
return value; |
673 | 676 |
} |
674 | 677 |
DataProfile profile = DALLocator.getDataManager().getDataProfile(profileName); |
675 |
if( profile==null ) {
|
|
678 |
if (profile == null) {
|
|
676 | 679 |
return value; |
677 | 680 |
} |
678 | 681 |
return profile.createData(value, descriptor.getTags()); |
... | ... | |
687 | 690 |
@Override |
688 | 691 |
public Object get(String name) { |
689 | 692 |
int index = this.data.getType().getIndex(name); |
690 |
if( index < 0 ) {
|
|
693 |
if (index < 0) {
|
|
691 | 694 |
// buscamos en los extra cols |
692 |
if(hasExtraColumnValue(name)) { |
|
695 |
if (hasExtraColumnValue(name)) {
|
|
693 | 696 |
return getExtraColumnValue(name); |
694 | 697 |
} |
695 | 698 |
if (hasExtraValue(name)) { |
696 | 699 |
return getExtraValue(name); |
697 | 700 |
} |
698 | 701 |
// y si esta ahi return |
699 |
throw new IllegalArgumentException("Attribute name '"+name+"' not found in the feature.");
|
|
702 |
throw new IllegalArgumentException("Attribute name '" + name + "' not found in the feature.");
|
|
700 | 703 |
} |
701 | 704 |
return this.get(index); |
702 | 705 |
} |
703 |
|
|
706 |
|
|
704 | 707 |
@Override |
705 | 708 |
public boolean isNull(int index) { |
706 | 709 |
FeatureType type = this.data.getType(); |
707 |
if( index <0 || index >= type.size() ) {
|
|
708 |
throw new IllegalArgumentException("Attribute index '"+index+"' out of range (0 to "+this.data.getType().size()+".");
|
|
710 |
if (index < 0 || index >= type.size()) {
|
|
711 |
throw new IllegalArgumentException("Attribute index '" + index + "' out of range (0 to " + this.data.getType().size() + ".");
|
|
709 | 712 |
} |
710 | 713 |
FeatureAttributeDescriptor attribute = type.getAttributeDescriptor(index); |
711 | 714 |
if (!this.data.getType().hasEvaluators()) { |
712 |
return this.data.get(index)==null;
|
|
715 |
return this.data.get(index) == null;
|
|
713 | 716 |
} |
714 | 717 |
Evaluator eval = attribute.getEvaluator(); |
715 | 718 |
if (eval == null) { |
716 |
return this.data.get(index)==null;
|
|
719 |
return this.data.get(index) == null;
|
|
717 | 720 |
} |
718 | 721 |
Object value = this.data.get(index); |
719 | 722 |
if (value != null) { |
... | ... | |
725 | 728 |
throw new DataEvaluatorRuntimeException(e); |
726 | 729 |
} |
727 | 730 |
this.data.set(index, value); |
728 |
return value==null;
|
|
731 |
return value == null;
|
|
729 | 732 |
} |
730 |
|
|
733 |
|
|
731 | 734 |
@Override |
732 | 735 |
public boolean isNull(String name) { |
733 | 736 |
int index = this.data.getType().getIndex(name); |
734 |
if( index < 0 ) {
|
|
735 |
throw new IllegalArgumentException("Attribute name '"+name+"' not found in the feature.");
|
|
737 |
if (index < 0) {
|
|
738 |
throw new IllegalArgumentException("Attribute name '" + name + "' not found in the feature.");
|
|
736 | 739 |
} |
737 | 740 |
return this.isNull(index); |
738 | 741 |
} |
... | ... | |
744 | 747 |
|
745 | 748 |
public List<String> keys() { |
746 | 749 |
List<String> ks = new ArrayList<>(); |
747 |
for( FeatureAttributeDescriptor attr : this.getType()) {
|
|
750 |
for (FeatureAttributeDescriptor attr : this.getType()) {
|
|
748 | 751 |
ks.add(attr.getName()); |
749 | 752 |
} |
750 | 753 |
return ks; |
... | ... | |
760 | 763 |
|
761 | 764 |
@Override |
762 | 765 |
public String next() { |
763 |
return ((FeatureAttributeDescriptor)it.next()).getName(); |
|
766 |
return ((FeatureAttributeDescriptor) it.next()).getName();
|
|
764 | 767 |
} |
765 | 768 |
|
766 | 769 |
@Override |
... | ... | |
780 | 783 |
|
781 | 784 |
@Override |
782 | 785 |
public Map.Entry next() { |
783 |
final String name = ((FeatureAttributeDescriptor)it.next()).getName(); |
|
786 |
final String name = ((FeatureAttributeDescriptor) it.next()).getName();
|
|
784 | 787 |
return new Map.Entry<String, Object>() { |
785 | 788 |
@Override |
786 | 789 |
public String getKey() { |
... | ... | |
810 | 813 |
@Override |
811 | 814 |
public Object get(int index) { |
812 | 815 |
FeatureType type = this.data.getType(); |
813 |
if( index <0 || index >= type.size() ) {
|
|
814 |
throw new IllegalArgumentException("Attribute index '"+index+"' out of range (0 to "+this.data.getType().size()+".");
|
|
816 |
if (index < 0 || index >= type.size()) {
|
|
817 |
throw new IllegalArgumentException("Attribute index '" + index + "' out of range (0 to " + this.data.getType().size() + ".");
|
|
815 | 818 |
} |
816 | 819 |
Object value = this.data.get(index); |
817 | 820 |
FeatureAttributeDescriptor attribute = type.getAttributeDescriptor(index); |
818 | 821 |
if (type.hasEvaluators()) { |
819 |
Evaluator eval = attribute.getEvaluator(); |
|
820 |
if (eval != null) { |
|
821 |
if (value == null) { // Ya hemos calculado el campo ? |
|
822 |
// FIXME: para comprobar si esta calculado usar un array especifico. |
|
823 |
try { |
|
824 |
value = eval.evaluate(this); |
|
825 |
} catch (EvaluatorException e) { |
|
826 |
throw new DataEvaluatorRuntimeException(e); |
|
827 |
} |
|
828 |
this.data.set(index, value); |
|
829 |
}
|
|
830 |
} |
|
822 |
Evaluator eval = attribute.getEvaluator();
|
|
823 |
if (eval != null) {
|
|
824 |
if (value == null) { // Ya hemos calculado el campo ?
|
|
825 |
// FIXME: para comprobar si esta calculado usar un array especifico.
|
|
826 |
try {
|
|
827 |
value = eval.evaluate(this);
|
|
828 |
} catch (EvaluatorException e) {
|
|
829 |
throw new DataEvaluatorRuntimeException(e);
|
|
830 |
}
|
|
831 |
this.data.set(index, value);
|
|
832 |
}
|
|
833 |
}
|
|
831 | 834 |
} |
832 | 835 |
value = get(attribute, value); |
833 |
return value;
|
|
836 |
return value; |
|
834 | 837 |
} |
835 | 838 |
|
836 |
private Object get(FeatureAttributeDescriptor featureAttributeDescriptor, Object value){ |
|
839 |
private Object get(FeatureAttributeDescriptor featureAttributeDescriptor, Object value) {
|
|
837 | 840 |
FeatureAttributeEmulator emulator = featureAttributeDescriptor.getFeatureAttributeEmulator(); |
838 |
if( emulator != null ) {
|
|
841 |
if (emulator != null) {
|
|
839 | 842 |
// int index = featureAttributeDescriptor.getIndex(); |
840 | 843 |
// value = this.data.get(index); |
841 | 844 |
// if( value==null ) { |
842 |
value = emulator.get(this);
|
|
845 |
value = emulator.get(this); |
|
843 | 846 |
// this.data.set(index,value); |
844 | 847 |
// } |
845 | 848 |
} else { |
846 | 849 |
FeatureAttributeGetter getter = featureAttributeDescriptor.getFeatureAttributeGetter(); |
847 |
if( getter != null ) {
|
|
850 |
if (getter != null) {
|
|
848 | 851 |
value = getter.getter(value); |
849 | 852 |
} |
850 | 853 |
} |
851 | 854 |
DataType dataType = featureAttributeDescriptor.getDataType(); |
852 | 855 |
Class<? extends DataType> theClass = dataType.getDefaultClass(); |
853 |
if( theClass!=null && !theClass.isInstance(value) ) {
|
|
856 |
if (theClass != null && !theClass.isInstance(value)) {
|
|
854 | 857 |
try { |
855 | 858 |
value = this.getDataTypesManager().coerce(dataType.getType(), value); |
856 | 859 |
} catch (CoercionException e) { |
857 |
throw new IllegalArgumentException(
|
|
858 |
"Can't convert to "+theClass.getSimpleName()+
|
|
859 |
" from '"+value.getClass().getSimpleName()+
|
|
860 |
"' with value '"+value.toString()+"'.");
|
|
860 |
throw new IllegalArgumentException( |
|
861 |
"Can't convert to " + theClass.getSimpleName()
|
|
862 |
+ " from '" + value.getClass().getSimpleName()
|
|
863 |
+ "' with value '" + value.toString() + "'.");
|
|
861 | 864 |
} |
862 | 865 |
} |
863 |
if( featureAttributeDescriptor.getType()==DataTypes.GEOMETRY ) {
|
|
864 |
if( value != null ) {
|
|
865 |
Geometry geom = (Geometry)value; |
|
866 |
if( geom.getProjection()==null ) {
|
|
867 |
IProjection proj = ((DefaultFeatureAttributeDescriptor)featureAttributeDescriptor).getSRS(this.storeRef); |
|
866 |
if (featureAttributeDescriptor.getType() == DataTypes.GEOMETRY) {
|
|
867 |
if (value != null) {
|
|
868 |
Geometry geom = (Geometry) value;
|
|
869 |
if (geom.getProjection() == null) {
|
|
870 |
IProjection proj = ((DefaultFeatureAttributeDescriptor) featureAttributeDescriptor).getSRS(this.storeRef);
|
|
868 | 871 |
geom.setProjection(proj); |
869 | 872 |
} |
870 | 873 |
} |
... | ... | |
899 | 902 |
|
900 | 903 |
@Override |
901 | 904 |
public boolean getBoolean(int index) { |
902 |
Boolean value = ((Boolean) this.get(index,Boolean.class,DataTypes.BOOLEAN));
|
|
905 |
Boolean value = ((Boolean) this.get(index, Boolean.class, DataTypes.BOOLEAN));
|
|
903 | 906 |
if (value == null) { |
904 | 907 |
return false; |
905 | 908 |
} |
... | ... | |
913 | 916 |
|
914 | 917 |
@Override |
915 | 918 |
public byte getByte(int index) { |
916 |
Byte value = ((Byte) this.get(index,Byte.class,DataTypes.BYTE));
|
|
919 |
Byte value = ((Byte) this.get(index, Byte.class, DataTypes.BYTE));
|
|
917 | 920 |
if (value == null) { |
918 | 921 |
return 0; |
919 | 922 |
} |
... | ... | |
927 | 930 |
|
928 | 931 |
@Override |
929 | 932 |
public java.sql.Date getDate(int index) { |
930 |
java.sql.Date value = ((java.sql.Date) this.get(index,java.sql.Date.class,DataTypes.DATE));
|
|
933 |
java.sql.Date value = ((java.sql.Date) this.get(index, java.sql.Date.class, DataTypes.DATE));
|
|
931 | 934 |
return value; |
932 | 935 |
} |
933 | 936 |
|
... | ... | |
938 | 941 |
|
939 | 942 |
@Override |
940 | 943 |
public java.sql.Time getTime(int index) { |
941 |
java.sql.Time value = ((java.sql.Time) this.get(index,java.sql.Time.class,DataTypes.TIME));
|
|
944 |
java.sql.Time value = ((java.sql.Time) this.get(index, java.sql.Time.class, DataTypes.TIME));
|
|
942 | 945 |
return value; |
943 | 946 |
} |
944 | 947 |
|
... | ... | |
949 | 952 |
|
950 | 953 |
@Override |
951 | 954 |
public java.sql.Timestamp getTimestamp(int index) { |
952 |
java.sql.Timestamp value = ((java.sql.Timestamp) this.get(index,java.sql.Timestamp.class,DataTypes.TIMESTAMP));
|
|
955 |
java.sql.Timestamp value = ((java.sql.Timestamp) this.get(index, java.sql.Timestamp.class, DataTypes.TIMESTAMP));
|
|
953 | 956 |
return value; |
954 | 957 |
} |
955 | 958 |
|
... | ... | |
961 | 964 |
@Override |
962 | 965 |
public double getDouble(int index) { |
963 | 966 |
|
964 |
Double value = ((Double) this.get(index,Double.class,DataTypes.DOUBLE));
|
|
967 |
Double value = ((Double) this.get(index, Double.class, DataTypes.DOUBLE));
|
|
965 | 968 |
if (value == null) { |
966 | 969 |
return 0; |
967 | 970 |
} |
... | ... | |
975 | 978 |
|
976 | 979 |
@Override |
977 | 980 |
public BigDecimal getDecimal(int index) { |
978 |
BigDecimal value = ((BigDecimal) this.get(index,BigDecimal.class,DataTypes.DECIMAL));
|
|
981 |
BigDecimal value = ((BigDecimal) this.get(index, BigDecimal.class, DataTypes.DECIMAL));
|
|
979 | 982 |
return value; |
980 | 983 |
} |
981 | 984 |
|
... | ... | |
996 | 999 |
|
997 | 1000 |
@Override |
998 | 1001 |
public float getFloat(int index) { |
999 |
Float value = ((Float) this.get(index,Float.class,DataTypes.FLOAT));
|
|
1002 |
Float value = ((Float) this.get(index, Float.class, DataTypes.FLOAT));
|
|
1000 | 1003 |
if (value == null) { |
1001 | 1004 |
return 0; |
1002 | 1005 |
} |
... | ... | |
1010 | 1013 |
|
1011 | 1014 |
@Override |
1012 | 1015 |
public Geometry getGeometry(int index) { |
1013 |
return (Geometry) this.get(index,Geometry.class,DataTypes.GEOMETRY);
|
|
1016 |
return (Geometry) this.get(index, Geometry.class, DataTypes.GEOMETRY);
|
|
1014 | 1017 |
} |
1015 | 1018 |
|
1016 | 1019 |
@Override |
... | ... | |
1020 | 1023 |
|
1021 | 1024 |
@Override |
1022 | 1025 |
public int getInt(int index) { |
1023 |
Integer value = ((Integer) this.get(index,Integer.class,DataTypes.INT));
|
|
1026 |
Integer value = ((Integer) this.get(index, Integer.class, DataTypes.INT));
|
|
1024 | 1027 |
if (value == null) { |
1025 | 1028 |
return 0; |
1026 | 1029 |
} |
... | ... | |
1034 | 1037 |
|
1035 | 1038 |
@Override |
1036 | 1039 |
public long getLong(int index) { |
1037 |
Long value = ((Long) this.get(index,Long.class,DataTypes.LONG));
|
|
1040 |
Long value = ((Long) this.get(index, Long.class, DataTypes.LONG));
|
|
1038 | 1041 |
if (value == null) { |
1039 | 1042 |
return 0; |
1040 | 1043 |
} |
... | ... | |
1048 | 1051 |
|
1049 | 1052 |
@Override |
1050 | 1053 |
public String getString(int index) { |
1051 |
return (String) this.get(index,String.class,DataTypes.STRING);
|
|
1054 |
return (String) this.get(index, String.class, DataTypes.STRING);
|
|
1052 | 1055 |
} |
1053 | 1056 |
|
1054 | 1057 |
@Override |
... | ... | |
1072 | 1075 |
@Override |
1073 | 1076 |
public Iterator getDataNames() { |
1074 | 1077 |
class DataNamesIterator implements Iterator { |
1078 |
|
|
1075 | 1079 |
Iterator attributeIteraror; |
1076 | 1080 |
|
1077 | 1081 |
DataNamesIterator(DefaultFeature feature) { |
... | ... | |
1104 | 1108 |
try { |
1105 | 1109 |
return get(name); |
1106 | 1110 |
} catch (IllegalArgumentException ex) { |
1107 |
if( "defaultgeometry".equalsIgnoreCase(name )) {
|
|
1111 |
if ("defaultgeometry".equalsIgnoreCase(name)) {
|
|
1108 | 1112 |
return this.getDefaultGeometry(); |
1109 | 1113 |
} |
1110 | 1114 |
throw ex; |
... | ... | |
1114 | 1118 |
@Override |
1115 | 1119 |
public Iterator getDataValues() { |
1116 | 1120 |
class DataValuesIterator implements Iterator { |
1121 |
|
|
1117 | 1122 |
DefaultFeature feature; |
1118 | 1123 |
int current = 0; |
1119 | 1124 |
|
... | ... | |
1197 | 1202 |
|
1198 | 1203 |
@Override |
1199 | 1204 |
public String toString() { |
1200 |
StringBuilder builder = new StringBuilder();
|
|
1201 |
FeatureAttributeDescriptor[] attributeDescriptors =
|
|
1202 |
getType().getAttributeDescriptors(); |
|
1205 |
StringBuilder builder = new StringBuilder();
|
|
1206 |
FeatureAttributeDescriptor[] attributeDescriptors |
|
1207 |
= getType().getAttributeDescriptors();
|
|
1203 | 1208 |
for (int i = 0; i < attributeDescriptors.length; i++) { |
1204 | 1209 |
String name = attributeDescriptors[i].getName(); |
1205 | 1210 |
Object value = get(name); |
... | ... | |
1211 | 1216 |
return builder.toString(); |
1212 | 1217 |
} |
1213 | 1218 |
|
1214 |
|
|
1215 |
|
|
1216 |
|
|
1217 |
/** |
|
1219 |
/** |
|
1218 | 1220 |
* @return the inserted |
1219 | 1221 |
*/ |
1220 | 1222 |
public boolean isInserted() { |
1221 | 1223 |
return inserted; |
1222 | 1224 |
} |
1223 | 1225 |
|
1224 |
|
|
1225 | 1226 |
/** |
1226 | 1227 |
* @param inserted the inserted to set |
1227 | 1228 |
*/ |
... | ... | |
1229 | 1230 |
this.inserted = inserted; |
1230 | 1231 |
} |
1231 | 1232 |
|
1232 |
@Override
|
|
1233 |
@Override |
|
1233 | 1234 |
public EvaluatorData getEvaluatorData() { |
1234 | 1235 |
return this; |
1235 | 1236 |
} |
... | ... | |
1238 | 1239 |
public int size() { |
1239 | 1240 |
return this.data.getType().size(); |
1240 | 1241 |
} |
1241 |
|
|
1242 |
|
|
1242 | 1243 |
public boolean isEmpty() { |
1243 | 1244 |
return false; |
1244 | 1245 |
} |
... | ... | |
1257 | 1258 |
} |
1258 | 1259 |
}; |
1259 | 1260 |
} |
1260 |
|
|
1261 |
|
|
1261 | 1262 |
public boolean containsKey(String key) { |
1262 |
return this.data.getType().get(key)!=null;
|
|
1263 |
return this.data.getType().get(key) != null;
|
|
1263 | 1264 |
} |
1264 | 1265 |
|
1265 | 1266 |
@Override |
1266 | 1267 |
public String getLabelOfValue(String name) { |
1267 | 1268 |
FeatureAttributeDescriptor attrdesc = this.data.getType().getAttributeDescriptor(name); |
1268 |
if( attrdesc==null ) {
|
|
1269 |
throw new IllegalArgumentException("Attribute name '"+name+"' not found in the feature.");
|
|
1269 |
if (attrdesc == null) {
|
|
1270 |
throw new IllegalArgumentException("Attribute name '" + name + "' not found in the feature.");
|
|
1270 | 1271 |
} |
1271 | 1272 |
Object value = this.get(attrdesc.getIndex()); |
1272 | 1273 |
String label = attrdesc.getLabelOfValue(value); |
1273 | 1274 |
return label; |
1274 | 1275 |
} |
1275 |
|
|
1276 |
|
|
1276 | 1277 |
@Override |
1277 | 1278 |
public void setExtraValue(String name, Object value) { |
1278 |
if( this.extraValues==null ) {
|
|
1279 |
this.extraValues = new HashMap<>(); |
|
1280 |
} |
|
1281 |
this.extraValues.put(name, value); |
|
1279 |
if (this.extraValues == null) {
|
|
1280 |
this.extraValues = new HashMap<>();
|
|
1281 |
}
|
|
1282 |
this.extraValues.put(name, value);
|
|
1282 | 1283 |
} |
1283 |
|
|
1284 |
|
|
1284 | 1285 |
public Object getExtraColumnValue(String name) { |
1285 | 1286 |
Object value; |
1286 | 1287 |
if (this.extraValues != null) { |
... | ... | |
1298 | 1299 |
} |
1299 | 1300 |
EditableFeatureAttributeDescriptor attrdesc = columns.get(index); |
1300 | 1301 |
value = extraValuesData[index]; |
1301 |
if (value!=null) {
|
|
1302 |
if (value != null) {
|
|
1302 | 1303 |
return value; |
1303 | 1304 |
} |
1304 | 1305 |
value = this.getExtraValue(name); |
1305 | 1306 |
extraValuesData[index] = value; |
1306 | 1307 |
if (value == null && !this.hasExtraValue(name)) { |
1307 |
if (attrdesc.getFeatureAttributeEmulator()!=null) {
|
|
1308 |
if (attrdesc.getFeatureAttributeEmulator() != null) {
|
|
1308 | 1309 |
value = attrdesc.getFeatureAttributeEmulator().get(this); |
1309 | 1310 |
extraValuesData[index] = value; |
1310 | 1311 |
} |
... | ... | |
1317 | 1318 |
Object value = this.data.getExtraValue(name); |
1318 | 1319 |
return value; |
1319 | 1320 |
} |
1320 |
|
|
1321 |
|
|
1321 | 1322 |
@Override |
1322 | 1323 |
public boolean hasExtraValue(String name) { |
1323 | 1324 |
return this.data.hasExtraValue(name); |
1324 | 1325 |
} |
1325 |
|
|
1326 | 1326 |
|
1327 | 1327 |
private boolean hasExtraColumnValue(String name) { |
1328 |
if( this.extraValues!=null ) {
|
|
1329 |
if( this.extraValues.containsKey(name) ) {
|
|
1330 |
return true; |
|
1331 |
} |
|
1328 |
if (this.extraValues != null) {
|
|
1329 |
if (this.extraValues.containsKey(name)) {
|
|
1330 |
return true;
|
|
1331 |
}
|
|
1332 | 1332 |
} |
1333 | 1333 |
FeatureExtraColumns columns = this.getType().getExtraColumns(); |
1334 | 1334 |
int index = columns.getIndexOf(name); |
1335 |
if( index >= 0 ) {
|
|
1336 |
return true; |
|
1335 |
if (index >= 0) {
|
|
1336 |
return true;
|
|
1337 | 1337 |
} |
1338 | 1338 |
return false; |
1339 | 1339 |
} |
1340 |
|
|
1340 |
|
|
1341 | 1341 |
@Override |
1342 | 1342 |
public boolean hasValue(String name) { |
1343 | 1343 |
name = name.toLowerCase(); |
1344 |
return this.data.getType().getIndex(name) >= 0 ||
|
|
1345 |
hasExtraValue(name) ||
|
|
1346 |
hasExtraColumnValue(name); |
|
1344 |
return this.data.getType().getIndex(name) >= 0 |
|
1345 |
|| hasExtraValue(name)
|
|
1346 |
|| hasExtraColumnValue(name);
|
|
1347 | 1347 |
} |
1348 |
|
|
1348 |
|
|
1349 | 1349 |
@Override |
1350 | 1350 |
public Object getExtraValue(int index) { |
1351 | 1351 |
return this.data.getExtraValue(index); |
... | ... | |
1356 | 1356 |
JsonObjectBuilder builder = this.toJsonBuilder(); |
1357 | 1357 |
return builder.build(); |
1358 | 1358 |
} |
1359 |
|
|
1359 |
|
|
1360 | 1360 |
@Override |
1361 | 1361 |
public JsonObjectBuilder toJsonBuilder() { |
1362 | 1362 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
... | ... | |
1367 | 1367 |
if (desc.isComputed()) { |
1368 | 1368 |
continue; |
1369 | 1369 |
} |
1370 |
switch(desc.getType()) { |
|
1370 |
switch (desc.getType()) {
|
|
1371 | 1371 |
case DataTypes.GEOMETRY: |
1372 | 1372 |
geom = this.getGeometry(desc.getIndex()); |
1373 |
if( geom!=null ) {
|
|
1373 |
if (geom != null) {
|
|
1374 | 1374 |
builder.add(desc.getName(), geom.convertToHexWKBQuietly()); |
1375 | 1375 |
} |
1376 | 1376 |
break; |
... | ... | |
1395 | 1395 |
case DataTypes.DATE: |
1396 | 1396 |
// Format date as ISO 8601 |
1397 | 1397 |
date = this.getDate(desc.getIndex()); |
1398 |
if( date==null ) {
|
|
1398 |
if (date == null) {
|
|
1399 | 1399 |
builder.addNull(desc.getName()); |
1400 | 1400 |
} else { |
1401 | 1401 |
LocalDateTime localDateTime = LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()); |
... | ... | |
1406 | 1406 |
case DataTypes.TIMESTAMP: |
1407 | 1407 |
// Format date as ISO 8601 |
1408 | 1408 |
date = this.getTimestamp(desc.getIndex()); |
1409 |
if( date==null ) {
|
|
1409 |
if (date == null) {
|
|
1410 | 1410 |
builder.addNull(desc.getName()); |
1411 | 1411 |
} else { |
1412 | 1412 |
LocalDateTime localDateTime = LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()); |
... | ... | |
1417 | 1417 |
case DataTypes.TIME: |
1418 | 1418 |
// Format date as ISO 8601 |
1419 | 1419 |
date = this.getTime(desc.getIndex()); |
1420 |
if( date==null ) {
|
|
1420 |
if (date == null) {
|
|
1421 | 1421 |
builder.addNull(desc.getName()); |
1422 | 1422 |
} else { |
1423 | 1423 |
LocalDateTime localDateTime = LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()); |
... | ... | |
1426 | 1426 |
} |
1427 | 1427 |
break; |
1428 | 1428 |
default: |
1429 |
builder.add(desc.getName(), Objects.toString(this.get(desc.getIndex()),""));
|
|
1429 |
builder.add(desc.getName(), this.getStringOrDefault(desc.getIndex(), ""));
|
|
1430 | 1430 |
} |
1431 |
}
|
|
1431 |
} |
|
1432 | 1432 |
return builder; |
1433 | 1433 |
} |
1434 | 1434 |
|
1435 | 1435 |
@Override |
1436 | 1436 |
public List<String> getKeys() { |
1437 |
List<String> l = new ArrayList<>(); |
|
1438 |
for (FeatureAttributeDescriptor descriptor : this.getType()) { |
|
1439 |
l.add(descriptor.getName()); |
|
1440 |
} |
|
1441 |
return l; |
|
1437 |
List<String> l = new ArrayList<>();
|
|
1438 |
for (FeatureAttributeDescriptor descriptor : this.getType()) {
|
|
1439 |
l.add(descriptor.getName());
|
|
1440 |
}
|
|
1441 |
return l;
|
|
1442 | 1442 |
} |
1443 | 1443 |
|
1444 | 1444 |
} |
Also available in: Unified diff