Example usage for org.springframework.beans CachedIntrospectionResults getPropertyDescriptor

List of usage examples for org.springframework.beans CachedIntrospectionResults getPropertyDescriptor

Introduction

In this page you can find the example usage for org.springframework.beans CachedIntrospectionResults getPropertyDescriptor.

Prototype

@Nullable
    PropertyDescriptor getPropertyDescriptor(String name) 

Source Link

Usage

From source file:org.springframework.beans.BeanUtils.java

/**
 * Retrieve the JavaBeans {@code PropertyDescriptors} for the given property.
 * @param clazz the Class to retrieve the PropertyDescriptor for
 * @param propertyName the name of the property
 * @return the corresponding PropertyDescriptor, or {@code null} if none
 * @throws BeansException if PropertyDescriptor lookup fails
 *///from ww w.  j a v a  2  s  . com
@Nullable
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName)
        throws BeansException {

    CachedIntrospectionResults cr = CachedIntrospectionResults.forClass(clazz);
    return cr.getPropertyDescriptor(propertyName);
}

From source file:org.springframework.beans.BeanWrapperImpl.java

/**
 * Convert the given value for the specified property to the latter's type.
 * <p>This method is only intended for optimizations in a BeanFactory.
 * Use the {@code convertIfNecessary} methods for programmatic conversion.
 * @param value the value to convert//from w ww .java 2 s.c  om
 * @param propertyName the target property
 * (note that nested or indexed properties are not supported here)
 * @return the new value, possibly the result of type conversion
 * @throws TypeMismatchException if type conversion failed
 */
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException {
    CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults();
    PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);
    if (pd == null) {
        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                "No property '" + propertyName + "' found");
    }
    TypeDescriptor td = cachedIntrospectionResults.getTypeDescriptor(pd);
    if (td == null) {
        td = cachedIntrospectionResults.addTypeDescriptor(pd, new TypeDescriptor(property(pd)));
    }
    return convertForProperty(propertyName, null, value, td);
}