Example usage for org.apache.commons.lang3.reflect MethodUtils getMatchingAccessibleMethod

List of usage examples for org.apache.commons.lang3.reflect MethodUtils getMatchingAccessibleMethod

Introduction

In this page you can find the example usage for org.apache.commons.lang3.reflect MethodUtils getMatchingAccessibleMethod.

Prototype

public static Method getMatchingAccessibleMethod(final Class<?> cls, final String methodName,
        final Class<?>... parameterTypes) 

Source Link

Document

Finds an accessible method that matches the given name and has compatible parameters.

Usage

From source file:com.hengyi.japp.sap.convert.impl.FieldCopyBoolean.java

@Override
protected void initBeanPropertyWriteMethod(Object bean, JCoRecord record) throws Exception {
    PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, beanPropertyName);
    Method m = descriptor.getWriteMethod();
    if (m == null) {
        beanPropertyWriteMethod = null;/*from   w w  w .  jav a2s  .com*/
    } else {
        beanPropertyWriteMethod = MethodUtils.getMatchingAccessibleMethod(bean.getClass(), m.getName(),
                BOOLEAN_CLASS);
    }
}

From source file:de.unentscheidbar.validation.internal.Methods.java

public static MethodChain findMethod(Class<?> clazz, String methodName, List<Class<?>> parameterTypes,
        String... propertyHierarchy) {

    Class<?>[] paramTypesAsArray = parameterTypes.toArray(new Class<?>[parameterTypes.size()]);
    Method m = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, paramTypesAsArray);

    Builder<Method> builder = ImmutableList.builder();
    for (int i = 0; clazz != null && m == null && i < propertyHierarchy.length; i++) {
        Method propertyAccessor = MethodUtils.getMatchingAccessibleMethod(clazz, propertyHierarchy[i]);
        if (propertyAccessor != null) {
            builder.add(propertyAccessor);
            clazz = propertyAccessor.getReturnType();
            m = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, paramTypesAsArray);
        }//w ww.j ava 2  s  . c om
    }
    if (m == null) {
        /* No such method found */
        return null;
    } else {
        /*
         * The list builder now contains all properties that lead to an accessible method m
         * which has the desired signature
         */
        builder.add(m);
        return new MethodChain(builder.build());
    }
}

From source file:com.hengyi.japp.sap.convert.impl.FieldCopyBase.java

protected void initBeanPropertyWriteMethod(Object bean, JCoRecord record) throws Exception {
    PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, beanPropertyName);
    beanPropertyWriteMethod = descriptor.getWriteMethod();
    if (beanPropertyWriteMethod == null) {
        return;/*  w  ww. ja  va 2 s .  c o m*/
    }
    String methodName = beanPropertyWriteMethod.getName();
    String expectedTypeString = record.getMetaData().getClassNameOfField(sapFieldName);
    Class<?> sapFieldType = Class.forName(expectedTypeString);
    beanPropertyWriteMethod = MethodUtils.getMatchingAccessibleMethod(bean.getClass(), methodName,
            sapFieldType);
}

From source file:io.konik.utils.RandomInvoiceGenerator.java

private static void setValue(Object entity, Method entityMethod, Object paramValue)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    if (paramValue == null || entity == null)
        return;/*from  ww  w .  j  a  v  a  2  s.  co  m*/
    String methodToCall = entityMethod.getName().replace("get", "set");
    //      int repeadAdder = 1;
    if (entityMethod.getName().startsWith("add")) {
        Collection.class.isAssignableFrom(entityMethod.getReturnType());
        methodToCall = entityMethod.getName();//overwrite
        //         repeadAdder += random.nextInt(5);//repeat call for adder
    }
    Method setterOrAdder = MethodUtils.getMatchingAccessibleMethod(entity.getClass(), methodToCall,
            paramValue.getClass());
    if (setterOrAdder == null) {
        setterOrAdder = getAccessibleMethod(entity.getClass(), methodToCall,
                paramValue.getClass().getSuperclass());
    }
    if (setterOrAdder == null) {
        System.out.println(
                "Could not find setter on Class Instnace :" + entity.getClass().getSimpleName() + " Getter :"
                        + entityMethod.getName() + " has no setter. Ignoring value:" + paramValue.toString());
        return;
    }
    //repeat a 2 times for adder
    for (int i = 0; i < 2; i++) {
        invokeMethod(entity, setterOrAdder.getName(), paramValue);
    }
}

From source file:org.apache.kylin.metadata.filter.function.BuiltInMethod.java

BuiltInMethod(Class<?> clazz, String methodName, Class<?>... argumentTypes) {
    this.method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argumentTypes);
}

From source file:sh.scrap.scrapper.functions.StringFunctionFactory.java

private Method findMethod(Class<?> targetClass, String methodName, Object mainArgument,
        Map<String, Object> annotations) {
    if (mainArgument == null)
        return MethodUtils.getMatchingAccessibleMethod(targetClass, methodName, String.class);
    else if (annotations.size() == 0)
        return MethodUtils.getMatchingAccessibleMethod(targetClass, methodName, String.class,
                mainArgument.getClass());

    Method candidate = null;/* www. j  a v a2s .  com*/
    for (Method method : targetClass.getMethods())
        if (method.getName().equals(methodName)) {
            candidate = method;
            String[] names = discoverer.getParameterNames(method);
            if (names.length > 2) {
                annotations.put(names[1], mainArgument);
                List<String> paramNames = Arrays.asList(names);
                if (paramNames.containsAll(annotations.keySet()) && annotations.keySet().contains(paramNames))
                    return candidate;
            } else
                return candidate;
        }

    if (candidate == null)
        throw new IllegalArgumentException("Unknown function [" + methodName + "]");

    return candidate;
}