Java Code Examples for org.apache.commons.beanutils.MethodUtils#getAccessibleMethod()

The following examples show how to use org.apache.commons.beanutils.MethodUtils#getAccessibleMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoaderFromClass.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find a method on the specified class whose name matches methodName,
 * and whose signature is:
 * <code> public static void foo(Digester d, String patternPrefix);</code>.
 *
 * @return null if no such method exists.
 */
public static Method locateMethod(Class<?> rulesClass, String methodName) 
                        throws PluginException {

    Class<?>[] paramSpec = { Digester.class, String.class };
    Method rulesMethod = MethodUtils.getAccessibleMethod(
        rulesClass, methodName, paramSpec);
        
    return rulesMethod;
}
 
Example 2
Source File: JpaUtil.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
public <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) {
    try {
        Method m = MethodUtils.getAccessibleMethod(mt.getJavaType(), "get" + WordUtils.capitalize(attr.getName()), (Class<?>) null);
        if (m != null && m.getAnnotation(Id.class) != null) {
            return true;
        }

        Field field = mt.getJavaType().getField(attr.getName());
        return field.getAnnotation(Id.class) != null;
    } catch (Exception e) {
        return false;
    }
}
 
Example 3
Source File: LoadTimeWeavableTestRunner.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void setTestName(final Object test, final Method testMethod) throws Exception {
    String name = testMethod == null ? "" : testMethod.getName();
    final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName",
            new Class[]{String.class});
    if (setNameMethod != null) {
        setNameMethod.invoke(test, name);
    }
}
 
Example 4
Source File: RiceUnitTestClassRunner.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void setTestName(final Object test, final Method testMethod) throws Exception {
        String name = testMethod == null ? "" : testMethod.getName();
        final Method setNameMethod = MethodUtils.getAccessibleMethod(test.getClass(), "setName", new Class[]{String.class});
        if (setNameMethod != null) {
            setNameMethod.invoke(test, name);
        }
}
 
Example 5
Source File: Beans.java    From components with Apache License 2.0 2 votes vote down vote up
/**
 * <p>Return an accessible property getter method for this property,
 * if there is one; otherwise return <code>null</code>.</p>
 *
 * @param clazz The class of the read method will be invoked on
 * @param descriptor Property descriptor to return a getter for
 * @return The read method
 */
Method getReadMethod(Class clazz, PropertyInfo descriptor) {
    return (MethodUtils.getAccessibleMethod(clazz, descriptor.getReadMethodName(), EMPTY_CLASS_PARAMETERS));
}
 
Example 6
Source File: Beans.java    From components with Apache License 2.0 2 votes vote down vote up
/**
 * <p>Return an accessible property setter method for this property,
 * if there is one; otherwise return <code>null</code>.</p>
 *
 * @param clazz The class of the read method will be invoked on
 * @param descriptor Property descriptor to return a setter for
 * @return The write method
 */
Method getWriteMethod(Class clazz, PropertyInfo descriptor) {
    return (MethodUtils.getAccessibleMethod(clazz, descriptor.getWriteMethodName(),
            new Class[]{descriptor.getWriteType()}));
}