public static Object convertValue ( String text , String typeName ) throws ClassNotFoundException , IntrospectionException { // see if it is a primitive type first Class < ? > typeClass = Classes . getPrimitiveTypeForName ( typeName ) ; if ( typeClass == null ) { ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; typeClass = loader . loadClass ( typeName ) ; } PropertyEditor editor = PropertyEditorManager . findEditor ( typeClass ) ; if ( editor == null ) { throw new IntrospectionException ( "No property editor for type=" + typeClass ) ; } editor . setAsText ( text ) ; return editor . getValue ( ) ; }
Convert a string value into the true value for typeName using the PropertyEditor associated with typeName .