Example usage for java.lang NoSuchMethodException NoSuchMethodException

List of usage examples for java.lang NoSuchMethodException NoSuchMethodException

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException NoSuchMethodException.

Prototype

public NoSuchMethodException(String s) 

Source Link

Document

Constructs a NoSuchMethodException with a detail message.

Usage

From source file:org.openamf.invoker.JavaServiceInvoker.java

private RankedMethod getServiceMethod(Class serviceClass, String methodName, List parameters)
        throws SecurityException, NoSuchMethodException {

    RankedMethod serviceMethod = null;/*from  w  w w.jav a  2s.  c  o  m*/
    Method[] methods = serviceClass.getMethods();
    List rankedMethods = new ArrayList(methods.length);

    log.debug("REQUESTED methodName: " + methodName);

    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        RankedMethod rankedMethod = new RankedMethod(method, methodName, parameters);
        if (rankedMethod.isInvokable()) {
            //only added invokable methods to list
            rankedMethods.add(rankedMethod);
        }
    }

    if (rankedMethods.size() > 0) {
        Collections.sort(rankedMethods);
        RankedMethod topRankedMethod = (RankedMethod) rankedMethods.get(0);
        log.info("topRankedMethod: name=" + topRankedMethod.getMethod().getName() + " rank="
                + topRankedMethod.getRank());
        serviceMethod = topRankedMethod;
    }

    if (serviceMethod == null) {
        String errorDesc = serviceClass + "." + methodName + "(" + parameters + ")";
        log.warn("Method Not Found: " + errorDesc);
        throw new NoSuchMethodException(errorDesc);
    }

    return serviceMethod;
}

From source file:net.femtoparsec.jnlmin.linesearch.AbstractLineSearch.java

private Method findClosestMethod(Map<String, Map<Class<?>, Method>> unaryMethods, String methodName,
        Class<?> parameterType) throws NoSuchMethodException {
    Map<Class<?>, Method> candidates = unaryMethods.get(methodName);

    if (candidates == null) {
        throw new NoSuchMethodException(methodName);
    }/*from  w  w  w  .java  2s  .  c om*/

    Class<?> closest = ReflectUtils.findClosestClass(parameterType, candidates.keySet());
    if (closest == null) {
        throw new NoSuchMethodException(methodName);
    }
    return candidates.get(closest);
}

From source file:org.apache.olingo.ext.proxy.commons.EntityContainerInvocationHandler.java

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    if (isSelfMethod(method)) {
        return invokeSelfMethod(method, args);
    } else if ("flush".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
        service.getPersistenceManager().flush();
        return ClassUtils.returnVoid();
    } else if ("flushAsync".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
        return service.getPersistenceManager().flushAsync();
    } else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
        final Class<?> returnType = method.getReturnType();

        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                new Class<?>[] { returnType }, OperationInvocationHandler.getInstance(this));
    } else {// w  ww. j a v a 2s.c  o m
        final Class<?> returnType = method.getReturnType();

        if (returnType.isAnnotationPresent(EntitySet.class)) {
            return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                    new Class<?>[] { returnType }, EntitySetInvocationHandler.getInstance(returnType, service));
        } else if (returnType
                .isAnnotationPresent(org.apache.olingo.ext.proxy.api.annotations.EntityType.class)) {
            return getSingleton(method);
        }

        throw new NoSuchMethodException(method.getName());
    }
}

From source file:jef.tools.reflect.ClassEx.java

Object innerInvoke(Object obj, String method, boolean isStatic, Object... params) throws ReflectionException {
    try {/*  www  . j  a v a2  s.com*/
        if (obj == null && !isStatic)
            obj = newInstance();
        List<Class<?>> list = new ArrayList<Class<?>>();
        for (Object pobj : params) {
            list.add(pobj.getClass());
        }
        MethodEx me = BeanUtils.getCompatibleMethod(cls, method, list.toArray(new Class[list.size()]));
        if (me == null) {
            NoSuchMethodException e = new NoSuchMethodException("Method:[" + cls.getName() + "::" + method
                    + "] not found with param count:" + params.length);
            throw new ReflectionException(e);
        }
        if (!Modifier.isPublic(me.getModifiers()) || !Modifier.isPublic(cls.getModifiers())) {
            try {
                me.setAccessible(true);
            } catch (SecurityException e) {
                System.out.println(me.toString() + "\n" + e.getMessage());
            }
        }
        return me.invoke(obj, params);
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e);
    } catch (SecurityException e) {
        throw new ReflectionException(e);
    } catch (IllegalArgumentException e) {
        throw new ReflectionException(e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof Exception) {
            throw new ReflectionException((Exception) e.getCause());
        } else {
            throw new ReflectionException(e);
        }

    }
}

