Search in sources :

Example 1 with ValueExtractorDescriptor

use of org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor 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 ValueExtractorDescriptor

use of org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor in project hibernate-validator by hibernate.

the class AbstractConfigurationImpl method applyXmlSettings.

private void applyXmlSettings(ValidationBootstrapParameters xmlParameters) {
    validationBootstrapParameters.setProviderClass(xmlParameters.getProviderClass());
    if (validationBootstrapParameters.getMessageInterpolator() == null) {
        if (xmlParameters.getMessageInterpolator() != null) {
            validationBootstrapParameters.setMessageInterpolator(xmlParameters.getMessageInterpolator());
        }
    }
    if (validationBootstrapParameters.getTraversableResolver() == null) {
        if (xmlParameters.getTraversableResolver() != null) {
            validationBootstrapParameters.setTraversableResolver(xmlParameters.getTraversableResolver());
        } else {
            validationBootstrapParameters.setTraversableResolver(getDefaultTraversableResolver());
        }
    }
    if (validationBootstrapParameters.getConstraintValidatorFactory() == null) {
        if (xmlParameters.getConstraintValidatorFactory() != null) {
            validationBootstrapParameters.setConstraintValidatorFactory(xmlParameters.getConstraintValidatorFactory());
        } else {
            validationBootstrapParameters.setConstraintValidatorFactory(defaultConstraintValidatorFactory);
        }
    }
    if (validationBootstrapParameters.getParameterNameProvider() == null) {
        if (xmlParameters.getParameterNameProvider() != null) {
            validationBootstrapParameters.setParameterNameProvider(xmlParameters.getParameterNameProvider());
        } else {
            validationBootstrapParameters.setParameterNameProvider(defaultParameterNameProvider);
        }
    }
    if (validationBootstrapParameters.getClockProvider() == null) {
        if (xmlParameters.getClockProvider() != null) {
            validationBootstrapParameters.setClockProvider(xmlParameters.getClockProvider());
        } else {
            validationBootstrapParameters.setClockProvider(defaultClockProvider);
        }
    }
    if (validationBootstrapParameters.getPropertyNodeNameProvider() == null) {
        if (xmlParameters.getPropertyNodeNameProvider() != null) {
            validationBootstrapParameters.setPropertyNodeNameProvider(xmlParameters.getPropertyNodeNameProvider());
        } else {
            validationBootstrapParameters.setPropertyNodeNameProvider(defaultPropertyNodeNameProvider);
        }
    }
    for (ValueExtractorDescriptor valueExtractorDescriptor : xmlParameters.getValueExtractorDescriptors().values()) {
        validationBootstrapParameters.addValueExtractorDescriptor(valueExtractorDescriptor);
    }
    validationBootstrapParameters.addAllMappings(xmlParameters.getMappings());
    configurationStreams.addAll(xmlParameters.getMappings());
    for (Map.Entry<String, String> entry : xmlParameters.getConfigProperties().entrySet()) {
        if (validationBootstrapParameters.getConfigProperties().get(entry.getKey()) == null) {
            validationBootstrapParameters.addConfigProperty(entry.getKey(), entry.getValue());
        }
    }
}
Also used : ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ValueExtractorDescriptor

use of org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor in project hibernate-validator by hibernate.

the class AbstractConfigurationImpl method buildValidatorFactory.

@Override
public final ValidatorFactory buildValidatorFactory() {
    loadValueExtractorsFromServiceLoader();
    parseValidationXml();
    for (ValueExtractorDescriptor valueExtractorDescriptor : valueExtractorDescriptors.values()) {
        validationBootstrapParameters.addValueExtractorDescriptor(valueExtractorDescriptor);
    }
    ValidatorFactory factory = null;
    try {
        if (isSpecificProvider()) {
            factory = validationBootstrapParameters.getProvider().buildValidatorFactory(this);
        } else {
            final Class<? extends ValidationProvider<?>> providerClass = validationBootstrapParameters.getProviderClass();
            if (providerClass != null) {
                for (ValidationProvider<?> provider : providerResolver.getValidationProviders()) {
                    if (providerClass.isAssignableFrom(provider.getClass())) {
                        factory = provider.buildValidatorFactory(this);
                        break;
                    }
                }
                if (factory == null) {
                    throw LOG.getUnableToFindProviderException(providerClass);
                }
            } else {
                List<ValidationProvider<?>> providers = providerResolver.getValidationProviders();
                // I run therefore I am
                assert providers.size() != 0;
                factory = providers.get(0).buildValidatorFactory(this);
            }
        }
    } finally {
        // close all input streams opened by this configuration
        for (InputStream in : configurationStreams) {
            try {
                in.close();
            } catch (IOException io) {
                LOG.unableToCloseInputStream();
            }
        }
    }
    return factory;
}
Also used : ValidationProvider(jakarta.validation.spi.ValidationProvider) ValidatorFactory(jakarta.validation.ValidatorFactory) ConstraintValidatorFactory(jakarta.validation.ConstraintValidatorFactory) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor) IOException(java.io.IOException)

