You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Ivan <xh...@gmail.com> on 2010/01/20 07:46:16 UTC

[Discussion] Geronimo EL 2.2 Spec API

Hi,
    Recently, I am working on a new EL 2.2 Spec, and most of the codes are
done, however, some descriptions in the spec are ambiguous. I listed them
below, any comment would be welcomed.
    Object BeanELResolver.invoke (ELContext context, Object base, Object
method, Class<?>[] paramTypes, Object[] params)
    --->
    If the base object is not null, invoke the method,with the given
parameters on this bean.The return value
    from the method is returned.
    If the base is not null, the propertyResolved property of the ELContext
object must be set to
    true by this resolver, before returning. If this property is not true
after this method is called, the caller
    should ignore the return value.
    The provided method object will first be coerced to a String. The methods
in the bean is then examined
    and an attempt will be made to select one for invocation. If no suitable
can be found, a
    MethodNotFoundException is thrown. If the given paramTypes is not null,
select the method with
    the given name and parameter types. Else select the method with the
given name that has the same number
    of parameters. If there are more than one such method, the method
selection process is undefined. Else
    select the method with the given name that takes a variable number of
arguments. Note the resolution for
    overloaded methods will likely be clarified in a future version of the
spec. The provide parameters are
    coerced to the correcponding parameter types of the method, and the
method is then invoked.
    <---
    a. The doc did not give enough description about how to coerce the
parameter values while the method is of variable arguments. So I use the
logic
    // 1. If there is no parameter value left for the variable argment,
create a zero-length array
    // 2. If there is only one parameter value left for the variable
argment, and it has the same array type with the varArgsClass, pass in
directly
    // 3. Eles, create an array of varArgsClass type, and add all the left
coerced parameter values

    b. There is no description about what's the correct behavior if base or
method is null, an exception is thrown or a null value is returned.
    I keep the same way with the existing getValue method in the same class,
a null value is returned.

    c. Not sure static method invocation is supported by this method, which
means the parameter base could be null.
       Currently, I directly return null if base is null.


    Object CompositeELResolver.(ELContext context, Object base, Object
method, Class<?>[] paramTypes, Object[] params)
    --->
    Parameters:
    context - The context of this evaluation.
    base - The bean on which to invoke the method
    method - The simple name of the method to invoke. Will be coerced to a
String. If method is “”or
    “” a NoSuchMethodException is raised.
    paramTypes
-AnarrayofClassobjectsidentifyingthemethod’sformalparametertypes,indeclared
      order. Use an empty array if the method has no parameters. Can be
null, in which case the method’s
      formal parameter types are assumed to be unknown.
      params - The parameters to pass to the method, or null if no
parameters.
    Returns: The result of the method invocation (null if the method has a
void return type).
   <---
    a. About the parameter method, it says that it would be coerced to a
String, and if the method is "", a NoSuchMethodException is raised.
       But NoSuchMethodException is not a runtime exception, and invoke
method in ELResolver is not declared to throw it.
       So I just use the codes below :
       --->
       String targetMethod = (String) expressionFactory.coerceToType(method,
String.class);
        if (targetMethod.length() == 0) {
            throw new ELException(new NoSuchMethodException());
        }
      <---

    The last issue is that coerce action is required in the invoke method,
so a ExpressionFactory is required, but if we want to use its method :
    public abstract Object coerceToType(Object obj, Class<?> expectedType)
throws ELException;
    I must create a new instance, so I just feel that it might be less
efficient. I tried to improve it while using CompositeELReslover, but not
satisfied by myself.

    I attached a patch file to GERONIMO-5031, it would be better if somebody
could help to review it before I do the changes.
    Thanks !

-- 
Ivan

Re: [Discussion] Geronimo EL 2.2 Spec API

Posted by Ivan <xh...@gmail.com>.
I added a global setting
"org.apache.geronimo.spec.el.useCachedExpressionFactory" in the ELContext,
by default, an cache expressionFactory will be added in the context to avoid
creating ExpressionFactory each time when doing the coerce. Plan to run it
against TCK when avaible.

