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);
}
}
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);
}
}
Aggregations