Package javax.el

Examples of javax.el.MethodNotFoundException


    }
   
    private static final Object[] EMPTY_PARAMS = new Object[0];
   
    public static Object invokeMethod(Object base, Method m, Object[] paramValues) throws ELException {
        if (m == null) throw new MethodNotFoundException();
       
        Class[] paramTypes = m.getParameterTypes();
        Object[] params = null;
       
        if (paramTypes.length == 0) {
            // leave params null
        } else if (paramValues == null) {
            throw new MethodNotFoundException(m.getDeclaringClass() + "." + m.getName() + " has " + paramTypes.length + " params");
        } else if (m.isVarArgs()) {
            // add values
            params = new Object[paramTypes.length];
           
            int i = 0;
            for (; i < paramTypes.length - 1; i++) {
                params[i] = ELSupport.coerceToType(paramValues[i], paramTypes[i]);
            }
           
            Class argType = paramTypes[i].getComponentType();
            if (paramTypes.length == paramValues.length) {
                if (paramValues[i] == null) {
                    params[i] = Array.newInstance(argType, 0);
                } else if (paramValues[i].getClass().isArray()) {
                    params[i] = paramValues[i];
                } else {
                    params[i] = Array.newInstance(argType, 1);
                    Array.set(params[i], 0, ELSupport.coerceToType(paramValues[i], argType));
                }
            } else {
                int len = paramValues.length - paramTypes.length + 1;
                Object ar = Array.newInstance(argType, len);
                for (int j = 0; j < len; j++) {
                    Array.set(ar, j, ELSupport.coerceToType(paramValues[paramTypes.length - 1 + j], argType));
                }
                params[i] = ar;
            }
        } else if (paramValues.length == paramTypes.length) {
            // add values
            params = new Object[paramTypes.length];
           
            // assign first set
            for (int i = 0; i < paramTypes.length; i++) {
                params[i] = ELSupport.coerceToType(paramValues[i], paramTypes[i]);
            }
        } else {
            throw new MethodNotFoundException(m.getDeclaringClass().getName() + "." + m.getName() + " has " + paramTypes.length + ", only passed " + paramValues.length + " parameters");
        }
       
        try {
            return m.invoke(base, params);
        } catch (IllegalAccessException iae) {
View Full Code Here


     * @throws MethodNotFoundException
     */
    public static Method getMethod(Object base, Object property,
            Class[] paramTypes) throws MethodNotFoundException {
        if (base == null || property == null) {
            throw new MethodNotFoundException(MessageFactory.get(
                    "error.method.notfound", base, property,
                    paramString(paramTypes)));
        }

        String methodName = (property instanceof String) ? (String) property
                : property.toString();

        Method method = null;
        try {
            method = base.getClass().getMethod(methodName, paramTypes);
        } catch (NoSuchMethodException nsme) {
            throw new MethodNotFoundException(MessageFactory.get(
                    "error.method.notfound", base, property,
                    paramString(paramTypes)));
        }
        return method;
    }
View Full Code Here

            Object[] paramValues) throws ELException {
        if (target instanceof MethodExpression) {
            MethodExpression me = (MethodExpression) target;
            return me.invoke(ctx.getELContext(), paramValues);
        } else if (target == null) {
            throw new MethodNotFoundException("Identity '" + this.image
                    + "' was null and was unable to invoke");
        } else {
            throw new ELException(
                    "Identity '"
                            + this.image
View Full Code Here

        // finally provide helpful hints
        if (obj instanceof MethodExpression) {
            return (MethodExpression) obj;
        } else if (obj == null) {
            throw new MethodNotFoundException("Identity '" + this.image
                    + "' was null and was unable to invoke");
        } else {
            throw new ELException(
                    "Identity '"
                            + this.image
View Full Code Here

     * @throws MethodNotFoundException
     */
    public static Method getMethod(Object base, Object property,
            Class[] paramTypes) throws MethodNotFoundException {
        if (base == null || property == null) {
            throw new MethodNotFoundException(MessageFactory.get(
                    "error.method.notfound", base, property,
                    paramString(paramTypes)));
        }

        String methodName = (property instanceof String) ? (String) property
                : property.toString();

        Method method = null;
        try {
            method = base.getClass().getMethod(methodName, paramTypes);
        } catch (NoSuchMethodException nsme) {
            throw new MethodNotFoundException(MessageFactory.get(
                    "error.method.notfound", base, property,
                    paramString(paramTypes)));
        }
        return method;
    }
View Full Code Here

  @Override
  public Object eval(Bindings bindings, ELContext context) {
    Object base = prefix.eval(bindings, context);
    if (base == null) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.base.null", prefix));
    }
    Object value = null;
    try {
      value = context.getELResolver().getValue(context, base, name);
    } catch (PropertyNotFoundException e) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.resolve", name, base.getClass()));
    }
    if (!context.isPropertyResolved()) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.resolve", name, base.getClass()));
    }
    Method method = null;
    if (value instanceof Method) {
      method = (Method)value;
    } else if (value instanceof MethodInfo) {
      try {
        method = value.getClass().getMethod(name, ((MethodInfo)value).getParamTypes());
      } catch (NoSuchMethodException e) {
        throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, base.getClass()), e);
      }
    } else {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, base.getClass()));
    }
    Class[] types = method.getParameterTypes();
    if (nodes == null && types.length > 0 || nodes != null && nodes.size() != types.length) {
      throw new ELException(LocalMessages.get("error.property.method.invocation", name, base.getClass()));
    }
