Package javax.el

Examples of javax.el.MethodNotFoundException


    @SuppressWarnings("null")
    public static Method getMethod(Object base, Object property,
            Class<?>[] paramTypes, Object[] paramValues)
            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();

        int paramCount;
        if (paramTypes == null) {
            paramCount = 0;
        } else {
            paramCount = paramTypes.length;
        }

        Method[] methods = base.getClass().getMethods();
        Map<Method,Integer> candidates = new HashMap<>();

        for (Method m : methods) {
            if (!m.getName().equals(methodName)) {
                // Method name doesn't match
                continue;
            }

            Class<?>[] mParamTypes = m.getParameterTypes();
            int mParamCount;
            if (mParamTypes == null) {
                mParamCount = 0;
            } else {
                mParamCount = mParamTypes.length;
            }

            // Check the number of parameters
            if (!(paramCount == mParamCount ||
                    (m.isVarArgs() && paramCount >= mParamCount))) {
                // Method has wrong number of parameters
                continue;
            }

            // Check the parameters match
            int exactMatch = 0;
            boolean noMatch = false;
            for (int i = 0; i < mParamCount; i++) {
                // Can't be null
                if (mParamTypes[i].equals(paramTypes[i])) {
                    exactMatch++;
                } else if (i == (mParamCount - 1) && m.isVarArgs()) {
                    Class<?> varType = mParamTypes[i].getComponentType();
                    for (int j = i; j < paramCount; j++) {
                        if (!isAssignableFrom(paramTypes[j], varType)) {
                            if (paramValues == null) {
                                noMatch = true;
                                break;
                            } else {
                                if (!isCoercibleFrom(paramValues[j], varType)) {
                                    noMatch = true;
                                    break;
                                }
                            }
                        }
                        // Don't treat a varArgs match as an exact match, it can
                        // lead to a varArgs method matching when the result
                        // should be ambiguous
                    }
                } else if (!isAssignableFrom(paramTypes[i], mParamTypes[i])) {
                    if (paramValues == null) {
                        noMatch = true;
                        break;
                    } else {
                        if (!isCoercibleFrom(paramValues[i], mParamTypes[i])) {
                            noMatch = true;
                            break;
                        }
                    }
                }
            }
            if (noMatch) {
                continue;
            }

            // If a method is found where every parameter matches exactly,
            // return it
            if (exactMatch == paramCount) {
                getMethod(base.getClass(), m);
            }

            candidates.put(m, Integer.valueOf(exactMatch));
        }

        // Look for the method that has the highest number of parameters where
        // the type matches exactly
        int bestMatch = 0;
        Method match = null;
        boolean multiple = false;
        for (Map.Entry<Method, Integer> entry : candidates.entrySet()) {
            if (entry.getValue().intValue() > bestMatch ||
                    match == null) {
                bestMatch = entry.getValue().intValue();
                match = entry.getKey();
                multiple = false;
            } else if (entry.getValue().intValue() == bestMatch) {
                multiple = true;
            }
        }
        if (multiple) {
            if (bestMatch == paramCount - 1) {
                // Only one parameter is not an exact match - try using the
                // super class
                match = resolveAmbiguousMethod(candidates.keySet(), paramTypes);
            } else {
                match = null;
            }

            if (match == null) {
                // If multiple methods have the same matching number of parameters
                // the match is ambiguous so throw an exception
                throw new MethodNotFoundException(MessageFactory.get(
                        "error.method.ambiguous", base, property,
                        paramString(paramTypes)));
                }
        }

        // Handle case where no match at all was found
        if (match == null) {
            throw new MethodNotFoundException(MessageFactory.get(
                        "error.method.notfound", base, property,
                        paramString(paramTypes)));
        }

        return getMethod(base.getClass(), match);
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

//                m = new MethodCache(type);
//                methodCache.set(type, m);
//            }
            r = m.findMethod(methodName, params);
            if (r == null) {
                throw new MethodNotFoundException(MessageFactory.get(
                        "error.method.notfound", base, name,
                        paramString(paramTypes(params))));
            }
        } else {
            throw new MethodNotFoundException();
        }
        return r;
    }
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

    }
   
    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

        {
            return invoker.invoke();
        }
        catch (javax.faces.el.MethodNotFoundException e)
        {
            throw new MethodNotFoundException(e.getMessage(), e);
        }
        catch (EvaluationException e)
        {
            throw new ELException(e.getMessage(), e);
        }
View Full Code Here

    public void testProcessValueChange2() throws Exception
    {
        // First, try to invoke the MethodExpression passed to the constructor of this instance,
        // passing the argument ValueChangeEvent as the argument
        methodExpressionOneArg.invoke(EasyMock.eq(facesContext.getELContext()), EasyMock.aryEq(paramsWithValueChangeEvent));
        EasyMock.expectLastCall().andThrow(new MethodNotFoundException()).times(1);
        // If a MethodNotFoundException  is thrown,
        // call to the zero argument MethodExpression derived from the MethodExpression passed
        // to the constructor of this instance
        methodExpressionZeroArg.invoke(EasyMock.eq(facesContext.getELContext()), EasyMock.aryEq(new Object[0]));
        EasyMock.expectLastCall().andReturn(null).times(1);
View Full Code Here

    public void testProcessAction2() throws Exception
    {
        // First, try to invoke the MethodExpression passed to the constructor of this instance,
        // passing the argument ActionEvent as the argument
        methodExpressionOneArg.invoke(EasyMock.eq(facesContext.getELContext()), EasyMock.aryEq(paramsWithActionEvent));
        EasyMock.expectLastCall().andThrow(new MethodNotFoundException()).times(1);
        // If a MethodNotFoundException  is thrown,
        // call to the zero argument MethodExpression derived from the MethodExpression passed
        // to the constructor of this instance
        methodExpressionZeroArg.invoke(EasyMock.eq(facesContext.getELContext()), EasyMock.aryEq(new Object[0]));
        EasyMock.expectLastCall().andReturn(null).times(1);
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.