use of org.qi4j.runtime.composite.CompositeConstraintModel in project qi4j-sdk by Qi4j.
the class CompositeAssemblyImpl method constraintsFor.
protected ValueConstraintsModel constraintsFor(Iterable<Annotation> constraintAnnotations, Type valueType, String name, boolean optional, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses, AccessibleObject accessor) {
valueType = wrapperClass(valueType);
List<AbstractConstraintModel> constraintModels = new ArrayList<>();
nextConstraint: for (Annotation constraintAnnotation : filter(translate(type(), hasAnnotation(ConstraintDeclaration.class)), constraintAnnotations)) {
// Check composite declarations first
Class<? extends Annotation> annotationType = constraintAnnotation.annotationType();
for (Class<? extends Constraint<?, ?>> constraint : constraintClasses) {
if (helper.appliesTo(constraint, annotationType, valueType)) {
constraintModels.add(new ConstraintModel(constraintAnnotation, constraint));
continue nextConstraint;
}
}
// Check the annotation itself
Constraints constraints = annotationType.getAnnotation(Constraints.class);
if (constraints != null) {
for (Class<? extends Constraint<?, ?>> constraintClass : constraints.value()) {
if (helper.appliesTo(constraintClass, annotationType, valueType)) {
constraintModels.add(new ConstraintModel(constraintAnnotation, constraintClass));
continue nextConstraint;
}
}
}
// No implementation found!
// Check if if it's a composite constraints
Iterable<Annotation> annotations = iterable(annotationType.getAnnotations());
if (matchesAny(translate(type(), hasAnnotation(ConstraintDeclaration.class)), annotations)) {
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, valueType, name, optional, constraintClasses, accessor);
CompositeConstraintModel compositeConstraintModel = new CompositeConstraintModel(constraintAnnotation, valueConstraintsModel);
constraintModels.add(compositeConstraintModel);
continue nextConstraint;
}
throw new InvalidCompositeException("Cannot find implementation of constraint @" + annotationType.getSimpleName() + " for " + valueType + " in method " + ((Member) accessor).getName() + " of composite " + types);
}
return new ValueConstraintsModel(constraintModels, name, optional);
}
Aggregations