public class ConstraintValidatorContextImpl extends Object implements HibernateConstraintValidatorContext
ConstraintValidatorContext.ConstraintViolationBuilder
Constructor and Description |
---|
ConstraintValidatorContextImpl(List<String> methodParameterNames,
TimeProvider timeProvider,
PathImpl propertyPath,
ConstraintDescriptor<?> constraintDescriptor) |
public ConstraintValidatorContextImpl(List<String> methodParameterNames, TimeProvider timeProvider, PathImpl propertyPath, ConstraintDescriptor<?> constraintDescriptor)
public final void disableDefaultConstraintViolation()
disableDefaultConstraintViolation
in interface ConstraintValidatorContext
public final String getDefaultConstraintMessageTemplate()
getDefaultConstraintMessageTemplate
in interface ConstraintValidatorContext
public final ConstraintValidatorContext.ConstraintViolationBuilder buildConstraintViolationWithTemplate(String messageTemplate)
buildConstraintViolationWithTemplate
in interface ConstraintValidatorContext
public <T> T unwrap(Class<T> type)
unwrap
in interface ConstraintValidatorContext
public HibernateConstraintValidatorContext addExpressionVariable(String name, Object value)
HibernateConstraintValidatorContext
ConstraintViolationBuilder
.
To create multiple constraint violations with different variable values, this method can be called
between successive calls to ConstraintValidatorContext.ConstraintViolationBuilder.addConstraintViolation()
.
For example:
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
HibernateConstraintValidatorContext context = constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class );
context.addExpressionVariable( "foo", "bar" );
context.buildConstraintViolationWithTemplate( "${foo}" )
.addConstraintViolation();
context.addExpressionVariable( "foo", "snafu" );
context.buildConstraintViolationWithTemplate( "${foo}" )
.addConstraintViolation();
return false;
}
addExpressionVariable
in interface HibernateConstraintValidatorContext
name
- the name under which to bind the expression variable, cannot be null
value
- the value to be bound to the specified namepublic HibernateConstraintValidatorContext addMessageParameter(String name, Object value)
HibernateConstraintValidatorContext
ConstraintViolationBuilder
.
To create multiple constraint violations with different variable values, this method can be called
between successive calls to ConstraintValidatorContext.ConstraintViolationBuilder.addConstraintViolation()
.
For example:
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
HibernateConstraintValidatorContext context = constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class );
context.addMessageParameter( "foo", "bar" );
context.buildConstraintViolationWithTemplate( "{foo}" )
.addConstraintViolation();
context.addMessageParameter( "foo", "snafu" );
context.buildConstraintViolationWithTemplate( "{foo}" )
.addConstraintViolation();
return false;
}
addMessageParameter
in interface HibernateConstraintValidatorContext
name
- the name under which to bind the parameter, cannot be null
value
- the value to be bound to the specified namepublic TimeProvider getTimeProvider()
HibernateConstraintValidatorContext
Future
and Past
constraints.getTimeProvider
in interface HibernateConstraintValidatorContext
null
. If no specific provider has been
configured during bootstrap, a default implementation using the current system time and the current
default time zone will be returned.public HibernateConstraintValidatorContext withDynamicPayload(Object violationContext)
HibernateConstraintValidatorContext
javax.validation.ConstraintViolation
has to be serialized.withDynamicPayload
in interface HibernateConstraintValidatorContext
violationContext
- an object representing additional information about the violationpublic final ConstraintDescriptor<?> getConstraintDescriptor()
public final List<ConstraintViolationCreationContext> getConstraintViolationCreationContexts()
Copyright © 2007-2019 Red Hat, Inc. All Rights Reserved