private static String forceValue ( int type , String value ) throws AttributeBadValueException { try { dispatchCheckValue ( type , value ) ; } catch ( AttributeBadValueException abe ) { if ( type == BYTE ) { // Try again: allow e.g. negative byte values short val = Short . parseShort ( value ) ; if ( val > 255 && val < - 128 ) throw new AttributeBadValueException ( "Cannot convert to byte: " + value ) ; value = Integer . toString ( ( val & 0xFF ) ) ; } } return value ; }
Check if the value is legal for a given type and try to convert to specified type .