List of usage examples for org.springframework.beans BeanUtils findDeclaredMethod
@Nullable public static Method findDeclaredMethod(Class<?> clazz, String methodName, Class<?>... paramTypes)
From source file:org.codehaus.griffon.commons.GriffonClassUtils.java
/** * <p>Work out if the specified property is readable and static. Java introspection does not * recognize this concept of static properties but Groovy does. We also consider public static fields * as static properties with no getters/setters</p> * * @param clazz The class to check for static property * @param propertyName The property name * @return true if the property with name propertyName has a static getter method */// w w w .ja va2s .c om public static boolean isStaticProperty(Class clazz, String propertyName) { Method getter = BeanUtils.findDeclaredMethod(clazz, getGetterName(propertyName), null); if (getter != null) { return isPublicStatic(getter); } else { try { Field f = clazz.getDeclaredField(propertyName); if (f != null) { return isPublicStatic(f); } } catch (NoSuchFieldException e) { return false; } } return false; }
From source file:org.codehaus.griffon.commons.GriffonClassUtils.java
/** * <p>Get a static property value, which has a public static getter or is just a public static field.</p> * * @param clazz The class to check for static property * @param name The property name// ww w . ja v a 2 s .c o m * @return The value if there is one, or null if unset OR there is no such property */ public static Object getStaticPropertyValue(Class clazz, String name) { Object value = null; Method getter = BeanUtils.findDeclaredMethod(clazz, getGetterName(name), null); try { if (getter != null) { value = getter.invoke(null, new Object[0]); } else { Field f = clazz.getDeclaredField(name); if (f != null) { value = f.get(null); } } } catch (Exception e) { value = null; } return value; }
From source file:grails.util.GrailsClassUtils.java
/** * <p>Work out if the specified property is readable and static. Java introspection does not * recognize this concept of static properties but Groovy does. We also consider public static fields * as static properties with no getters/setters</p> * * @param clazz The class to check for static property * @param propertyName The property name * @return true if the property with name propertyName has a static getter method */// ww w. ja v a 2 s .c o m @SuppressWarnings("rawtypes") public static boolean isStaticProperty(Class clazz, String propertyName) { Method getter = BeanUtils.findDeclaredMethod(clazz, getGetterName(propertyName), (Class[]) null); if (getter != null) { return isPublicStatic(getter); } try { Field f = clazz.getDeclaredField(propertyName); if (f != null) { return isPublicStatic(f); } } catch (NoSuchFieldException ignored) { // ignored } return false; }
From source file:grails.util.GrailsClassUtils.java
/** * <p>Get a static property value, which has a public static getter or is just a public static field.</p> * * @param clazz The class to check for static property * @param name The property name//from w ww .ja v a 2s .c om * @return The value if there is one, or null if unset OR there is no such property */ public static Object getStaticPropertyValue(Class<?> clazz, String name) { Method getter = BeanUtils.findDeclaredMethod(clazz, getGetterName(name), (Class[]) null); try { if (getter != null) { ReflectionUtils.makeAccessible(getter); return getter.invoke(clazz); } return getStaticFieldValue(clazz, name); } catch (Exception ignored) { // ignored } return null; }
From source file:org.codehaus.groovy.grails.commons.GrailsClassUtils.java
/** * <p>Work out if the specified property is readable and static. Java introspection does not * recognize this concept of static properties but Groovy does. We also consider public static fields * as static properties with no getters/setters</p> * * @param clazz The class to check for static property * @param propertyName The property name * @return true if the property with name propertyName has a static getter method *///from w w w .j a v a 2 s . c o m @SuppressWarnings("rawtypes") public static boolean isStaticProperty(Class clazz, String propertyName) { Method getter = BeanUtils.findDeclaredMethod(clazz, getGetterName(propertyName), null); if (getter != null) { return isPublicStatic(getter); } try { Field f = clazz.getDeclaredField(propertyName); if (f != null) { return isPublicStatic(f); } } catch (NoSuchFieldException ignored) { // ignored } return false; }
From source file:org.codehaus.groovy.grails.commons.GrailsClassUtils.java
/** * <p>Get a static property value, which has a public static getter or is just a public static field.</p> * * @param clazz The class to check for static property * @param name The property name//from ww w. ja v a 2 s .c o m * @return The value if there is one, or null if unset OR there is no such property */ public static Object getStaticPropertyValue(Class<?> clazz, String name) { Method getter = BeanUtils.findDeclaredMethod(clazz, getGetterName(name), null); try { if (getter != null) { return getter.invoke(null); } return getStaticFieldValue(clazz, name); } catch (Exception ignored) { // ignored } return null; }