Example usage for org.springframework.beans ConfigurablePropertyAccessor isWritableProperty

List of usage examples for org.springframework.beans ConfigurablePropertyAccessor isWritableProperty

Introduction

In this page you can find the example usage for org.springframework.beans ConfigurablePropertyAccessor isWritableProperty.

Prototype

boolean isWritableProperty(String propertyName);

Source Link

Document

Determine whether the specified property is writable.

Usage

From source file:org.brushingbits.jnap.validation.constraints.AbstractConstraintValidator.java

/**
 * This method copies all the annotation properties to fields with the same name.
 * /*from   w w  w . j  a va 2  s. c o  m*/
 * @param constraintAnnotation This constraint annotation.
 * @see PropertyAccessorFactory
 */
protected void bindParameters(A constraintAnnotation) {
    Class<?> annotationClass = constraintAnnotation.getClass();
    Method[] methods = annotationClass.getDeclaredMethods();
    ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(this);
    try {
        for (Method method : methods) {
            String methodName = method.getName();
            if (accessor.isWritableProperty(methodName)) {
                accessor.setPropertyValue(methodName,
                        method.invoke(constraintAnnotation, ArrayUtils.EMPTY_OBJECT_ARRAY));
            }
        }
    } catch (Exception e) {
        ReflectionUtils.handleReflectionException(e);
    }
}

From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java

private boolean isNullAndWritableProperty(ConfigurablePropertyAccessor accessor, String propertyName) {
    return accessor.isWritableProperty(propertyName)
            && (accessor.isReadableProperty(propertyName) && accessor.getPropertyValue(propertyName) == null);
}