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));
}
}
}
}
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());
}
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;
}
Aggregations