use of org.hibernate.validator.internal.metadata.facets.Cascadable in project hibernate-validator by hibernate.
the class ValidatorImpl method validateCascadedConstraints.
/**
* Validates all cascaded constraints for the given bean using the current group set in the execution context.
* This method must always be called after validateConstraints for the same context.
*
* @param validationContext The execution context
* @param valueContext Collected information for single validation
*/
private void validateCascadedConstraints(BaseBeanValidationContext<?> validationContext, ValueContext<?, Object> valueContext) {
Validatable validatable = valueContext.getCurrentValidatable();
BeanValueContext.ValueState<Object> originalValueState = valueContext.getCurrentValueState();
for (Cascadable cascadable : validatable.getCascadables()) {
valueContext.appendNode(cascadable);
if (isCascadeRequired(validationContext, valueContext.getCurrentBean(), valueContext.getPropertyPath(), cascadable.getConstraintLocationKind())) {
Object value = getCascadableValue(validationContext, valueContext.getCurrentBean(), cascadable);
CascadingMetaData cascadingMetaData = cascadable.getCascadingMetaData();
if (value != null) {
CascadingMetaData effectiveCascadingMetaData = cascadingMetaData.addRuntimeContainerSupport(valueExtractorManager, value.getClass());
// validate cascading on the annotated object
if (effectiveCascadingMetaData.isCascading()) {
validateCascadedAnnotatedObjectForCurrentGroup(value, validationContext, valueContext, effectiveCascadingMetaData);
}
if (effectiveCascadingMetaData.isContainer()) {
ContainerCascadingMetaData containerCascadingMetaData = effectiveCascadingMetaData.as(ContainerCascadingMetaData.class);
if (containerCascadingMetaData.hasContainerElementsMarkedForCascading()) {
// validate cascading on the container elements
validateCascadedContainerElementsForCurrentGroup(value, validationContext, valueContext, containerCascadingMetaData.getContainerElementTypesCascadingMetaData());
}
}
}
}
// reset the value context
valueContext.resetValueState(originalValueState);
}
}
Aggregations