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.kawanfw.sql.jdbc.DatabaseMetaDataHttp.java

/**
 * Get the return type of a DatabaseMetaData method
 * /* ww w  .  j av a2s .  c  om*/
 * @param methodName
 *            the DatabaseMetaData method
 * @return the return type
 * @throws ClassNotFoundException
 * @throws SecurityException
 * @throws NoSuchMethodException
 */
private String getMethodReturnType(String methodName)
        throws ClassNotFoundException, SecurityException, NoSuchMethodException {

    Class<?> c = Class.forName("java.sql.DatabaseMetaData");
    Method[] allMethods = c.getDeclaredMethods();

    for (Method m : allMethods) {
        if (m.getName().endsWith(methodName)) {
            String returnType = m.getReturnType().toString();

            if (returnType.startsWith("class ")) {
                returnType = StringUtils.substringAfter(returnType, "class ");
            }
            if (returnType.startsWith("interface ")) {
                returnType = StringUtils.substringAfter(returnType, "interface ");
            }

            return returnType;
        }
    }

    throw new NoSuchMethodException("DatabaseMetaData does not contain this method: " + methodName);
}

From source file:org.jgentleframework.configure.ConfigurationProxy.java

@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {

    if (Modifier.isAbstract(method.getModifiers())) {
        if (method.isAnnotationPresent(Block.class)) {
            Block anno = method.getAnnotation(Block.class);
            Class<?>[] clazzList = anno.value();
            ObjectBlock objBlock = new ObjectBlock(method, clazzList);
            this.objBlockList.add(objBlock);
        }//  ww  w.  jav a  2 s . co  m
        // thc thi hm getOptionsList trn ConfigModule interface
        if (method.getName().equals("getOptionsList") && method.getParameterTypes().length == 0) {
            checkBlock(method);
            return this.optionsList;
        } else if (method.getName().equals("getTargetClass") && method.getParameterTypes().length == 0) {
            checkBlock(method);
            return this.targetClass;
        } else if (method.getName().equals("getConfigInstance") && method.getParameterTypes().length == 1) {
            checkBlock(method);
            return this.configObjList.get(args[0]);
        } else {
            if (!this.objBlockList.isEmpty()) {
                ObjectBlock objb = this.objBlockList.get(this.configObjList.size() - 1);
                List<Class<?>> clazzList = null;
                clazzList = objb.getBlockList();
                for (Class<?> clazz : clazzList) {
                    Object objConfig = this.configObjList.get(clazz);
                    List<Method> methodList = Arrays.asList(objConfig.getClass().getMethods());
                    if (methodList.contains(method)) {
                        checkBlock(method);
                        return method.invoke(objConfig, args);
                    } else {
                        continue;
                    }
                }
            }
            // Nu khng c
            for (Class<?> clazz : this.configObjList.keySet()) {
                Object objConfig = this.configObjList.get(clazz);
                List<Method> methodList = Arrays.asList(ReflectUtils.getAllDeclaredMethods(clazz));
                if (methodList.contains(method)) {
                    checkBlock(method);
                    return method.invoke(objConfig, args);
                } else {
                    continue;
                }
            }
            throw new NoSuchMethodException("Could not found " + method + " method!");
        }
    } else {
        checkBlock(method);
        return proxy.invokeSuper(obj, args);
    }
}

From source file:ClassReader.java

protected final Member resolveMethod(int index)
        throws IOException, ClassNotFoundException, NoSuchMethodException {
    int oldPos = pos;
    try {/*www.j av a 2 s  . co  m*/
        Member m = (Member) cpool[index];
        if (m == null) {
            pos = cpoolIndex[index];
            Class owner = resolveClass(readShort());
            NameAndType nt = resolveNameAndType(readShort());
            String signature = nt.name + nt.type;
            if ("<init>".equals(nt.name)) {
                Constructor[] ctors = owner.getConstructors();
                for (int i = 0; i < ctors.length; i++) {
                    String sig = getSignature(ctors[i], ctors[i].getParameterTypes());
                    if (sig.equals(signature)) {
                        cpool[index] = ctors[i];
                        m = ctors[i];
                        return m;
                    }
                }
            } else {
                Method[] methods = owner.getDeclaredMethods();
                for (int i = 0; i < methods.length; i++) {
                    String sig = getSignature(methods[i], methods[i].getParameterTypes());
                    if (sig.equals(signature)) {
                        cpool[index] = methods[i];
                        m = methods[i];
                        return m;
                    }
                }
            }
            throw new NoSuchMethodException(signature);
        }
        return m;
    } finally {
        pos = oldPos;
    }

}