From source file:net.femtoparsec.jnlmin.utils.PropertySetter.java

private Method getSetter(String propertyName, Class<?> propertyClass) throws NoSuchMethodException {
    final String setterName = this.getSetterName(propertyName);
    final Key key = new Key(propertyName, propertyClass);

    Method method = this.setters.get(key);
    if (method == null && !checkedSetters.contains(key)) {
        Map<Class<?>, Method> candidates = this.unaryMethods.get(setterName);
        if (candidates != null) {
            Class<?> closestClass = ReflectUtils.findClosestClass(propertyClass, candidates.keySet());
            if (closestClass != null) {
                method = candidates.get(closestClass);
            }/*  w  w  w. j a v a2 s . com*/
        }
        this.setters.put(key, method);
        this.checkedSetters.add(key);
    }

    if (method == null) {
        throw new NoSuchMethodException(String.format("%s(%s)", setterName, propertyClass));
    }

    return method;
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java

/**
 * Returns a {@link Constructor} object that reflects the specified constructor of the given type.
 * <p/>/* ww  w . ja v  a  2  s .  co  m*/
 * If no parameter types are specified i.e., {@code paramTypes} is {@code null} or empty, the default constructor
 * is returned.<br/>
 * If a parameter type is not known i.e., it is {@code null}, all declared constructors are checked whether their
 * parameter types conform to the known parameter types i.e., if every known type is assignable to the parameter
 * type of the constructor and if exactly one was found, it is returned.<br/>
 * Otherwise a {@link NoSuchMethodException} is thrown indicating that no or several constructors were found.
 *
 * @param type the class
 * @param paramTypes the full-qualified class names of the parameters (can be {@code null})
 * @param classLoader the class loader to use
 * @return the accessible constructor resolved
 * @throws NoSuchMethodException if there are zero or more than one constructor candidates
 * @throws ClassNotFoundException if a class cannot be located by the specified class loader
 */
@SuppressWarnings("unchecked")
public static <T> Constructor<T> findConstructor(Class<T> type, Class<?>... clazzes)
        throws NoSuchMethodException, ClassNotFoundException {
    Constructor<T> constructor = null;

    // If all parameter types are known, find the constructor that exactly matches the signature
    if (!ArrayUtils.contains(clazzes, null)) {
        try {
            constructor = type.getDeclaredConstructor(clazzes);
        } catch (NoSuchMethodException e) {
            // Ignore
        }
    }

    // If no constructor was found, find all possible candidates
    if (constructor == null) {
        List<Constructor<T>> candidates = new ArrayList<>(1);
        for (Constructor<T> declaredConstructor : (Constructor<T>[]) type.getDeclaredConstructors()) {
            if (ClassUtils.isAssignable(clazzes, declaredConstructor.getParameterTypes())) {

                // Check if there is already a constructor method with the same signature
                for (int i = 0; i < candidates.size(); i++) {
                    Constructor<T> candidate = candidates.get(i);
                    /**
                     * If all parameter types of constructor A are assignable to the types of constructor B
                     * (at least one type is a subtype of the corresponding parameter), keep the one whose types
                     * are more concrete and drop the other one.
                     */
                    if (ClassUtils.isAssignable(declaredConstructor.getParameterTypes(),
                            candidate.getParameterTypes())) {
                        candidates.remove(candidate);
                        i--;
                    } else if (ClassUtils.isAssignable(candidate.getParameterTypes(),
                            declaredConstructor.getParameterTypes())) {
                        declaredConstructor = null;
                        break;
                    }
                }

                if (declaredConstructor != null) {
                    candidates.add(declaredConstructor);
                }
            }
        }
        if (candidates.size() != 1) {
            throw new NoSuchMethodException(
                    String.format("Cannot find distinct constructor for type '%s' with parameter types %s",
                            type, Arrays.toString(clazzes)));
        }
        constructor = candidates.get(0);
    }

    //do we really need this dependency?
    //ReflectionUtils.makeAccessible(constructor);
    if (constructor != null && !constructor.isAccessible())
        constructor.setAccessible(true);

    return constructor;

}

From source file:mitm.common.hibernate.InjectSessionProxyFactory.java

public InjectSessionProxyFactory(Class<T> clazz, HibernateSessionSource sessionSource)
        throws NoSuchMethodException {
    super(clazz);

    this.sessionSource = sessionSource;

    findInjectMethods(clazz);//w  ww  .ja  v a  2s .com

    if (injectHibernateSessionMethod == null) {
        throw new NoSuchMethodException("@InjectHibernateSession annotation was not found.");
    }

    this.setMethodHandler(new InjectSessionMethodHandler());
}

From source file:com.bstek.dorado.data.provider.manager.DataProviderInterceptorInvoker.java

public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    Method proxyMethod = methodInvocation.getMethod();
    String currentMethodName = proxyMethod.getName();
    if (!currentMethodName.equals(INTERCEPTING_METHOD_NAME)
            && !currentMethodName.equals(INTERCEPTING_PAGING_METHOD_NAME)) {
        return methodInvocation.proceed();
    }//from ww w . ja v a  2  s  .c  o  m

    if (interceptor == null) {
        interceptor = BeanFactoryUtils.getBean(interceptorName);
    }

    Method[] methods = MethodAutoMatchingUtils.getMethodsByName(interceptor.getClass(), methodName);
    if (methods.length == 0) {
        throw new NoSuchMethodException(resourceManager.getString("dorado.common/methodNotFoundInInterceptor",
                interceptorName, methodName));
    }

    DataProvider dataProvider = (DataProvider) methodInvocation.getThis();

    MethodAutoMatchingException[] exceptions = new MethodAutoMatchingException[4];
    int i = 0;

    try {
        try {
            return invokeInterceptorByParamName(dataProvider, methods, methodInvocation, false);
        } catch (MoreThanOneMethodsMatchsException e) {
            throw e;
        } catch (MethodAutoMatchingException e) {
            exceptions[i++] = e;
        } catch (AbortException e) {
            // do nothing
        }

        try {
            return invokeInterceptorByParamName(dataProvider, methods, methodInvocation, true);
        } catch (MoreThanOneMethodsMatchsException e) {
            throw e;
        } catch (MethodAutoMatchingException e) {
            exceptions[i++] = e;
        } catch (AbortException e) {
            // do nothing
        }

        try {
            return invokeInterceptorByParamType(dataProvider, methods, methodInvocation, false);
        } catch (MoreThanOneMethodsMatchsException e) {
            throw e;
        } catch (MethodAutoMatchingException e) {
            exceptions[i++] = e;
        } catch (AbortException e) {
            // do nothing
        }

        try {
            return invokeInterceptorByParamType(dataProvider, methods, methodInvocation, true);
        } catch (MoreThanOneMethodsMatchsException e) {
            throw e;
        } catch (MethodAutoMatchingException e) {
            exceptions[i++] = e;
        } catch (AbortException e) {
            // do nothing
        }
    } catch (MethodAutoMatchingException e) {
        exceptions[i++] = e;
    }

    for (MethodAutoMatchingException e : exceptions) {
        if (e == null) {
            break;
        }
        logger.error(e.getMessage());
    }
    throw new IllegalArgumentException(resourceManager.getString("dorado.common/noMatchingMethodError",
            interceptor.getClass().getName(), methodName));
}

