protected Object initPropertyValue ( String pValue , String pType , String pFormat ) throws ClassNotFoundException { // System.out.println("pValue=" + pValue + " pType=" + pType // + " pFormat=" + pFormat); // No value to convert if ( pValue == null ) { return null ; } // No conversion needed for Strings if ( ( pType == null ) || pType . equals ( "String" ) || pType . equals ( "java.lang.String" ) ) { return pValue ; } Object value ; if ( pType . equals ( "Date" ) || pType . equals ( "java.util.Date" ) ) { // Special parser needed try { // Parse date through StringUtil if ( pFormat == null ) { value = StringUtil . toDate ( pValue , sDefaultFormat ) ; } else { value = StringUtil . toDate ( pValue , new SimpleDateFormat ( pFormat ) ) ; } } catch ( IllegalArgumentException e ) { // Not parseable... throw e ; } // Return return value ; } else if ( pType . equals ( "java.sql.Timestamp" ) ) { // Special parser needed try { // Parse timestamp through StringUtil value = StringUtil . toTimestamp ( pValue ) ; } catch ( IllegalArgumentException e ) { // Not parseable... throw new RuntimeException ( e . getMessage ( ) ) ; } // Return return value ; } else { int dot = pType . indexOf ( "." ) ; if ( dot < 0 ) { pType = "java.lang." + pType ; } // Get class Class cl = Class . forName ( pType ) ; // Try to create instance from <Constructor>(String) value = createInstance ( cl , pValue ) ; if ( value == null ) { // createInstance failed for some reason // Try to invoke the static method valueof(String) value = invokeStaticMethod ( cl , "valueOf" , pValue ) ; // If the value is still null, well, then I cannot help... } } // Return return value ; }
Initializes the value of a property .