From source file:com.ewcms.publication.freemarker.directive.PropertyDirective.java

/**
 * /*from   www. ja va 2s . c o  m*/
 * 
 * @param objectValue
 *                
 * @param property 
 *                ??
 * @return           
 */
protected Object getValue(Object objectValue, String property) throws NoSuchMethodException {
    try {
        return PropertyUtils.getProperty(objectValue, property);
    } catch (NoSuchMethodException e) {
        throw e;
    } catch (Exception e) {
        throw new NoSuchMethodException(e.toString());
    }
}

From source file:org.seasar.mayaa.impl.cycle.script.rhino.RhinoUtil.java

/**
 * getter??????/*from ww  w  . ja  va 2 s .c o m*/
 * JavaBean????????
 *
 * @param bean ?
 * @param propertyName ??
 * @return ?????????null
 * @throws NoSuchMethodException getter??????
 */
protected static Object getWithGetterMethod(Object bean, String propertyName) throws NoSuchMethodException {
    Class beanClass = bean.getClass();
    String baseName = capitalizePropertyName(propertyName);
    Method getter = null;
    try {
        getter = beanClass.getMethod("get" + baseName, VOID_ARGS_CLASS);
    } catch (NoSuchMethodException ignore) {
        // try boolean
    }
    if (getter == null) {
        try {
            // TODO Method
            Method booleanGetter = beanClass.getMethod("is" + baseName, VOID_ARGS_CLASS);
            if (booleanGetter != null) {
                Class returnType = booleanGetter.getReturnType();
                if (returnType.equals(Boolean.class) || returnType.equals(Boolean.TYPE)) {
                    getter = booleanGetter;
                }
            }
        } catch (NoSuchMethodException ignore) {
            // throw new exception for "getXxx"
        }
    }
    if (getter == null || Modifier.isPublic(getter.getModifiers()) == false) {
        throw new NoSuchMethodException(beanClass.toString() + ".get" + baseName + "()");
    }

    if (getter.isAccessible() == false) {
        getter.setAccessible(true);
    }
    try {
        return getter.invoke(bean, null);
    } catch (IllegalAccessException e) {
        LOG.debug(StringUtil.getMessage(RhinoUtil.class, 1, propertyName, beanClass.getName()));
    } catch (InvocationTargetException e) {
        LOG.debug(StringUtil.getMessage(RhinoUtil.class, 1, propertyName, beanClass.getName()));
    }
    return null;
}

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

private void findInjectMethods(Class<T> clazz) throws NoSuchMethodException {
    Method[] methods = clazz.getMethods();

    for (Method method : methods) {
        if (method.isAnnotationPresent(InjectHibernateSession.class)) {
            String parameterDescriptor = RuntimeSupport.makeDescriptor(method);

            if (!parameterDescriptor.equals("(Lorg/hibernate/Session;)V")) {
                throw new NoSuchMethodException(
                        "@InjectHibernateSession method does not have the correct parameters.");
            }//from w w w  .j  a  v a2 s.c  o  m

            injectHibernateSessionMethod = method;
        } else if (method.isAnnotationPresent(InjectHibernateSessionSource.class)) {
            String parameterDescriptor = RuntimeSupport.makeDescriptor(method);

            if (!parameterDescriptor.equals("(Lmitm/common/hibernate/HibernateSessionSource;)V")) {
                throw new NoSuchMethodException(
                        "@InjectHibernateSessionSource method does not have the correct parameters.");
            }

            injectHibernateSessionSourceMethod = method;
        }
    }
}

From source file:org.jdto.util.MethodUtils.java

/**
 * <p>Invoke a named method whose parameter type matches the object
 * type.</p>//from  ww w  .  ja va  2 s . c o m
 *
 * <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
 *
 * <p>This method supports calls to methods taking primitive parameters via
 * passing in wrapping classes. So, for example, a
 * <code>Boolean</code> object would match a
 * <code>boolean</code> primitive.</p>
 *
 * @param object invoke method on this object
 * @param methodName get method with this name
 * @param args use these arguments - treat null as empty array
 * @param parameterTypes match these parameters - treat null as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the method
 * invoked
 * @throws IllegalAccessException if the requested method is not accessible
 * via reflection
 */
