use of org.apache.webbeans.annotation.AnnotationManager in project tomee by apache.
the class BeanContext method mergeOWBAndOpenEJBInfo.
public void mergeOWBAndOpenEJBInfo() {
final CdiEjbBean cdiEjbBean = get(CdiEjbBean.class);
if (cdiEjbBean == null) {
return;
}
final InjectionTargetImpl<?> injectionTarget = InjectionTargetImpl.class.cast(get(CdiEjbBean.class).getInjectionTarget());
final InterceptorResolutionService.BeanInterceptorInfo info = injectionTarget.getInterceptorInfo();
if (info == null) {
return;
}
final Collection<Interceptor<?>> postConstructInterceptors = Collection.class.cast(Reflections.get(injectionTarget, "postConstructInterceptors"));
final Collection<Interceptor<?>> preDestroyInterceptors = Collection.class.cast(Reflections.get(injectionTarget, "preDestroyInterceptors"));
if (postConstructInterceptors != null) {
for (final Interceptor<?> pc : postConstructInterceptors) {
if (isEjbInterceptor(pc)) {
continue;
}
final InterceptorData interceptorData = createInterceptorData(pc);
instanceScopedInterceptors.add(interceptorData);
cdiInterceptors.add(interceptorData);
}
}
if (preDestroyInterceptors != null) {
for (final Interceptor<?> pd : preDestroyInterceptors) {
if (isEjbInterceptor(pd)) {
continue;
}
if (postConstructInterceptors.contains(pd)) {
continue;
}
final InterceptorData interceptorData = createInterceptorData(pd);
instanceScopedInterceptors.add(interceptorData);
cdiInterceptors.add(interceptorData);
}
}
for (final Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo> entry : info.getBusinessMethodsInfo().entrySet()) {
final Interceptor<?>[] interceptors = entry.getValue().getCdiInterceptors();
if (interceptors == null) {
continue;
}
for (final Interceptor<?> i : interceptors) {
// already at class level, since we merge "hooks" in InterceptorData no need to add it again
if (postConstructInterceptors.contains(i) || preDestroyInterceptors.contains(i)) {
continue;
}
final InterceptorData data = createInterceptorData(i);
addCdiMethodInterceptor(entry.getKey(), data);
}
entry.getValue().setEjbInterceptors(new ArrayList<>());
entry.getValue().setCdiInterceptors(new ArrayList<>());
}
// handled by OpenEJB now so clean up all duplication from OWB
if (info.getSelfInterceptorBean() != null) {
try {
final Field field = InterceptorResolutionService.BeanInterceptorInfo.class.getDeclaredField("selfInterceptorBean");
field.setAccessible(true);
field.set(info, null);
} catch (final Exception e) {
// no-op
}
}
Map.class.cast(Reflections.get(injectionTarget, "methodInterceptors")).clear();
clear(Collection.class.cast(postConstructInterceptors));
clear(Collection.class.cast(preDestroyInterceptors));
clear(Collection.class.cast(Reflections.get(injectionTarget, "postConstructMethods")));
clear(Collection.class.cast(Reflections.get(injectionTarget, "preDestroyMethods")));
clear(Collection.class.cast(Reflections.get(info, "ejbInterceptors")));
clear(Collection.class.cast(Reflections.get(info, "cdiInterceptors")));
// OWB doesn't compute AROUND_INVOKE so let's do it
final Method timeout = getEjbTimeout();
if (timeout != null) {
final AnnotatedType annotatedType = cdiEjbBean.getAnnotatedType();
final AnnotationManager annotationManager = getWebBeansContext().getAnnotationManager();
final Collection<Annotation> annotations = new HashSet<>(annotationManager.getInterceptorAnnotations(annotatedType.getAnnotations()));
final Set<AnnotatedMethod<?>> methods = annotatedType.getMethods();
for (final AnnotatedMethod<?> m : methods) {
if (timeout.equals(m.getJavaMember())) {
annotations.addAll(annotationManager.getInterceptorAnnotations(m.getAnnotations()));
break;
}
}
if (!annotations.isEmpty()) {
for (final Interceptor<?> timeoutInterceptor : getWebBeansContext().getBeanManagerImpl().resolveInterceptors(InterceptionType.AROUND_TIMEOUT, AnnotationUtil.asArray(annotations))) {
if (isEjbInterceptor(timeoutInterceptor)) {
continue;
}
final InterceptorData data = createInterceptorData(timeoutInterceptor);
addCdiMethodInterceptor(timeout, data);
}
}
}
}
Aggregations