Class ValidatorImpl

    • Constructor Summary

      Constructors 
      Constructor Description
      ValidatorImpl()
      Default constructor.
      ValidatorImpl​(jakarta.validation.ValidatorFactory validatorFactory, jakarta.persistence.ValidationMode mode)
      Type-specific constructor Returns an Exception if a Validator could not be created.
      ValidatorImpl​(Configuration conf)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addValidationGroup​(java.lang.Integer event, java.lang.Class<?>... validationGroup)
      Add a validation group for a specified event.
      void addValidationGroup​(java.lang.String validationGroupName, java.lang.Class<?>... vgs)
      Add a validation group for the specific property.
      void addValidationGroup​(java.lang.String validationGroupName, java.lang.String group)
      Add the validation group(s) for the specified event.
      jakarta.validation.metadata.BeanDescriptor getConstraintsForClass​(java.lang.Class<?> cls)
      Returns the validation constraints for the specified class
      java.lang.Class<?>[] getValidationGroup​(java.lang.Integer event)
      Return the validation groups to be validated for a specified event
      boolean isValidating​(java.lang.Integer event)
      Returns whether the Validator is validating for the specified event.
      <T> ValidationException validate​(T arg0, int event)
      Validates a given instance
      <T> ValidationException validateProperty​(T arg0, java.lang.String property, int event)
      Validates a property of a given instance
      <T> ValidationException validateValue​(java.lang.Class<T> arg0, java.lang.String arg1, java.lang.Object arg2, int event)
      Validates a value based upon the constraints applied to a given class attribute.
      <T> boolean validating​(T arg0, int event)
      Returns whether validation is active for the given event.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ValidatorImpl

        public ValidatorImpl()
        Default constructor. Builds a default validator factory, if available and creates the validator. Returns an Exception if a Validator could not be created.
      • ValidatorImpl

        public ValidatorImpl​(jakarta.validation.ValidatorFactory validatorFactory,
                             jakarta.persistence.ValidationMode mode)
        Type-specific constructor Returns an Exception if a Validator could not be created.
        Parameters:
        validatorFactory - Instance of validator factory to use. Specify null to use the default factory.
        mode - ValdiationMode enum value
    • Method Detail

      • addValidationGroup

        public void addValidationGroup​(java.lang.String validationGroupName,
                                       java.lang.Class<?>... vgs)
        Add a validation group for the specific property. The properties map to a specific lifecycle event. To disable validation for a group, set the validation group to null.
        Parameters:
        validationGroupName -
        vgs -
      • addValidationGroup

        public void addValidationGroup​(java.lang.Integer event,
                                       java.lang.Class<?>... validationGroup)
        Add a validation group for a specified event. Event definitions are defined in LifecycleEvent. To disable validation for a group, set the validation group to null.
        Parameters:
        event -
        validationGroup -
      • addValidationGroup

        public void addValidationGroup​(java.lang.String validationGroupName,
                                       java.lang.String group)
        Add the validation group(s) for the specified event. Event definitions are defined in LifecycleEvent
        Parameters:
        event -
        group -
      • getValidationGroup

        public java.lang.Class<?>[] getValidationGroup​(java.lang.Integer event)
        Return the validation groups to be validated for a specified event
        Parameters:
        event - Lifecycle event id
        Returns:
        An array of validation groups
      • isValidating

        public boolean isValidating​(java.lang.Integer event)
        Returns whether the Validator is validating for the specified event. Based on whether validation groups are specified for the event.
        Parameters:
        event - the event to check for validation
        Returns:
        returns true if validating for this particular event
      • getConstraintsForClass

        public jakarta.validation.metadata.BeanDescriptor getConstraintsForClass​(java.lang.Class<?> cls)
        Returns the validation constraints for the specified class
        Parameters:
        cls - Class for which constraints to return
        Returns:
        The validation bean descriptor
      • validate

        public <T> ValidationException validate​(T arg0,
                                                int event)
        Validates a given instance
        Specified by:
        validate in interface Validator
        Specified by:
        validate in class AbstractValidator
        Type Parameters:
        T - The instance to validate
        Parameters:
        arg0 - The class, of type T to validate
        event - The event id
        Returns:
        ValidationException if the validator produces one or more constraint violations.
      • validateProperty

        public <T> ValidationException validateProperty​(T arg0,
                                                        java.lang.String property,
                                                        int event)
        Validates a property of a given instance
        Specified by:
        validateProperty in interface Validator
        Specified by:
        validateProperty in class AbstractValidator
        Type Parameters:
        T - The instance to validate
        Parameters:
        arg0 - The property to validate
        property - The property to validate
        event - The event id
        Returns:
        ValidationException if the validator produces one or more constraint violations.
      • validateValue

        public <T> ValidationException validateValue​(java.lang.Class<T> arg0,
                                                     java.lang.String arg1,
                                                     java.lang.Object arg2,
                                                     int event)
        Validates a value based upon the constraints applied to a given class attribute.
        Specified by:
        validateValue in interface Validator
        Specified by:
        validateValue in class AbstractValidator
        Type Parameters:
        T - The instance type to base validation upon
        Parameters:
        arg0 - The class of type T to validate
        arg1 - The property to validate
        arg2 - The property value to validate
        event - The event id
        Returns:
        ValidationException if the validator produces one or more constraint violations.
      • validating

        public <T> boolean validating​(T arg0,
                                      int event)
        Returns whether validation is active for the given event.
        Specified by:
        validating in interface Validator
        Overrides:
        validating in class AbstractValidator
        Type Parameters:
        T -
        Parameters:
        arg0 - Type being validated
        event - event type
        Returns:
        true if validation is active for the specified event