2010/1/20 Ivan <xh...@gmail.com>

> Hi,
>     Recently, I am working on a new EL 2.2 Spec, and most of the codes are
> done, however, some descriptions in the spec are ambiguous. I listed them
> below, any comment would be welcomed.
>     Object BeanELResolver.invoke (ELContext context, Object base, Object
> method, Class<?>[] paramTypes, Object[] params)
>     --->
>     If the base object is not null, invoke the method,with the given
> parameters on this bean.The return value
>     from the method is returned.
>     If the base is not null, the propertyResolved property of the ELContext
> object must be set to
>     true by this resolver, before returning. If this property is not true
> after this method is called, the caller
>     should ignore the return value.
>     The provided method object will first be coerced to a String. The
> methods in the bean is then examined
>     and an attempt will be made to select one for invocation. If no
> suitable can be found, a
>     MethodNotFoundException is thrown. If the given paramTypes is not null,
> select the method with
>     the given name and parameter types. Else select the method with the
> given name that has the same number
>     of parameters. If there are more than one such method, the method
> selection process is undefined. Else
>     select the method with the given name that takes a variable number of
> arguments. Note the resolution for
>     overloaded methods will likely be clarified in a future version of the
> spec. The provide parameters are
>     coerced to the correcponding parameter types of the method, and the
> method is then invoked.
>     <---
>     a. The doc did not give enough description about how to coerce the
> parameter values while the method is of variable arguments. So I use the
> logic
>     // 1. If there is no parameter value left for the variable argment,
> create a zero-length array
>     // 2. If there is only one parameter value left for the variable
> argment, and it has the same array type with the varArgsClass, pass in
> directly
>     // 3. Eles, create an array of varArgsClass type, and add all the left
> coerced parameter values
>
>     b. There is no description about what's the correct behavior if base or
> method is null, an exception is thrown or a null value is returned.
>     I keep the same way with the existing getValue method in the same
> class, a null value is returned.
>
>     c. Not sure static method invocation is supported by this method, which
> means the parameter base could be null.
>        Currently, I directly return null if base is null.
>
>
>     Object CompositeELResolver.(ELContext context, Object base, Object
> method, Class<?>[] paramTypes, Object[] params)
>     --->
>     Parameters:
>     context - The context of this evaluation.
>     base - The bean on which to invoke the method
>     method - The simple name of the method to invoke. Will be coerced to a
> String. If method is “”or
>     “” a NoSuchMethodException is raised.
>     paramTypes
> -AnarrayofClassobjectsidentifyingthemethod’sformalparametertypes,indeclared
>       order. Use an empty array if the method has no parameters. Can be
> null, in which case the method’s
>       formal parameter types are assumed to be unknown.
>       params - The parameters to pass to the method, or null if no
> parameters.
>     Returns: The result of the method invocation (null if the method has a
> void return type).
>    <---
>     a. About the parameter method, it says that it would be coerced to a
> String, and if the method is "", a NoSuchMethodException is raised.
>        But NoSuchMethodException is not a runtime exception, and invoke
> method in ELResolver is not declared to throw it.
>        So I just use the codes below :
>        --->
>        String targetMethod = (String)
> expressionFactory.coerceToType(method, String.class);
>         if (targetMethod.length() == 0) {
>             throw new ELException(new NoSuchMethodException());
>         }
>       <---
>
>     The last issue is that coerce action is required in the invoke method,
> so a ExpressionFactory is required, but if we want to use its method :
>     public abstract Object coerceToType(Object obj, Class<?> expectedType)
> throws ELException;
>     I must create a new instance, so I just feel that it might be less
> efficient. I tried to improve it while using CompositeELReslover, but not
> satisfied by myself.
>
>     I attached a patch file to GERONIMO-5031, it would be better if
> somebody could help to review it before I do the changes.
>     Thanks !
>
> --
> Ivan
>



-- 
Ivan