View Full Code Here

  protected Method findMethod(String name, Class<?> clazz, Class<?> returnType, Class<?>[] paramTypes) {
    Method method = null;
    try {
      method = clazz.getMethod(name, paramTypes);
    } catch (NoSuchMethodException e) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, clazz));
    }
    if (returnType != null && !returnType.isAssignableFrom(method.getReturnType())) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, clazz));
    }
    return method;
  }
View Full Code Here

  }

  protected Method getMethod(Bindings bindings, ELContext context, Class<?> returnType, Class<?>[] paramTypes) {
    Object value = eval(bindings, context);
    if (value == null) {
      throw new MethodNotFoundException(LocalMessages.get("error.identifier.method.notfound", name));
    }
    if (value instanceof Method) {
      Method method = (Method)value;
      if (returnType != null && !returnType.isAssignableFrom(method.getReturnType())) {
        throw new MethodNotFoundException(LocalMessages.get("error.identifier.method.notfound", name));
      }
      if (!Arrays.equals(method.getParameterTypes(), paramTypes)) {
        throw new MethodNotFoundException(LocalMessages.get("error.identifier.method.notfound", name));
      }
      return method;
    }
    throw new MethodNotFoundException(LocalMessages.get("error.identifier.method.notamethod", name, value.getClass()));
  }
View Full Code Here

        public String toString() {
          return getName();
        }
      });
    } catch (PropertyNotFoundException e) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.resolve", name, base.getClass()));
    }
    if (!context.isPropertyResolved()) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.resolve", name, base.getClass()));
    }
    Method method = null;
    if (value instanceof Method) {
      method = (Method)value;
    } else if (value instanceof MethodInfo) {
      try {
        method = value.getClass().getMethod(name, ((MethodInfo)value).getParamTypes());
      } catch (NoSuchMethodException e) {
        throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, base.getClass()), e);
      }
    } else {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, base.getClass()));
    }
    return method;
  }
View Full Code Here

 
  @Override
  public Object eval(Bindings bindings, ELContext context) {
    Object base = getBase().eval(bindings, context);
    if (base == null) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.base.null", getBase()));
    }
    String name = getName(bindings, context);
    if (name == null || name.length() == 0) {
      throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, base.getClass()));
    }
    Method method = resolveMethod(context, base, name);
    if (varargs && method.isVarArgs()) {
      if (method.getParameterTypes().length > getParamCount() + 1) {
        throw new ELException(LocalMessages.get("error.property.method.invocation", name, base.getClass()));
View Full Code Here

TOP

Related Classes of javax.el.MethodNotFoundException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.