}
if (violations != null && !violations.isEmpty()) {
ValidatorException toThrow;
if (1 == violations.size()) {
ConstraintViolation violation = violations.iterator().next();
toThrow = new ValidatorException(MessageFactory.getMessage(
context,
MESSAGE_ID,
violation.getMessage(),
MessageFactory.getLabel(context, component)));
} else {
Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(
violations.size());
for (ConstraintViolation violation : violations) {
messages.add(MessageFactory.getMessage(context,
MESSAGE_ID,
violation.getMessage(),
MessageFactory.getLabel(
context,
component)));
}
toThrow = new ValidatorException(messages);