Search in sources :

Example 1 with InterceptorBindingsAdapter

use of org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter in project core by weld.

the class EjbSupportImpl method registerCdiInterceptorsForMessageDrivenBeans.

public void registerCdiInterceptorsForMessageDrivenBeans(BeanDeployerEnvironment environment, BeanManagerImpl manager) {
    for (InternalEjbDescriptor<?> descriptor : getEjbDescriptors()) {
        if (descriptor.isMessageDriven()) {
            EnhancedAnnotatedType<?> type = manager.getServices().getRequired(ClassTransformer.class).getEnhancedAnnotatedType(descriptor.getBeanClass(), manager.getId());
            if (!manager.getInterceptorModelRegistry().containsKey(type.slim())) {
                InterceptionModelInitializer.of(manager, type, null).init();
            }
            InterceptionModel model = manager.getInterceptorModelRegistry().get(type.slim());
            if (model != null) {
                ejbServices.registerInterceptors(descriptor.delegate(), new InterceptorBindingsAdapter(model));
            }
        }
    }
}
Also used : InterceptorBindingsAdapter(org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter) ClassTransformer(org.jboss.weld.resources.ClassTransformer) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel)

Example 2 with InterceptorBindingsAdapter

use of org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter in project core by weld.

the class EnterpriseBeanInterceptionTest method testInterceptors.

@Test
public void testInterceptors() throws Exception {
    SessionBean<Ball> ballSessionBean = (SessionBean<Ball>) beanManager.getBeans(Ball.class).iterator().next();
    InterceptorBindings interceptorBindings = new InterceptorBindingsAdapter(beanManager.getInterceptorModelRegistry().get(ballSessionBean.getAnnotated()));
    List<javax.enterprise.inject.spi.Interceptor> interceptors = new ArrayList<javax.enterprise.inject.spi.Interceptor>(interceptorBindings.getAllInterceptors());
    Assert.assertEquals(3, interceptors.size());
    List<Class<?>> expectedInterceptors = Arrays.<Class<?>>asList(Goalkeeper.class, Defender.class, Referee.class);
    Assert.assertTrue(expectedInterceptors.contains(interceptors.get(0).getBeanClass()));
    Assert.assertTrue(expectedInterceptors.contains(interceptors.get(1).getBeanClass()));
    Assert.assertTrue(expectedInterceptors.contains(interceptors.get(2).getBeanClass()));
    Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getBeanClass().getMethod("shoot")).size());
    Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("shoot")).size());
    Assert.assertEquals(Goalkeeper.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("shoot")).get(0).getBeanClass());
    Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getBeanClass().getMethod("pass")).size());
    Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("pass")).size());
    Assert.assertEquals(Defender.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("pass")).get(0).getBeanClass());
    Method finishGameMethod = ballSessionBean.getBeanClass().getMethod("finishGame", Timer.class);
    Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, finishGameMethod).size());
    Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, finishGameMethod).size());
    Assert.assertEquals(Referee.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, finishGameMethod).get(0).getBeanClass());
}
Also used : InterceptorBindingsAdapter(org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) SessionBean(org.jboss.weld.bean.SessionBean) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) Test(org.junit.Test)

Example 3 with InterceptorBindingsAdapter

use of org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter in project wildfly by wildfly.

the class WeldInterceptorBindingsService method getInterceptorBindings.

private InterceptorBindings getInterceptorBindings(final String ejbName, final BeanManagerImpl manager) {
    InterceptorBindings retVal = null;
    if (ejbName != null) {
        retVal = interceptorSupport.getInterceptorBindings(ejbName, manager);
    } else {
        // This is a managed bean
        SlimAnnotatedType<?> type = (SlimAnnotatedType<?>) manager.createAnnotatedType(componentClass);
        if (!manager.getInterceptorModelRegistry().containsKey(type)) {
            EnhancedAnnotatedType<?> enhancedType = manager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(type);
            InterceptionModelInitializer.of(manager, enhancedType, null).init();
        }
        InterceptionModel model = manager.getInterceptorModelRegistry().get(type);
        if (model != null) {
            retVal = new InterceptorBindingsAdapter(manager.getInterceptorModelRegistry().get(type));
        }
    }
    return retVal != null ? retVal : NullInterceptorBindings.INSTANCE;
}
Also used : InterceptorBindingsAdapter(org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) ClassTransformer(org.jboss.weld.resources.ClassTransformer) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) SlimAnnotatedType(org.jboss.weld.annotated.slim.SlimAnnotatedType)

Aggregations

InterceptorBindingsAdapter (org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter)3 InterceptorBindings (org.jboss.weld.ejb.spi.InterceptorBindings)2 InterceptionModel (org.jboss.weld.interceptor.spi.model.InterceptionModel)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 SlimAnnotatedType (org.jboss.weld.annotated.slim.SlimAnnotatedType)1 SessionBean (org.jboss.weld.bean.SessionBean)1 Test (org.junit.Test)1