Example usage for org.apache.commons.lang.reflect MethodUtils getAccessibleMethod

List of usage examples for org.apache.commons.lang.reflect MethodUtils getAccessibleMethod

Introduction

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

Prototype

public static Method getAccessibleMethod(Method method) 

Source Link

Document

Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method.

Usage

From source file:org.sglj.service.rmi.RmiUtils.java

public static Method getMatchingAccessibleMethod(Class<?> cls, String methodName, Class<?>[] parameterTypes,
        Collection<Method> callableMethods) {
    try {/* ww w.j av  a2  s.co m*/
        return cls.getMethod(methodName, parameterTypes);
    } catch (NoSuchMethodException e) { /* SWALLOW */
    }
    // search through all methods
    Method bestMatch = null;
    for (Method method : callableMethods) {
        if (method.getName().equals(methodName)) {
            // compare parameters
            if (ClassUtils.isAssignable(parameterTypes, method.getParameterTypes(), true)) {
                // get accessible version of method
                Method accessibleMethod = MethodUtils.getAccessibleMethod(method);
                if (accessibleMethod != null) {
                    if (bestMatch == null || compareParameterTypes(accessibleMethod.getParameterTypes(),
                            bestMatch.getParameterTypes(), parameterTypes) < 0) {
                        bestMatch = accessibleMethod;
                    }
                }
            }
        }
    }
    return bestMatch;
}