if ( returnType.getName().equals( byte.class.getName() ) ) {
try {
returnValue = Byte.parseByte( value );
}
catch ( NumberFormatException e ) {
throw new ValidationException( "Invalid byte format", e );
}
}
else if ( returnType.getName().equals( short.class.getName() ) ) {
try {
returnValue = Short.parseShort( value );
}
catch ( NumberFormatException e ) {
throw new ValidationException( "Invalid short format", e );
}
}
else if ( returnType.getName().equals( int.class.getName() ) ) {
try {
returnValue = Integer.parseInt( value );
}
catch ( NumberFormatException e ) {
throw new ValidationException( "Invalid int format", e );
}
}
else if ( returnType.getName().equals( long.class.getName() ) ) {
try {
returnValue = Long.parseLong( value );
}
catch ( NumberFormatException e ) {
throw new ValidationException( "Invalid long format", e );
}
}
else if ( returnType.getName().equals( float.class.getName() ) ) {
try {
returnValue = Float.parseFloat( value );
}
catch ( NumberFormatException e ) {
throw new ValidationException( "Invalid float format", e );
}
}
else if ( returnType.getName().equals( double.class.getName() ) ) {
try {
returnValue = Double.parseDouble( value );
}
catch ( NumberFormatException e ) {
throw new ValidationException( "Invalid double format", e );
}
}
else if ( returnType.getName().equals( boolean.class.getName() ) ) {
returnValue = Boolean.parseBoolean( value );
}
else if ( returnType.getName().equals( char.class.getName() ) ) {
if ( value.length() != 1 ) {
throw new ValidationException( "Invalid char value: " + value );
}
returnValue = value.charAt( 0 );
}
else if ( returnType.getName().equals( String.class.getName() ) ) {
returnValue = value;
}
else if ( returnType.getName().equals( Class.class.getName() ) ) {
returnValue = ReflectionHelper.loadClass( value, this.getClass() );
}
else {
try {
@SuppressWarnings("unchecked")
Class<Enum> enumClass = (Class<Enum>) returnType;
returnValue = Enum.valueOf( enumClass, value );
}
catch ( ClassCastException e ) {
throw new ValidationException(
"Invalid return type: " + returnType + ". Should be a enumeration type.", e
);
}
}
return returnValue;