Revision 45041 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractFunction.java
AbstractFunction.java | ||
---|---|---|
14 | 14 |
import java.util.List; |
15 | 15 |
import java.util.Locale; |
16 | 16 |
import java.util.Objects; |
17 |
import javax.json.JsonArray; |
|
18 |
import javax.json.JsonObject; |
|
19 |
import javax.json.JsonStructure; |
|
17 | 20 |
import org.apache.commons.io.IOUtils; |
18 | 21 |
import org.apache.commons.lang3.BooleanUtils; |
19 | 22 |
import org.apache.commons.lang3.Range; |
... | ... | |
111 | 114 |
return descriptionArgs; |
112 | 115 |
} |
113 | 116 |
|
117 |
@Override |
|
114 | 118 |
public String getFullDescription() { |
115 | 119 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
116 | 120 |
|
... | ... | |
335 | 339 |
File f = new File(s); |
336 | 340 |
return f; |
337 | 341 |
} |
342 |
|
|
343 |
protected boolean isNull(Object args[], int n) { |
|
344 |
return getObject(args, n)==null; |
|
345 |
} |
|
338 | 346 |
|
339 | 347 |
protected Object getObject(Object args[], int n) { |
340 | 348 |
if( args.length < n ) { |
... | ... | |
343 | 351 |
return args[n]; |
344 | 352 |
} |
345 | 353 |
|
354 |
protected JsonObject getJsonObject(Object args[], int n) { |
|
355 |
if( args.length < n ) { |
|
356 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
357 |
} |
|
358 |
return getJsonObject(args[n],n); |
|
359 |
} |
|
360 |
|
|
361 |
protected JsonObject getJsonObject(Object value, int n) { |
|
362 |
if( value == null ) { |
|
363 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
|
364 |
} |
|
365 |
if( !(value instanceof JSONObject) ) { |
|
366 |
try { |
|
367 |
value = JsonUtils.toJsonObject(value); |
|
368 |
} catch(Throwable th) { |
|
369 |
String type = value.getClass().getCanonicalName(); |
|
370 |
throw new IllegalArgumentException( |
|
371 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
372 |
I18N.Expected_XexpectedX_and_found_XfoundX("JsonObject",type), |
|
373 |
th |
|
374 |
); |
|
375 |
} |
|
376 |
} |
|
377 |
return (JsonObject) value; |
|
378 |
} |
|
379 |
|
|
380 |
protected JsonArray getJsonArray(Object args[], int n) { |
|
381 |
if( args.length < n ) { |
|
382 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
383 |
} |
|
384 |
return getJsonArray(args[n],n); |
|
385 |
} |
|
386 |
|
|
387 |
protected JsonArray getJsonArray(Object value, int n) { |
|
388 |
if( value == null ) { |
|
389 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
|
390 |
} |
|
391 |
if( !(value instanceof JsonArray) ) { |
|
392 |
try { |
|
393 |
value = JsonUtils.toJsonArray(value); |
|
394 |
} catch(Throwable th) { |
|
395 |
String type = value.getClass().getCanonicalName(); |
|
396 |
throw new IllegalArgumentException( |
|
397 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
398 |
I18N.Expected_XexpectedX_and_found_XfoundX("JsonObject",type), |
|
399 |
th |
|
400 |
); |
|
401 |
} |
|
402 |
} |
|
403 |
return (JsonArray) value; |
|
404 |
} |
|
405 |
|
|
406 |
protected JsonStructure getJsonStructure(Object args[], int n) { |
|
407 |
if( args.length < n ) { |
|
408 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
409 |
} |
|
410 |
return getJsonStructure(args[n],n); |
|
411 |
} |
|
412 |
|
|
413 |
protected JsonStructure getJsonStructure(Object value, int n) { |
|
414 |
if( value == null ) { |
|
415 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
|
416 |
} |
|
417 |
if( !(value instanceof JsonStructure) ) { |
|
418 |
try { |
|
419 |
value = JsonUtils.toJson(value); |
|
420 |
} catch(Throwable th) { |
|
421 |
String type = value.getClass().getCanonicalName(); |
|
422 |
throw new IllegalArgumentException( |
|
423 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
424 |
I18N.Expected_XexpectedX_and_found_XfoundX("JsonObject",type), |
|
425 |
th |
|
426 |
); |
|
427 |
} |
|
428 |
} |
|
429 |
return (JsonStructure) value; |
|
430 |
} |
|
431 |
|
|
346 | 432 |
protected Object getObject(Interpreter interpreter, Codes args, int n) { |
347 | 433 |
if( args.size() < n ) { |
348 | 434 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.size(), n)); |
... | ... | |
613 | 699 |
} |
614 | 700 |
} |
615 | 701 |
} |
616 |
protected static final int TYPE_INT = 0b0000001; |
|
617 |
protected static final int TYPE_LONG = 0b0000010; |
|
618 |
protected static final int TYPE_FLOAT = 0b0000100; |
|
619 |
protected static final int TYPE_DOUBLE = 0b0001000; |
|
620 |
protected static final int TYPE_BOOLEAN = 0b0010000; |
|
621 |
protected static final int TYPE_STRING = 0b0100000; |
|
622 |
protected static final int TYPE_DATE = 0b1000000; |
|
702 |
protected static final int TYPE_INT = 0b00000001; |
|
703 |
protected static final int TYPE_LONG = 0b00000010; |
|
704 |
protected static final int TYPE_FLOAT = 0b00000100; |
|
705 |
protected static final int TYPE_DOUBLE = 0b00001000; |
|
706 |
protected static final int TYPE_BOOLEAN = 0b00010000; |
|
707 |
protected static final int TYPE_STRING = 0b00100000; |
|
708 |
protected static final int TYPE_DATE = 0b01000000; |
|
709 |
protected static final int TYPE_NULL = 0b10000000; |
|
623 | 710 |
|
624 | 711 |
protected int getType(Object op1, Object op2) { |
625 | 712 |
int r = 0; |
626 |
if( op1 instanceof Double ) { |
|
713 |
if( op1 == null ) { |
|
714 |
r |= TYPE_NULL; |
|
715 |
} else if( op1 instanceof Double ) { |
|
627 | 716 |
r |= TYPE_DOUBLE; |
628 | 717 |
} else if( op1 instanceof Float ) { |
629 | 718 |
r |= TYPE_FLOAT; |
... | ... | |
638 | 727 |
} else if( op1 instanceof Date ) { |
639 | 728 |
r |= TYPE_DATE; |
640 | 729 |
} |
641 |
if( op2 instanceof Double ) { |
|
730 |
if( op2 == null ) { |
|
731 |
r |= TYPE_NULL; |
|
732 |
} else if( op2 instanceof Double ) { |
|
642 | 733 |
r |= TYPE_DOUBLE; |
643 | 734 |
} else if( op2 instanceof Float ) { |
644 | 735 |
r |= TYPE_FLOAT; |
Also available in: Unified diff