// if a ValidatorFactory already exists, only inject it's ConstraintValidatorFactory if required
if (!beanManager.getBeans(ValidatorFactory.class).isEmpty())
{
ValidatorFactory validatorFactory = getReference(beanManager, ValidatorFactory.class);
ConstraintValidatorFactory constraintValidatorFactory = validatorFactory.getConstraintValidatorFactory();
if(constraintValidatorFactory instanceof InjectingConstraintValidatorFactory) {
inject(beanManager, InjectingConstraintValidatorFactory.class, (InjectingConstraintValidatorFactory)constraintValidatorFactory);
}
return;
}
abd.addBean(new Bean<ValidatorFactory>()
{
@Override
public Class<?> getBeanClass()
{
return ValidatorFactory.class;
}
@Override
public Set<InjectionPoint> getInjectionPoints()
{
return Collections.emptySet();
}
@Override
public String getName()
{
return "validatorFactory";
}
@SuppressWarnings("serial")
@Override
public Set<Annotation> getQualifiers()
{
Set<Annotation> qualifiers = new HashSet<Annotation>();
qualifiers.add(new AnnotationLiteral<Default>()
{
});
qualifiers.add(new AnnotationLiteral<Any>()
{
});
return qualifiers;
}
@Override
public Class<? extends Annotation> getScope()
{
return ApplicationScoped.class;
}
@Override
public Set<Class<? extends Annotation>> getStereotypes()
{
return Collections.emptySet();
}
@Override
public Set<Type> getTypes()
{
Set<Type> types = new HashSet<Type>();
types.add(ValidatorFactory.class);
types.add(Object.class);
return types;
}
@Override
public boolean isAlternative()
{
return false;
}
@Override
public boolean isNullable()
{
return false;
}
@Override
public ValidatorFactory create(CreationalContext<ValidatorFactory> ctx)
{
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
ConstraintValidatorFactory constraintValidatorFactory = validatorFactory.getConstraintValidatorFactory();
if(constraintValidatorFactory instanceof InjectingConstraintValidatorFactory) {
inject(beanManager, InjectingConstraintValidatorFactory.class, (InjectingConstraintValidatorFactory)constraintValidatorFactory);
}
return validatorFactory;