Validator validator = null;
// let one of the SPI implementations build the validator
Iterator<ValidatorProvider> providers = ServiceLoader.load(ValidatorProvider.class).iterator();
while (providers.hasNext()) {
ValidatorProvider provider = providers.next();
if (targetType != null) {
validator = provider.getByTargetType(targetType);
}
else if (validatorType != null) {
validator = provider.getByValidatorType(validatorType);
}
else {
validator = provider.getByValidatorId(validatorId);
}
if (validator != null) {
break;
}