org.zkoss.zel.impl.lang
Class ELSupport

java.lang.Object
  extended by org.zkoss.zel.impl.lang.ELSupport
Direct Known Subclasses:
SimpleNode

public class ELSupport
extends java.lang.Object

A helper class that implements the EL Specification

Version:
$Id: ELSupport.java 1050680 2010-12-18 17:26:52Z markt $
Author:
Jacob Hookom [[email protected]]

Field Summary
protected static boolean COERCE_NULL_TO_NULL
          EL 2.2 by spec. should coerce "null" value to 0 number, 0 character, "" String, false boolean.
 
Constructor Summary
ELSupport()
           
 
Method Summary
static java.lang.Boolean coerceToBoolean(java.lang.Object obj)
          Convert an object to Boolean.
static java.lang.Character coerceToCharacter(java.lang.Object obj)
           
static java.util.Date coerceToDateTime(java.lang.Object obj, java.lang.Class type)
          Coerce an object to an instance of java.util.Date
static java.lang.Enum<?> coerceToEnum(java.lang.Object obj, java.lang.Class type)
           
protected static java.lang.Number coerceToNumber(java.lang.Number number, java.lang.Class<?> type)
           
static java.lang.Number coerceToNumber(java.lang.Object obj, java.lang.Class<?> type)
           
protected static java.lang.Number coerceToNumber(java.lang.String val, java.lang.Class<?> type)
           
static java.lang.String coerceToString(java.lang.Object obj)
          Coerce an object to a string
static java.lang.Object coerceToType(java.lang.Object obj, java.lang.Class<?> type)
           
protected static java.lang.Object coerceToTypeForSetValue(java.lang.Object obj, java.lang.Class<?> type)
           
static int compare(java.lang.Object obj0, java.lang.Object obj1)
          Compare two objects, after coercing to the same type if appropriate.
static boolean equals(java.lang.Object obj0, java.lang.Object obj1)
          Compare two objects for equality, after coercing to the same type if appropriate.
static boolean isBigDecimalOp(java.lang.Object obj0, java.lang.Object obj1)
           
static boolean isBigIntegerOp(java.lang.Object obj0, java.lang.Object obj1)
           
static boolean isDateTimeType(java.lang.Class<?> type)
           
static boolean isDoubleOp(java.lang.Object obj0, java.lang.Object obj1)
           
static boolean isLongOp(java.lang.Object obj0, java.lang.Object obj1)
           
static boolean isStringFloat(java.lang.String str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COERCE_NULL_TO_NULL

protected static final boolean COERCE_NULL_TO_NULL
EL 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

Constructor Detail

ELSupport

public ELSupport()
Method Detail

compare

public static final int compare(java.lang.Object obj0,
                                java.lang.Object obj1)
                         throws ELException
Compare two objects, after coercing to the same type if appropriate. If the objects are identical, or they are equal according to equals(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:

Parameters:
obj0 - first object
obj1 - 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 Comparable
java.lang.ClassCastException - if the objects are not mutually comparable

equals

public static final boolean equals(java.lang.Object obj0,
                                   java.lang.Object obj1)
                            throws ELException
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 object
obj1 - the second object
Returns:
true if the objects are equal
Throws:
ELException

coerceToEnum

public static final java.lang.Enum<?> coerceToEnum(java.lang.Object obj,
                                                   java.lang.Class type)

coerceToBoolean

public static final java.lang.Boolean coerceToBoolean(java.lang.Object obj)
                                               throws ELException
Convert an object to Boolean. Null and empty string are false.

Parameters:
obj - the object to convert
Returns:
the Boolean value of the object
Throws:
ELException - if object is not Boolean or String

coerceToCharacter

public static final java.lang.Character coerceToCharacter(java.lang.Object obj)
                                                   throws ELException
Throws:
ELException

coerceToNumber

protected static final java.lang.Number coerceToNumber(java.lang.Number number,
                                                       java.lang.Class<?> type)
                                                throws ELException
Throws:
ELException

coerceToNumber

public static final java.lang.Number coerceToNumber(java.lang.Object obj,
                                                    java.lang.Class<?> type)
                                             throws ELException
Throws:
ELException

coerceToNumber

protected static final java.lang.Number coerceToNumber(java.lang.String val,
                                                       java.lang.Class<?> type)
                                                throws ELException
Throws:
ELException

coerceToString

public static final java.lang.String coerceToString(java.lang.Object obj)
Coerce an object to a string

Parameters:
obj -
Returns:
the String value of the object

coerceToTypeForSetValue

protected static final java.lang.Object coerceToTypeForSetValue(java.lang.Object obj,
                                                                java.lang.Class<?> type)
                                                         throws ELException
Throws:
ELException

coerceToType

public static final java.lang.Object coerceToType(java.lang.Object obj,
                                                  java.lang.Class<?> type)
                                           throws ELException
Throws:
ELException

isBigDecimalOp

public static final boolean isBigDecimalOp(java.lang.Object obj0,
                                           java.lang.Object obj1)

isBigIntegerOp

public static final boolean isBigIntegerOp(java.lang.Object obj0,
                                           java.lang.Object obj1)

isDoubleOp

public static final boolean isDoubleOp(java.lang.Object obj0,
                                       java.lang.Object obj1)

isLongOp

public static final boolean isLongOp(java.lang.Object obj0,
                                     java.lang.Object obj1)

isStringFloat

public static final boolean isStringFloat(java.lang.String str)

isDateTimeType

public static final boolean isDateTimeType(java.lang.Class<?> type)

coerceToDateTime

public static final java.util.Date coerceToDateTime(java.lang.Object obj,
                                                    java.lang.Class type)
                                             throws ELException
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


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo