Class ValidationExtension

java.lang.Object
org.hibernate.validator.cdi.ValidationExtension
All Implemented Interfaces:
Extension
Direct Known Subclasses:
ValidationExtension

public class ValidationExtension extends Object implements Extension
A CDI portable extension which integrates Bean Validation with CDI. It registers the following objects:
  • Beans for ValidatorFactory and Validator representing default validator factory and validator as configured via META-INF/validation.xml. These beans will have the Default qualifier and in addition the HibernateValidator qualifier if Hibernate Validator is the default validation provider.
  • In case Hibernate Validator is not the default provider, another pair of beans will be registered in addition which are qualified with the HibernateValidator qualifier.
Neither of these beans will be registered in case there is already another bean with the same type and qualifier(s), e.g. registered by another portable extension or the application itself.
Author:
Gunnar Morling, Hardy Ferentschik
  • Constructor Details

    • ValidationExtension

      public ValidationExtension()
  • Method Details

    • beforeBeanDiscovery

      public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscoveryEvent, BeanManager beanManager)
      Used to register the method validation interceptor binding annotation.
      Parameters:
      beforeBeanDiscoveryEvent - event fired before the bean discovery process starts
      beanManager - the bean manager.
    • afterBeanDiscovery

      public void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscoveryEvent, BeanManager beanManager)
      Registers beans for ValidatorFactory and Validator if not yet present.
      Parameters:
      afterBeanDiscoveryEvent - event fired after the bean discovery phase.
      beanManager - the bean manager.
    • processBean

      public void processBean(@Observes ProcessBean<?> processBeanEvent)
      Watches the ProcessBean event in order to determine whether beans for ValidatorFactory and Validator already have been registered by some other component.
      Parameters:
      processBeanEvent - event fired for each enabled bean.
    • processAnnotatedType

      public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> processAnnotatedTypeEvent)
      Used to register the method validation interceptor bindings.
      Type Parameters:
      T - the annotated type
      Parameters:
      processAnnotatedTypeEvent - event fired for each annotated type