Example usage for org.springframework.beans CachedIntrospectionResults getTypeDescriptor

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

Introduction

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

Prototype

@Nullable
    TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) 

Source Link

Usage

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/*  w ww .  j  a v a2s . 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);
}