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