Example usage for org.springframework.util ReflectionUtils findMethod

List of usage examples for org.springframework.util ReflectionUtils findMethod

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils findMethod.

Prototype

@Nullable
public static Method findMethod(Class<?> clazz, String name, @Nullable Class<?>... paramTypes) 

Source Link

Document

Attempt to find a Method on the supplied class with the supplied name and parameter types.

Usage

From source file:org.tdar.core.service.ReflectionService.java

/**
 * Call the setter of the supplied object and field with the supplied value
 * // w ww  . j  a va 2  s . c  o m
 * @param obj
 * @param field
 * @param fieldValue
 */
public <T> void callFieldSetter(Object obj, Field field, T fieldValue) {
    String setterName = generateSetterName(field);
    String valClass = "null";
    if (fieldValue != null) {
        valClass = fieldValue.getClass().getSimpleName();
    }
    logger.trace("Calling {}.{}({})",
            new Object[] { field.getDeclaringClass().getSimpleName(), setterName, valClass });
    // here we assume that field's type is assignable from the fieldValue
    Method setter = ReflectionUtils.findMethod(field.getDeclaringClass(), setterName, field.getType());
    try {
        setter.invoke(obj, fieldValue);
    } catch (Exception e) {
        logger.debug("cannot call field setter {} on : {} {}  {}", field, obj, fieldValue, e);
    }

}

From source file:org.tdar.core.service.ReflectionService.java

public Method findMatchingSetter(Method method) {
    String name = "set" + method.getName().substring(3);
    return ReflectionUtils.findMethod(method.getDeclaringClass(), name, method.getReturnType());
}