Example usage for org.springframework.beans CachedIntrospectionResults addTypeDescriptor

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

Introduction

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

Prototype

TypeDescriptor addTypeDescriptor(PropertyDescriptor pd, TypeDescriptor td) 

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 w  w. j  ava  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);
}