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:gobblin.util.reflection.GobblinConstructorUtils.java

/**
 * Convenience method on top of {@link ConstructorUtils#invokeConstructor(Class, Object[])} that returns a new
 * instance of the <code>cls</code> based on a constructor priority order. Each {@link List} in the
 * <code>constructorArgs</code> array contains the arguments for a constructor of <code>cls</code>. The first
 * constructor whose signature matches the argument types will be invoked.
 *
 * @param cls the class to be instantiated
 * @param constructorArgs An array of constructor argument list. Order defines the priority of a constructor.
 * @return//from ww w  .  j a  v  a2  s  .c om
 *
 * @throws NoSuchMethodException if no constructor matched was found
 */
@SafeVarargs
public static <T> T invokeFirstConstructor(Class<T> cls, List<Object>... constructorArgs)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {

    for (List<Object> args : constructorArgs) {

        Class<?>[] parameterTypes = new Class[args.size()];
        for (int i = 0; i < args.size(); i++) {
            parameterTypes[i] = args.get(i).getClass();
        }

        if (ConstructorUtils.getMatchingAccessibleConstructor(cls, parameterTypes) != null) {
            return ConstructorUtils.invokeConstructor(cls, args.toArray(new Object[args.size()]));
        }
    }
    throw new NoSuchMethodException("No accessible constructor found");
}

From source file:org.apache.myfaces.trinidadbuild.plugin.faces.parse.rules.BeanPropertySetterRule.java

public void end(String namespace, String name) throws Exception {
    Object top = digester.peek();

    PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(top, propertyName);

    if (descriptor == null) {
        throw new NoSuchMethodException("Missing bean property \"" + propertyName + "\"");
    }/*from ww  w  .  j a  va 2s. c o  m*/

    Class propertyType = descriptor.getPropertyType();

    if (QName.class.equals(propertyType)) {
        int colon = bodyText.indexOf(':');
        if (colon != -1) {
            String namespaceURI = digester.findNamespaceURI(bodyText.substring(0, colon));
            bodyText = "{" + namespaceURI + "}" + bodyText.substring(colon + 1);
        } else if (bodyText.indexOf('{') == -1) {
            String namespaceURI = digester.findNamespaceURI("");
            bodyText = "{" + namespaceURI + "}" + bodyText.substring(colon + 1);
        }
        BeanUtils.setProperty(top, propertyName, bodyText);
    } else {
        super.end(namespace, name);
    }
}

From source file:PropertyUtils.java

/**
 * Get specified property value//from  ww w .j a v  a2s.  co  m
 */
public static Object getProperty(Object bean, String property)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), property);
    if (descriptor == null)
        throw new NoSuchMethodException("Cannot find property " + bean.getClass().getName() + "." + property);
    Method method = descriptor.getReadMethod();
    if (method == null)
        throw new NoSuchMethodException("Cannot find getter for " + bean.getClass().getName() + "." + property);
    return method.invoke(bean, null);
}

From source file:info.novatec.testit.livingdoc.util.ClassUtils.java

private static <T> NoSuchMethodException noSuitableConstructorException(Class<T> klass, Object... args) {
    return new NoSuchMethodException(klass.getName() + ".<init>(" + toString(args) + ")");
}

From source file:au.id.hazelwood.sos.web.controller.framework.GlobalExceptionHandlerUnitTest.java

@Test
public void testHandleNotFound() throws Exception {
    WebRequest webRequest = mock(WebRequest.class);

    ResponseEntity<Object> responseEntity = handler
            .handleNotFound(new NoSuchMethodException("Entity not found"), webRequest);

    assertResponseEntity(responseEntity, HttpStatus.NOT_FOUND, "Entity not found");
    verifyZeroInteractions(webRequest);//  w  w w. j av a  2  s. co m
}

From source file:org.mypsycho.beans.DescriptorExtension.java

void delegateRequired(String method) throws NoSuchMethodException {
    if (delegate == null) {
        throw new NoSuchMethodException("Property '" + getName() + "' has no " + method
                + " method on bean class '" + type.getName() + "'");
    }//from   w  w w  . jav  a 2 s  .  co  m
}

From source file:org.carewebframework.shell.property.PropertyUtil.java

/**
 * Returns the requested method from an object instance.
 * /*from w  w  w .  j ava  2 s  .co  m*/
 * @param methodName Name of the setter method.
 * @param instance Object instance to search.
 * @param valueClass The desired property return type (null if don't care).
 * @param setter If true, search for setter method signature. If false, getter method signature.
 * @return The requested method.
 * @throws NoSuchMethodException If method was not found.
 */
private static Method findMethod(String methodName, Object instance, Class<?> valueClass, boolean setter)
        throws NoSuchMethodException {
    if (methodName == null) {
        return null;
    }

    int paramCount = setter ? 1 : 0;

    for (Method method : instance.getClass().getMethods()) {
        if (method.getName().equals(methodName) && method.getParameterTypes().length == paramCount) {
            Class<?> targetClass = setter ? method.getParameterTypes()[0] : method.getReturnType();

            if (valueClass == null || TypeUtils.isAssignable(targetClass, valueClass)) {
                return method;
            }
        }
    }

    throw new NoSuchMethodException("Compatible method not found: " + methodName);

}

From source file:com.haulmont.bali.util.ReflectionHelper.java

/**
 * Instantiates an object by appropriate constructor.
 * @param cls       class/*w w  w  .j  av  a  2 s.c  o m*/
 * @param params    constructor arguments
 * @return          created object instance
 * @throws NoSuchMethodException    if the class has no constructor matching the given arguments
 */
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<T> cls, Object... params) throws NoSuchMethodException {
    Class[] paramTypes = getParamTypes(params);

    Constructor<T> constructor = ConstructorUtils.getMatchingAccessibleConstructor(cls, paramTypes);
    if (constructor == null)
        throw new NoSuchMethodException(
                "Cannot find a matching constructor for " + cls.getName() + " and given parameters");
    try {
        return constructor.newInstance(params);
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.mypsycho.beans.DefaultInvoker.java

void required(Object bean, PropertyDescriptor prop, Method method, String name) throws NoSuchMethodException {
    if (method == null) {
        throw new NoSuchMethodException("Property '" + prop.getName() + "' has no " + name
                + " method on bean class '" + bean.getClass() + "'");
    }// w w w. j av a2  s  .  c o  m
}

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

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    if ("load".equals(method.getName())) {
        load();/* w w  w .  jav  a 2 s  .c o m*/
        return proxy;
    } else {
        if (isSelfMethod(method)) {
            return invokeSelfMethod(method, args);
        } else {
            throw new NoSuchMethodException(method.getName());
        }
    }
}