org.hibernate.validator.internal.engine.constraintvalidation

## Class ConstraintValidatorContextImpl

- java.lang.Object
- - org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl

- All Implemented Interfaces:
    ConstraintValidatorContext, HibernateConstraintValidatorContext

      public class ConstraintValidatorContextImpl
      extends Object
      implements HibernateConstraintValidatorContext

  Author:
    Hardy Ferentschik, Gunnar Morling

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface javax.validation.ConstraintValidatorContext

      `ConstraintValidatorContext.ConstraintViolationBuilder`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConstraintValidatorContextImpl(List<String> methodParameterNames, PathImpl propertyPath, ConstraintDescriptor<?> constraintDescriptor)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `HibernateConstraintValidatorContext` | `addExpressionVariable(String name, Object value)` Allows to set an additional named variable which can be interpolated in the constraint violation message.
    `ConstraintValidatorContext.ConstraintViolationBuilder` | `buildConstraintViolationWithTemplate(String messageTemplate)`
    `void` | `disableDefaultConstraintViolation()`
    `ConstraintDescriptor<?>` | `getConstraintDescriptor()`
    `List<ConstraintViolationCreationContext>` | `getConstraintViolationCreationContexts()`
    `String` | `getDefaultConstraintMessageTemplate()`
    `List<String>` | `getMethodParameterNames()`
    `<T> T` | `unwrap(Class<T> type)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ConstraintValidatorContextImpl

          public ConstraintValidatorContextImpl(List<String> methodParameterNames,
                                        PathImpl propertyPath,
                                        ConstraintDescriptor<?> constraintDescriptor)

  - ### Method Detail

    - #### disableDefaultConstraintViolation

          public final void disableDefaultConstraintViolation()

      Specified by:
        `disableDefaultConstraintViolation` in interface `ConstraintValidatorContext`

    - #### getDefaultConstraintMessageTemplate

          public final String getDefaultConstraintMessageTemplate()

      Specified by:
        `getDefaultConstraintMessageTemplate` in interface `ConstraintValidatorContext`

    - #### buildConstraintViolationWithTemplate

          public final ConstraintValidatorContext.ConstraintViolationBuilder buildConstraintViolationWithTemplate(String messageTemplate)

      Specified by:
        `buildConstraintViolationWithTemplate` in interface `ConstraintValidatorContext`

    - #### unwrap

          public <T> T unwrap(Class<T> type)

      Specified by:
        `unwrap` in interface `ConstraintValidatorContext`

    - #### addExpressionVariable

          public HibernateConstraintValidatorContext addExpressionVariable(String name,
                                                                  Object value)

      Description copied from interface: `HibernateConstraintValidatorContext`
      Allows to set an additional named variable which can be interpolated in the constraint violation message. The variable will be available for interpolation for all constraint violations generated for this constraint. This includes the default one as well as all violations created by the `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;
            }

      Specified by:
        `addExpressionVariable` in interface `HibernateConstraintValidatorContext`
      Parameters:
        `name` - the name under which to bind the parameter, cannot be `null`
        `value` - the value to be bound to the specified name
      Returns:
        a reference to itself to allow method chaining

    - #### getConstraintDescriptor

          public final ConstraintDescriptor<?> getConstraintDescriptor()

    - #### getConstraintViolationCreationContexts

          public final List<ConstraintViolationCreationContext> getConstraintViolationCreationContexts()

    - #### getMethodParameterNames

          public List<String> getMethodParameterNames()

Copyright © 2007-2014 Red Hat, Inc. All Rights Reserved