Search in sources :

Example 36 with ValidatorFactory

use of javax.validation.ValidatorFactory in project Payara by payara.

the class ValidationNamingProxy method handle.

@Override
public Object handle(String name) throws NamingException {
    // delegate to the java:comp/BeanManager handler to obtain the appropriate BeanManager
    BeanManager beanManager = obtainBeanManager();
    if (beanManager == null) {
        // There is no bean manager available, return and let BeanValidatorNamingProxy handle lookup..
        return null;
    }
    if (VALIDATOR_FACTORY_CONTEXT.equals(name)) {
        try {
            ValidatorFactory validatorFactory = (ValidatorFactory) getAndCreateBean(beanManager, ValidatorFactory.class);
            if (validatorFactory != null) {
                return validatorFactory;
            } else {
                throw new NamingException("Error retrieving " + name);
            }
        } catch (Throwable t) {
            NamingException ne = new NamingException("Error retrieving " + name);
            ne.initCause(t);
            throw ne;
        }
    } else if (VALIDATOR_CONTEXT.equals(name)) {
        try {
            Validator validator = (Validator) getAndCreateBean(beanManager, Validator.class);
            if (validator != null) {
                return validator;
            } else {
                throw new NamingException("Error retrieving " + name);
            }
        } catch (Throwable t) {
            NamingException ne = new NamingException("Error retrieving " + name);
            ne.initCause(t);
            throw ne;
        }
    } else {
        throw new NamingException("wrong handler for " + name);
    }
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) NamingException(javax.naming.NamingException) BeanManager(javax.enterprise.inject.spi.BeanManager) Validator(javax.validation.Validator)

Example 37 with ValidatorFactory

use of javax.validation.ValidatorFactory in project Payara by payara.

the class BeanValidatorNamingProxy method getValidator.

private Validator getValidator() throws NamingException {
    if (null == validator) {
        try {
            ValidatorFactory factory = getValidatorFactory();
            ValidatorContext validatorContext = factory.usingContext();
            validator = validatorContext.getValidator();
        } catch (Throwable t) {
            NamingException ne = new NamingException("Error retrieving Validator for " + nameForValidator + " lookup");
            ne.initCause(t);
            throw ne;
        }
    }
    return validator;
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) ValidatorContext(javax.validation.ValidatorContext) NamingException(javax.naming.NamingException)

Example 38 with ValidatorFactory

use of javax.validation.ValidatorFactory in project tomee by apache.

the class AppComposerAsJUnitRuleTest method lookupValidatorFactory.

@Test
public void lookupValidatorFactory() throws Exception {
    final ValidatorFactory validatorFactory = (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory");
    assertNotNull(validatorFactory);
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 39 with ValidatorFactory

use of javax.validation.ValidatorFactory in project tomee by apache.

the class AppComposerAsJUnitRuleTest method injectionValidatorFactory.

@Test
public void injectionValidatorFactory() {
    final ValidatorFactory validatorFactory = persistManager.getValidatorFactory();
    assertNotNull(validatorFactory);
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) Test(org.junit.Test)

Example 40 with ValidatorFactory

use of javax.validation.ValidatorFactory in project tomee by apache.

the class AppComposerAsJUnitRuleWithReusableModulesTest method injectionValidatorFactory.

@Test
public void injectionValidatorFactory() {
    final ValidatorFactory validatorFactory = persistManager.getValidatorFactory();
    assertNotNull(validatorFactory);
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) Test(org.junit.Test)

Aggregations

ValidatorFactory (javax.validation.ValidatorFactory)55 Validator (javax.validation.Validator)16 Test (org.junit.Test)12 ConstraintViolation (javax.validation.ConstraintViolation)10 Before (org.junit.Before)8 HashMap (java.util.HashMap)5 BeanManager (javax.enterprise.inject.spi.BeanManager)5 InitialContext (javax.naming.InitialContext)5 NamingException (javax.naming.NamingException)5 ArrayList (java.util.ArrayList)4 ConstraintValidatorFactory (javax.validation.ConstraintValidatorFactory)4 ValidationException (javax.validation.ValidationException)4 ValidatorContext (javax.validation.ValidatorContext)4 HibernateValidator (org.hibernate.validator.HibernateValidator)4 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)4 TransactionManager (javax.transaction.TransactionManager)3 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)3 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)3 ProxyBeanManager (org.jboss.as.jpa.beanmanager.ProxyBeanManager)3 PhaseOnePersistenceUnitServiceImpl (org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl)3