Search in sources :

Example 1 with CascadingMetaData

use of org.hibernate.validator.internal.metadata.aggregated.CascadingMetaData 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);
    }
}
Also used : Cascadable(org.hibernate.validator.internal.metadata.facets.Cascadable) CascadingMetaData(org.hibernate.validator.internal.metadata.aggregated.CascadingMetaData) ContainerCascadingMetaData(org.hibernate.validator.internal.metadata.aggregated.ContainerCascadingMetaData) Validatable(org.hibernate.validator.internal.metadata.facets.Validatable) BeanValueContext(org.hibernate.validator.internal.engine.valuecontext.BeanValueContext) ContainerCascadingMetaData(org.hibernate.validator.internal.metadata.aggregated.ContainerCascadingMetaData)

Aggregations

BeanValueContext (org.hibernate.validator.internal.engine.valuecontext.BeanValueContext)1 CascadingMetaData (org.hibernate.validator.internal.metadata.aggregated.CascadingMetaData)1 ContainerCascadingMetaData (org.hibernate.validator.internal.metadata.aggregated.ContainerCascadingMetaData)1 Cascadable (org.hibernate.validator.internal.metadata.facets.Cascadable)1 Validatable (org.hibernate.validator.internal.metadata.facets.Validatable)1