public void validateOpts ( Object instance ) { final Set < ConstraintViolation < Object > > set = validator . validate ( instance ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( ConstraintViolation < Object > violation : set ) { final Path path = violation . getPropertyPath ( ) ; final String msg = violation . getMessage ( ) ; sb . append ( path . toString ( ) ) . append ( " " ) . append ( msg ) . append ( ". " ) ; } if ( sb . length ( ) > 0 ) { // is ConstraintViolationException more appropriate, // letting user choose their error message? throw new ValidationException ( OPT_VIOLATION_MSG + ": " + sb . toString ( ) ) ; } }
This method will only be called if we know that JSR 303 1 . 0 Bean Validation API and compliant implementation are available on classpath .