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.apache.hadoop.hbase.client.coprocessor.Batch.java

/**
 * Creates a new {@link Batch.Call} instance that invokes a method
 * with the given parameters and returns the result.
 *
 * <p>//ww  w  . j  ava2s. co m
 * Note that currently the method is naively looked up using the method name
 * and class types of the passed arguments, which means that
 * <em>none of the arguments can be <code>null</code></em>.
 * For more flexibility, see
 * {@link Batch#forMethod(java.lang.reflect.Method, Object...)}.
 * </p>
 *
 * @param protocol the protocol class being called
 * @param method the method name
 * @param args zero or more arguments to be passed to the method
 * (individual args cannot be <code>null</code>!)
 * @param <T> the class type of the protocol implementation being invoked
 * @param <R> the return type for the method call
 * @return a {@code Callable} instance that will invoke the given method
 * and return the results
 * @throws NoSuchMethodException if the method named, with the given argument
 *     types, cannot be found in the protocol class
 * @see Batch#forMethod(java.lang.reflect.Method, Object...)
 * @see org.apache.hadoop.hbase.client.HTable#coprocessorExec(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call, org.apache.hadoop.hbase.client.coprocessor.Batch.Callback)
 */
public static <T extends CoprocessorProtocol, R> Call<T, R> forMethod(final Class<T> protocol,
        final String method, final Object... args) throws NoSuchMethodException {
    Class[] types = new Class[args.length];
    for (int i = 0; i < args.length; i++) {
        if (args[i] == null) {
            throw new NullPointerException("Method argument cannot be null");
        }
        types[i] = args[i].getClass();
    }

    Method m = MethodUtils.getMatchingAccessibleMethod(protocol, method, types);
    if (m == null) {
        throw new NoSuchMethodException("No matching method found for '" + method + "'");
    }

    m.setAccessible(true);
    return forMethod(m, args);
}

From source file:com.buffalokiwi.api.APIResponse.java

/**
 * Clone an api response // w  ww  .  j  av a 2s .c  o  m
 * @param <T> some class that extends APIResponse
 * @param that Some response to clone 
 * @param type The class 
 * @return A copy of that 
 * @throws java.lang.NoSuchMethodException 
 * @throws java.lang.InstantiationException 
 * @throws java.lang.reflect.InvocationTargetException 
 * @throws java.lang.IllegalAccessException 
 */
public static <T extends APIResponse> T copyFrom(final IAPIResponse that, Class<T> type)
        throws NoSuchMethodException, InstantiationException, InvocationTargetException,
        IllegalArgumentException, IllegalAccessException {
    for (final Constructor<?> c : type.getConstructors()) {
        if (c.getParameterCount() == 6) {
            final T r = (T) c.newInstance(that.getProtocolVersion(), that.getStatusLine(), that.headers(),
                    that.getRedirectLocations(), that.getBytes(), that.getResponseCharsetName());
            return r;
        }
    }
    //T r = type.getConstructor( ProtocolVersion.class, StatusLine.class, List.class ).newInstance( that.getProtocolVersion(), that.getStatusLine(), that.headers());
    //r.setContent( that.getResponseContent(), that.getResponseCharsetName());
    //return r;    
    throw new NoSuchMethodException("Failed to locate constructor in class " + type);
}

From source file:ca.quadrilateral.btester.discovery.ParentInclusiveTestableMethodDiscoverer.java

private Method getMethod(final Class<?> clazz, final String methodName, final Class<?> returnType)
        throws NoSuchMethodException {
    if (clazz == null) {
        throw new NoSuchMethodException("No method with name " + methodName + " found");
    }//from  w  w w .  ja v  a 2s .  c  o  m
    try {
        return clazz.getDeclaredMethod(methodName, returnType);
    } catch (NoSuchMethodException e) {
        return getMethod(clazz.getSuperclass(), methodName, returnType);
    }
}

From source file:org.ovirt.engine.sdk.mapping.Mapper.java

/**
 * Fetches class contractor for mapping context
 * //from w  ww . jav  a2  s .  c o m
 * @param to
 *            class to look at
 * 
 * @return .ctr
 * 
 * @throws NoSuchMethodException
 */
private static <T> Constructor<?> getConstracor(Class<T> to) throws NoSuchMethodException {
    for (Constructor<?> ctr : to.getConstructors()) {
        if (ctr.getParameterTypes().length > 0 && ctr.getParameterTypes()[0].equals(HttpProxyBroker.class)) {
            return ctr;
        }
    }
    throw new NoSuchMethodException("HttpProxyBroker");
}

From source file:cherry.foundation.testtool.invoker.InvokerServiceImpl.java

@Override
public String invoke(String beanName, String className, String methodName, int methodIndex, String args,
        String argTypes) {// w ww .  j a v  a 2s  .  c  om
    try {

        Class<?> beanClass = getClass().getClassLoader().loadClass(className);
        List<Method> methodList = reflectionResolver.resolveMethod(beanClass, methodName);
        if (methodList.isEmpty()) {
            throw new NoSuchMethodException(format("{0}#{1}() not found", className, methodName));
        }
        Method method = (methodList.size() == 1 ? methodList.get(0) : methodList.get(methodIndex));

        return invoker.invoke(beanName, beanClass, method, resolveArgs(args), resolveArgTypes(argTypes));
    } catch (ClassNotFoundException | NoSuchMethodException ex) {
        return fromThrowableToString(ex);
    } catch (IOException ex) {
        return fromThrowableToString(ex);
    } catch (IllegalStateException ex) {
        if (ex.getCause() instanceof InvocationTargetException
                || ex.getCause() instanceof IllegalAccessException || ex.getCause() instanceof IOException) {
            return fromThrowableToString(ex.getCause());
        } else {
            return fromThrowableToString(ex);
        }
    } catch (Exception ex) {
        return fromThrowableToString(ex);
    }
}

