Search in sources :

Example 1 with ContainerCascadingMetaData

use of org.hibernate.validator.internal.metadata.aggregated.ContainerCascadingMetaData in project hibernate-validator by hibernate.

the class ValidatorImpl method validateCascadedContainerElementsForCurrentGroup.

private void validateCascadedContainerElementsForCurrentGroup(Object value, BaseBeanValidationContext<?> validationContext, ValueContext<?, ?> valueContext, List<ContainerCascadingMetaData> containerElementTypesCascadingMetaData) {
    for (ContainerCascadingMetaData cascadingMetaData : containerElementTypesCascadingMetaData) {
        if (!cascadingMetaData.isMarkedForCascadingOnAnnotatedObjectOrContainerElements()) {
            continue;
        }
        ValueExtractorDescriptor extractor = valueExtractorManager.getMaximallySpecificAndRuntimeContainerElementCompliantValueExtractor(cascadingMetaData.getEnclosingType(), cascadingMetaData.getTypeParameter(), value.getClass(), cascadingMetaData.getValueExtractorCandidates());
        if (extractor == null) {
            throw LOG.getNoValueExtractorFoundForTypeException(cascadingMetaData.getEnclosingType(), cascadingMetaData.getTypeParameter(), value.getClass());
        }
        CascadingValueReceiver receiver = new CascadingValueReceiver(validationContext, valueContext, cascadingMetaData);
        ValueExtractorHelper.extractValues(extractor, value, receiver);
    }
}
Also used : ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor) ContainerCascadingMetaData(org.hibernate.validator.internal.metadata.aggregated.ContainerCascadingMetaData)

Example 2 with ContainerCascadingMetaData

use of org.hibernate.validator.internal.metadata.aggregated.ContainerCascadingMetaData 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

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