Package org.zkoss.zel.impl.lang
Class ELSupport
java.lang.Object
org.zkoss.zel.impl.lang.ELSupport
- Direct Known Subclasses:
SimpleNode
A helper class that implements the EL Specification
- Author:
- Jacob Hookom [jacob@hookom.net]
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final booleanEL 2.2 by spec. should coerce "null" value to 0 number, 0 character, "" String, false boolean.protected static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final BooleancoerceToBoolean(Object obj, boolean primitive) Convert an object to Boolean.static final DatecoerceToDateTime(Object obj, Class type) Coerce an object to an instance of java.util.Datestatic final Enum<?>coerceToEnum(Object obj, Class type) protected static final NumbercoerceToNumber(Number number, Class<?> type) static final NumbercoerceToNumber(Object obj, Class<?> type) protected static final NumbercoerceToNumber(String val, Class<?> type) static final StringcoerceToString(Object obj) Coerce an object to a string.static final ObjectcoerceToType(Object obj, Class<?> type) protected static final ObjectcoerceToTypeForSetValue(Object obj, Class<?> type) static final intCompare two objects, after coercing to the same type if appropriate.static final booleanCompare two objects for equality, after coercing to the same type if appropriate.static final booleanisBigDecimalOp(Object obj0, Object obj1) static final booleanisBigIntegerOp(Object obj0, Object obj1) static final booleanisDateTimeType(Class<?> type) static final booleanisDoubleOp(Object obj0, Object obj1) static final booleanstatic final booleanisStringFloat(String str)
-
Field Details
-
COERCE_NULL_TO_NULL
protected static final boolean COERCE_NULL_TO_NULLEL 2.2 by spec. should coerce "null" value to 0 number, 0 character, "" String, false boolean. This spec. makes it impossible to store null state into java lang object when doing setValue() and can set unexpected coerced value into java lang object. So we provide a system property "org.zkoss.zel.impl.parser.COERCE_NULL_TO_NULL" to switch this behavior when doing setValue(). By default we will set org.zkoss.zel.impl.parser.COERCE_NULL_TO_NULL to true to allow set null value though this is not compliant to the EL 2.2 spec. Shall you need to make ZEL to follow EL 2.2 spec. when doing setValue, please set "org.zkoss.zel.impl.parser.COERCE_NULL_TO_NULL" system property to false. Ref. https://services.brics.dk/java/courseadmin/SWP2011/documents/getDocument/expression_language-2_2-mrel-spec.pdf?d=41976 -
COERCE_TO_ZERO
protected static final boolean COERCE_TO_ZERO
-
-
Constructor Details
-
ELSupport
public ELSupport()
-
-
Method Details
-
compare
Compare two objects, after coercing to the same type if appropriate. If the objects are identical, or they are equal according toequals(Object, Object)then return 0. If either object is a BigDecimal, then coerce both to BigDecimal first. Similarly for Double(Float), BigInteger, and Long(Integer, Char, Short, Byte). Otherwise, check that the first object is an instance of Comparable, and compare against the second object. If that is null, return 1, otherwise return the result of comparing against the second object. Similarly, if the second object is Comparable, if the first is null, return -1, else return the result of comparing against the first object. A null object is considered as:- ZERO when compared with Numbers
- the empty string for String compares
- Otherwise null is considered to be lower than anything else.
- Parameters:
obj0- first objectobj1- second object- Returns:
- -1, 0, or 1 if this object is less than, equal to, or greater than val.
- Throws:
ELException- if neither object is ComparableClassCastException- if the objects are not mutually comparable
-
equals
Compare two objects for equality, after coercing to the same type if appropriate. If the objects are identical (including both null) return true. If either object is null, return false. If either object is Boolean, coerce both to Boolean and check equality. Similarly for Enum, String, BigDecimal, Double(Float), Long(Integer, Short, Byte, Character) Otherwise default to using Object.equals().- Parameters:
obj0- the first objectobj1- the second object- Returns:
- true if the objects are equal
- Throws:
ELException- if one of the coercion fails
-
coerceToEnum
-
coerceToBoolean
Convert an object to Boolean. Null and empty string are false.- Parameters:
obj- the object to convertprimitive- is the target a primitive in which case coercion to null is not permitted- Returns:
- the Boolean value of the object
- Throws:
ELException- if object is not Boolean or String
-
coerceToNumber
- Throws:
ELException
-
coerceToNumber
- Throws:
ELException
-
coerceToNumber
- Throws:
ELException
-
coerceToString
Coerce an object to a string.- Parameters:
obj- the object to convert- Returns:
- the String value of the object
-
coerceToTypeForSetValue
- Throws:
ELException
-
coerceToType
- Throws:
ELException
-
isBigDecimalOp
-
isBigIntegerOp
-
isDoubleOp
-
isLongOp
-
isStringFloat
-
isDateTimeType
-
coerceToDateTime
Coerce an object to an instance of java.util.Date- Parameters:
obj- the object to be converted; must be an instance of java.util.Date or a number which represents the millisecond since "the epoch" base time, namely January 1, 1970, 00:00:00 GMT.type- the class type which shall be a kind of java.util.Date; e.g. java.sql.Date, java.sql.Time, java.sql.Timestamp- Returns:
- the instance as requested by the specified type
- Throws:
ELException
-