public static Object invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (parameterTypes == null) {
        parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (args == null) {
        args = ArrayUtils.EMPTY_OBJECT_ARRAY;
    }
    Method method = getMatchingAccessibleMethod(object.getClass(), methodName, parameterTypes);
    if (method == null) {
        throw new NoSuchMethodException(
                "No such accessible method: " + methodName + "() on object: " + object.getClass().getName());
    }
    return method.invoke(object, args);
}

From source file:org.apache.struts.actions.DispatchAction.java

/**
 * Dispatch to the specified method./*from w w  w  .  ja  va2 s. c  om*/
 * @since Struts 1.1
 */
protected ActionForward dispatchMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, String name) throws Exception {

    // Make sure we have a valid method name to call.
    // This may be null if the user hacks the query string.
    if (name == null) {
        return this.unspecified(mapping, form, request, response);
    }

    // Identify the method object to be dispatched to
    Method method = null;
    try {
        method = getMethod(name);

    } catch (NoSuchMethodException e) {
        String message = messages.getMessage("dispatch.method", mapping.getPath(), name);
        log.error(message, e);

        String userMsg = messages.getMessage("dispatch.method.user", mapping.getPath());
        throw new NoSuchMethodException(userMsg);
    }

    ActionForward forward = null;
    try {
        Object args[] = { mapping, form, request, response };
        forward = (ActionForward) method.invoke(this, args);

    } catch (ClassCastException e) {
        String message = messages.getMessage("dispatch.return", mapping.getPath(), name);
        log.error(message, e);
        throw e;

    } catch (IllegalAccessException e) {
        String message = messages.getMessage("dispatch.error", mapping.getPath(), name);
        log.error(message, e);
        throw e;

    } catch (InvocationTargetException e) {
        // Rethrow the target exception if possible so that the
        // exception handling machinery can deal with it
        Throwable t = e.getTargetException();
        if (t instanceof Exception) {
            throw ((Exception) t);
        } else {
            String message = messages.getMessage("dispatch.error", mapping.getPath(), name);
            log.error(message, e);
            throw new ServletException(t);
        }
    }

    // Return the returned ActionForward instance
    return (forward);
}

From source file:com.ett.common.util.ReflectUtil.java

/**
 * @param object/*from www . j  ava2  s . c o  m*/
 * @param methodName
 * @param params
 * @return
 * @throws NoSuchMethodException
 */
public static Object invokePrivateMethod(Object object, String methodName, Object... params)
        throws NoSuchMethodException {
    Assert.notNull(object);
    Assert.hasText(methodName);
    Class[] types = new Class[params.length];
    for (int i = 0; i < params.length; i++) {
        types[i] = params[i].getClass();
    }

    Class clazz = object.getClass();
    Method method = null;
    for (Class superClass = clazz; superClass != Object.class; superClass = superClass.getSuperclass()) {
        try {
            method = superClass.getDeclaredMethod(methodName, types);
            break;
        } catch (NoSuchMethodException e) {
            // ??17,?
        }
    }

    if (method == null)
        throw new NoSuchMethodException("No Such Method:" + clazz.getSimpleName() + methodName);

    boolean accessible = method.isAccessible();
    method.setAccessible(true);
    Object result = null;
    try {
        result = method.invoke(object, params);
    } catch (Exception e) {
        ReflectionUtils.handleReflectionException(e);
    }
    method.setAccessible(accessible);
    return result;
}

From source file:org.apache.camel.component.cxf.jaxrs.CxfRsProducer.java

private Method findRightMethod(List<Class<?>> resourceClasses, String methodName, Class[] parameterTypes)
        throws NoSuchMethodException {
    Method answer = null;// w  w  w.  j a va 2 s .c  o m
    for (Class<?> clazz : resourceClasses) {
        try {
            answer = clazz.getMethod(methodName, parameterTypes);
        } catch (NoSuchMethodException ex) {
            // keep looking 
        } catch (SecurityException ex) {
            // keep looking
        }
        if (answer != null) {
            return answer;
        }
    }
    throw new NoSuchMethodException(
            "Can find the method " + methodName + "withe these parameter " + arrayToString(parameterTypes));
}