Author: struberg
Date: Wed Jan 16 22:03:24 2013
New Revision: 1434432
URL: http://svn.apache.org/viewvc?rev=1434432&view=rev
Log:
OWB-344 invoke PostConstruct interceptors even if no method got intercepted
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java?rev=1434432&r1=1434431&r2=1434432&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
Wed Jan 16 22:03:24 2013
@@ -534,7 +534,6 @@ public final class AnnotationManager
/**
* Returns bean stereotypes.
- * @param bean bean instance
* @return bean stereotypes
*/
public Set<Class<? extends Annotation>> getStereotypes(Set<Class<? extends
Annotation>> anns)
@@ -550,7 +549,6 @@ public final class AnnotationManager
/**
* Returns true if name exists,false otherwise.
- * @param bean bean instance
* @return true if name exists
*/
public boolean hasNamedOnStereoTypes(Set<Class<? extends Annotation>>
stereotypes)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1434432&r1=1434431&r2=1434432&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
Wed Jan 16 22:03:24 2013
@@ -99,8 +99,6 @@ public class InterceptorResolutionServic
AnnotationManager annotationManager =
webBeansContext.getAnnotationManager();
BeanManager beanManager = webBeansContext.getBeanManagerImpl();
- // pick up CDI interceptors from a class level
- Set<Annotation> classInterceptorBindings =
annotationManager.getInterceptorAnnotations(annotatedType.getAnnotations());
// pick up EJB-style interceptors from a class level
List<Interceptor<?>> classLevelEjbInterceptors = new
ArrayList<Interceptor<?>>();
@@ -114,7 +112,10 @@ public class InterceptorResolutionServic
decorators = null; // less to store
}
+ // pick up CDI interceptors from a class level
+ Set<Annotation> classInterceptorBindings =
annotationManager.getInterceptorAnnotations(annotatedType.getAnnotations());
Set<Interceptor<?>> allUsedCdiInterceptors = new
HashSet<Interceptor<?>>();
+ addCdiClassLifecycleInterceptors(classInterceptorBindings,
allUsedCdiInterceptors);
LinkedHashSet<Interceptor<?>> allUsedEjbInterceptors = new
LinkedHashSet<Interceptor<?>>(); // we need to preserve the order!
allUsedEjbInterceptors.addAll(classLevelEjbInterceptors);
@@ -178,6 +179,18 @@ public class InterceptorResolutionServic
nonInterceptedMethods,
lifecycleMethodInterceptorInfos);
}
+ private void addCdiClassLifecycleInterceptors(Set<Annotation>
classInterceptorBindings, Set<Interceptor<?>> allUsedCdiInterceptors)
+ {
+ if (classInterceptorBindings.size() > 0)
+ {
+ allUsedCdiInterceptors.addAll(
+
webBeansContext.getBeanManagerImpl().resolveInterceptors(InterceptionType.POST_CONSTRUCT,
AnnotationUtil.asArray(classInterceptorBindings)));
+
+ allUsedCdiInterceptors.addAll(
+
webBeansContext.getBeanManagerImpl().resolveInterceptors(InterceptionType.PRE_DESTROY,
AnnotationUtil.asArray(classInterceptorBindings)));
+ }
+ }
+
/**
* Check whether this class has any method which intercepts the whole bean
itself.
* @return SelfInterceptorBean or <code>null</code> if this bean doesn't
intercept itself
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1434432&r1=1434431&r2=1434432&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
Wed Jan 16 22:03:24 2013
@@ -145,7 +145,13 @@ public final class WebBeansInterceptorCo
}
}
- if (methodInterceptors.size() > 0)
+ List<Interceptor<?>> postConstructInterceptors
+ =
getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(),
interceptorInfo.getCdiInterceptors(), InterceptionType.POST_CONSTRUCT);
+
+ List<Interceptor<?>> preDestroyInterceptors
+ =
getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(),
interceptorInfo.getCdiInterceptors(), InterceptionType.PRE_DESTROY);
+
+ if (methodInterceptors.size() > 0 ||
postConstructInterceptors.size() > 0 || preDestroyInterceptors.size() > 0)
{
// we only need to create a proxy class for intercepted or
decorated Beans
InterceptorDecoratorProxyFactory pf =
webBeansContext.getInterceptorDecoratorProxyFactory();
@@ -159,11 +165,6 @@ public final class WebBeansInterceptorCo
Class proxyClass = pf.createProxyClass(classLoader,
bean.getReturnType(), businessMethods, nonInterceptedMethods);
// now we collect the post-construct and pre-destroy
interceptors
- List<Interceptor<?>> postConstructInterceptors
- =
getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(),
interceptorInfo.getCdiInterceptors(), InterceptionType.POST_CONSTRUCT);
-
- List<Interceptor<?>> preDestroyInterceptors
- =
getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(),
interceptorInfo.getCdiInterceptors(), InterceptionType.PRE_DESTROY);
injectionTarget.setInterceptorInfo(interceptorInfo,
proxyClass, methodInterceptors, postConstructInterceptors,
preDestroyInterceptors);
}
@@ -195,18 +196,6 @@ public final class WebBeansInterceptorCo
return lifecycleInterceptors;
}
- private void addAllInterceptors(List<Interceptor<?>> collect,
Interceptor<?>[] interceptors)
- {
- if (interceptors != null)
- {
- for (Interceptor<?> interceptor : interceptors)
- {
- collect.add(interceptor);
- }
- }
- }
-
-
/**
* Configure bean instance interceptor stack.
* @param bean bean instance