Example 4 with ValueExtractorDescriptor

use of org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor in project hibernate-validator by hibernate.

the class ValidatorFactoryBean method createValidationXmlValueExtractors.

private Set<ValueExtractorDescriptor> createValidationXmlValueExtractors(Configuration<?> config) {
    BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
    Set<String> valueExtractorFqcns = bootstrapConfiguration.getValueExtractorClassNames();
    @SuppressWarnings("unchecked") Set<ValueExtractorDescriptor> valueExtractorDescriptors = valueExtractorFqcns.stream().map(fqcn -> createInstance((Class<? extends ValueExtractor<?>>) run(LoadClass.action(fqcn, null)))).map(ve -> new ValueExtractorDescriptor(ve)).collect(Collectors.toSet());
    return valueExtractorDescriptors;
}
Also used : GetClassLoader(org.hibernate.validator.internal.util.privilegedactions.GetClassLoader) ConstraintValidatorFactory(jakarta.validation.ConstraintValidatorFactory) ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor) BeanNames(org.hibernate.validator.cdi.spi.BeanNames) ClassHierarchyHelper(org.hibernate.validator.internal.util.classhierarchy.ClassHierarchyHelper) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) TraversableResolver(jakarta.validation.TraversableResolver) Function(java.util.function.Function) Instance(jakarta.enterprise.inject.Instance) ValidatorFactory(jakarta.validation.ValidatorFactory) Bean(jakarta.enterprise.inject.spi.Bean) HashSet(java.util.HashSet) ValueExtractor(jakarta.validation.valueextraction.ValueExtractor) CollectionHelper.newHashSet(org.hibernate.validator.internal.util.CollectionHelper.newHashSet) GetInstancesFromServiceLoader(org.hibernate.validator.internal.util.privilegedactions.GetInstancesFromServiceLoader) Map(java.util.Map) PassivationCapable(jakarta.enterprise.inject.spi.PassivationCapable) CollectionHelper(org.hibernate.validator.internal.util.CollectionHelper) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Validation(jakarta.validation.Validation) BootstrapConfiguration(jakarta.validation.BootstrapConfiguration) BeanMetaDataClassNormalizer(org.hibernate.validator.metadata.BeanMetaDataClassNormalizer) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) NamedLiteral(jakarta.enterprise.inject.literal.NamedLiteral) LoadClass(org.hibernate.validator.internal.util.privilegedactions.LoadClass) Set(java.util.Set) CreationalContext(jakarta.enterprise.context.spi.CreationalContext) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) ParameterNameProvider(jakarta.validation.ParameterNameProvider) List(java.util.List) ClockProvider(jakarta.validation.ClockProvider) MessageInterpolator(jakarta.validation.MessageInterpolator) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) HibernateValidatorConfiguration(org.hibernate.validator.HibernateValidatorConfiguration) AccessController(java.security.AccessController) Collections(java.util.Collections) IgnoreForbiddenApisErrors(org.hibernate.validator.internal.IgnoreForbiddenApisErrors) Configuration(jakarta.validation.Configuration) ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor) BootstrapConfiguration(jakarta.validation.BootstrapConfiguration) LoadClass(org.hibernate.validator.internal.util.privilegedactions.LoadClass) ValueExtractor(jakarta.validation.valueextraction.ValueExtractor)

Example 5 with ValueExtractorDescriptor

use of org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor in project hibernate-validator by hibernate.

the class ValidatorContextImpl method addValueExtractor.

@Override
public HibernateValidatorContext addValueExtractor(ValueExtractor<?> extractor) {
    ValueExtractorDescriptor descriptor = new ValueExtractorDescriptor(extractor);
    ValueExtractorDescriptor previous = valueExtractorDescriptors.put(descriptor.getKey(), descriptor);
    if (previous != null) {
        throw LOG.getValueExtractorForTypeAndTypeUseAlreadyPresentException(extractor, previous.getValueExtractor());
    }
    return this;
}
Also used : ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor)

Aggregations

ValueExtractorDescriptor (org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor)10 ValueExtractor (jakarta.validation.valueextraction.ValueExtractor)3 Map (java.util.Map)3 ConstraintValidatorFactory (jakarta.validation.ConstraintValidatorFactory)2 ValidatorFactory (jakarta.validation.ValidatorFactory)2 Annotation (java.lang.annotation.Annotation)2 Type (java.lang.reflect.Type)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ContainerClassTypeParameterAndExtractor (org.hibernate.validator.internal.metadata.core.MetaConstraint.ContainerClassTypeParameterAndExtractor)2 ResolvedType (com.fasterxml.classmate.ResolvedType)1 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)1 CreationalContext (jakarta.enterprise.context.spi.CreationalContext)1 Instance (jakarta.enterprise.inject.Instance)1 NamedLiteral (jakarta.enterprise.inject.literal.NamedLiteral)1 Bean (jakarta.enterprise.inject.spi.Bean)1 BeanManager (jakarta.enterprise.inject.spi.BeanManager)1