From source file:org.jkcsoft.java.util.Beans.java

public static Object get(Object bean, String propName) throws Exception {
    PropertyDescriptor pd = getPropertyDescriptor(bean, propName);

    if (pd == null) {
        throw new NoSuchFieldException("Unknown property: " + propName);
    }//from   w  w  w .  j  av  a  2  s  .  c  o m

    Method getter = pd.getReadMethod();
    if (getter == null) {
        throw new NoSuchMethodException("No read method for: " + propName);
    }

    return getter.invoke(bean, new Object[] {});
}

From source file:com.curl.orb.servlet.InstanceManagementUtil.java

/**
 * Get Method./*from   ww w. j a  v  a 2  s .  co  m*/
 */
public static Method getMethod(Object obj, String methodName, Object[] arguments) throws NoSuchMethodException {
    Method method = MethodUtils.getMatchingAccessibleMethod(obj.getClass(), methodName,
            getArgumentClasses(arguments));
    if (method == null)
        throw new NoSuchMethodException("No such accessible method: " + methodName + "() on object");
    return method;
}

From source file:org.forgerock.openam.guice.GuiceModuleCreator.java

/**
 * Finds and returns the Constructor to use to create the Guice module.
 *
 * Note: There must be one and only one public no-arg constructor for the Guice module.
 *
 * @param clazz The Guice module class./*from www .  j  av a  2s  . c o  m*/
 * @param <T> The Guice module class type.
 * @return The public no-arg constructor.
 * @throws NoSuchMethodException If no public no-arg constructor exists in this class.
 */
private <T> Constructor<T> getConstructor(Class<T> clazz) throws NoSuchMethodException {

    Constructor constructor = ConstructorUtils.getAccessibleConstructor(clazz, new Class[] {});

    if (constructor != null) {
        return constructor;
    } else {
        throw new NoSuchMethodException(
                String.format("No public zero-arg constructor found on %s", clazz.getCanonicalName()));
    }
}

From source file:org.openamf.AdvancedGateway.java

/**
 * Uses the setting in openamf-config.xml to gets the correct invoker,
 * enforce access control, and store state-beans in the request/session
 * /*ww  w.ja  v  a2 s  .c o  m*/
 * @see org.openamf.DefaultGateway#getServiceInvoker(org.openamf.AMFBody,
 *         javax.servlet.http.HttpServletRequest)
 */
protected ServiceInvoker getServiceInvoker(AMFBody requestBody, HttpServletRequest httpServletRequest)
        throws ServiceInvocationException {

    ServiceInvoker serviceInvoker = null;

    try {
        ServiceConfig serviceConfig = getServiceConfig(requestBody);

        if (serviceConfig == null) {
            throw new AccessDeniedException(
                    "could not find service configuration for '" + requestBody.getServiceName() + "'");
        }

        ServiceRequest request = new ServiceRequest(requestBody, serviceConfig);
        ServiceMethodConfig methodConfig = getMethodConfig(serviceConfig, request);
        // abort if no method config is found. This allows us to restrict
        // access to the service in the openamf configuration.
        if (methodConfig == null) {
            NoSuchMethodException e = new NoSuchMethodException(request.getRequestBody().toString());

            log.warn("Method config not found: " + request.getRequestBody().toString());
            throw e;
        }

        // store methodConfig for later use
        request.setServiceMethodConfig(methodConfig);

        // Check access permissions if there are any in the configuration
        Iterator constraints = methodConfig.getAccessConstraintConfigs();
        if (constraints.hasNext()) {
            boolean accessDenied = true;
            while (accessDenied && constraints.hasNext()) {
                ServiceMethodAccessConstraintConfig constraint = (ServiceMethodAccessConstraintConfig) constraints
                        .next();
                accessDenied = !httpServletRequest.isUserInRole(constraint.getRoleName());
            }
            if (accessDenied) {
                Principal user = httpServletRequest.getUserPrincipal();
                throw new AccessDeniedException((user == null ? "<anonymous user>" : user.getName()));
            }
        }

        addStateBeansToParams(httpServletRequest, request, methodConfig);

        serviceInvoker = ServiceInvoker.load(serviceConfig.getServiceInvokerConfig().getClassName(), request,
                httpServletRequest, getServletContext());

        serviceInvoker.prepare(request);

    } catch (Exception e) {
        throw new ServiceInvocationException(requestBody, e);
    }

    return serviceInvoker;
}

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

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    if ("filter".equals(method.getName()) || "orderBy".equals(method.getName())
            || "top".equals(method.getName()) || "skip".equals(method.getName())
            || "expand".equals(method.getName()) || "select".equals(method.getName())
            || "nextPage".equals(method.getName()) || "refs".equals(method.getName())
            || "execute".equals(method.getName())) {
        invokeSelfMethod(method, args);/* ww  w.j  a v a2 s  .  c  o m*/
        return proxy;
    } else if (isSelfMethod(method)) {
        return invokeSelfMethod(method, args);
    } 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 {
        throw new NoSuchMethodException(method.getName());
    }
}