// process first single groups. For these we can optimise object traversal by first running all validations on the current bean
// before traversing the object.
Iterator<Group> groupIterator = validationOrder.getGroupIterator();
while ( groupIterator.hasNext() ) {
Group group = groupIterator.next();
valueContext.setCurrentGroup( group.getDefiningClass() );
validateConstraintsForCurrentGroup( context, valueContext );
if ( shouldFailFast( context ) ) {
return context.getFailingConstraints();
}
}
groupIterator = validationOrder.getGroupIterator();
while ( groupIterator.hasNext() ) {
Group group = groupIterator.next();
valueContext.setCurrentGroup( group.getDefiningClass() );
validateCascadedConstraints( context, valueContext );
if ( shouldFailFast( context ) ) {
return context.getFailingConstraints();
}
}
// now we process sequences. For sequences I have to traverse the object graph since I have to stop processing when an error occurs.
Iterator<Sequence> sequenceIterator = validationOrder.getSequenceIterator();
while ( sequenceIterator.hasNext() ) {
Sequence sequence = sequenceIterator.next();
for ( Group group : sequence.getComposingGroups() ) {
int numberOfViolations = context.getFailingConstraints().size();
valueContext.setCurrentGroup( group.getDefiningClass() );
validateConstraintsForCurrentGroup( context, valueContext );
if ( shouldFailFast( context ) ) {
return context.getFailingConstraints();
}