From source file:org.statefulj.framework.core.actions.MethodInvocationAction.java

protected Object invoke(Object context, List<Object> invokeParmList) throws SecurityException,
        NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Method method = ReflectionUtils.findMethod(context.getClass(), this.method, this.parameters);
    if (method == null) {
        throw new NoSuchMethodException(this.method);
    }/*from   w ww . j a v  a  2s.c  om*/
    Object[] methodParms = invokeParmList.subList(0, this.parameters.length).toArray();
    method.setAccessible(true);
    return method.invoke(context, methodParms);
}

From source file:org.dhatim.javabean.factory.BasicFactoryDefinitionParser.java

/**
 * Creates a FactoryInstanceFactory object.
 *
 * @param factoryDefinition//from  w w  w.ja  va2  s .  c  o m
 * @param className
 * @param staticGetInstanceMethodDef
 * @param factoryMethodDef
 * @return
 * @throws ClassNotFoundException
 * @throws SecurityException
 * @throws NoSuchMethodException
 */
private Factory<?> createFactoryInstanceFactory(String factoryDefinition, String className,
        String staticGetInstanceMethodDef, String factoryMethodDef)
        throws ClassNotFoundException, SecurityException, NoSuchMethodException {
    Class<?> factoryClass = ClassUtil.forName(className, this.getClass());
    Method getInstanceMethod = factoryClass.getMethod(staticGetInstanceMethodDef);
    Class<?> factoryType = getInstanceMethod.getReturnType();
    Method factoryMethod = factoryType.getMethod(factoryMethodDef);

    if (!Modifier.isStatic(getInstanceMethod.getModifiers())) {
        throw new NoSuchMethodException("No static method with the name '" + staticGetInstanceMethodDef
                + "' can be found on the class '" + className + "'.");
    }

    return new FactoryInstanceFactory(factoryDefinition, getInstanceMethod, factoryMethod);
}