Search in sources :

Example 1 with MessageInterpolatorImpl

use of org.jvnet.hk2.config.MessageInterpolatorImpl in project Payara by payara.

the class CommandRunnerImpl method initBeanValidator.

private static synchronized void initBeanValidator() {
    if (beanValidator != null) {
        return;
    }
    ClassLoader cl = System.getSecurityManager() == null ? Thread.currentThread().getContextClassLoader() : AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

        @Override
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    try {
        Thread.currentThread().setContextClassLoader(Validation.class.getClassLoader());
        Configuration<?> configuration = Validation.byDefaultProvider().providerResolver(new HibernateValidationProviderResolver()).configure();
        ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
        ValidatorContext validatorContext = validatorFactory.usingContext();
        validatorContext.messageInterpolator(new MessageInterpolatorImpl());
        beanValidator = validatorContext.getValidator();
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : PrivilegedAction(java.security.PrivilegedAction) MessageInterpolatorImpl(org.jvnet.hk2.config.MessageInterpolatorImpl)

Example 2 with MessageInterpolatorImpl

use of org.jvnet.hk2.config.MessageInterpolatorImpl in project Payara by payara.

the class CompositeUtil method initBeanValidator.

private static synchronized void initBeanValidator() {
    if (beanValidator != null) {
        return;
    }
    ClassLoader cl = System.getSecurityManager() == null ? Thread.currentThread().getContextClassLoader() : AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

        @Override
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    try {
        Thread.currentThread().setContextClassLoader(Validation.class.getClassLoader());
        ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
        ValidatorContext validatorContext = validatorFactory.usingContext();
        validatorContext.messageInterpolator(new MessageInterpolatorImpl());
        beanValidator = validatorContext.getValidator();
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : Validation(javax.validation.Validation) ValidatorFactory(javax.validation.ValidatorFactory) PrivilegedAction(java.security.PrivilegedAction) ValidatorContext(javax.validation.ValidatorContext) MessageInterpolatorImpl(org.jvnet.hk2.config.MessageInterpolatorImpl)

Aggregations

PrivilegedAction (java.security.PrivilegedAction)2 MessageInterpolatorImpl (org.jvnet.hk2.config.MessageInterpolatorImpl)2 Validation (javax.validation.Validation)1 ValidatorContext (javax.validation.ValidatorContext)1 ValidatorFactory (javax.validation.ValidatorFactory)1