use of org.apache.myfaces.cdi.wrapper.FacesValidatorCDIWrapper in project myfaces by apache.
the class ApplicationImpl method createValidator.
@Override
public final Validator createValidator(final String validatorId) throws FacesException {
Assert.notEmpty(validatorId, "validatorId");
Class<? extends Validator> validatorClass = getObjectFromClassMap(validatorId, _validatorClassMap);
if (validatorClass == null) {
String message = "Unknown validator id '" + validatorId + "'.";
log.severe(message);
throw new FacesException(message);
}
try {
if (!_cdiManagedValidatorMap.containsKey(validatorClass)) {
FacesValidator annotation = validatorClass.getAnnotation(FacesValidator.class);
if (annotation != null && annotation.managed()) {
_cdiManagedValidatorMap.put(validatorClass, true);
} else {
_cdiManagedValidatorMap.put(validatorClass, false);
}
}
boolean managed = _cdiManagedValidatorMap.get(validatorClass);
Validator validator = null;
if (managed) {
validator = new FacesValidatorCDIWrapper(validatorClass, validatorId);
_handleAttachedResourceDependencyAnnotations(getFacesContext(), ((FacesWrapper<Validator>) validator).getWrapped());
} else {
validator = createValidatorInstance(validatorClass);
_handleAttachedResourceDependencyAnnotations(getFacesContext(), validator);
}
return validator;
} catch (Exception e) {
log.log(Level.SEVERE, "Could not instantiate validator " + validatorClass, e);
throw new FacesException("Could not instantiate validator: " + validatorClass, e);
}
}
Aggregations