Author: rmannibucau
Date: Sat Jun 28 22:47:57 2014
New Revision: 1606406
URL: http://svn.apache.org/r1606406
Log:
constructor interceptors can override class interceptors
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
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=1606406&r1=1606405&r2=1606406&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
Sat Jun 28 22:47:57 2014
@@ -111,7 +111,8 @@ public class InterceptorResolutionServic
// pick up CDI interceptors from a class level
Set<Annotation> classInterceptorBindings =
annotationManager.getInterceptorAnnotations(annotatedType.getAnnotations());
Set<Interceptor<?>> allUsedCdiInterceptors = new
HashSet<Interceptor<?>>();
- addCdiClassLifecycleInterceptors(annotatedType,
classInterceptorBindings, allUsedCdiInterceptors);
+ Set<Interceptor<?>> allUsedConstructorCdiInterceptors = new
HashSet<Interceptor<?>>();
+ addCdiClassLifecycleInterceptors(annotatedType,
classInterceptorBindings, allUsedCdiInterceptors,
allUsedConstructorCdiInterceptors);
LinkedHashSet<Interceptor<?>> allUsedEjbInterceptors = new
LinkedHashSet<Interceptor<?>>(); // we need to preserve the order!
allUsedEjbInterceptors.addAll(classLevelEjbInterceptors);
@@ -182,6 +183,9 @@ public class InterceptorResolutionServic
List<Interceptor<?>> cdiInterceptors = new
ArrayList<Interceptor<?>>(allUsedCdiInterceptors);
Collections.sort(cdiInterceptors, new
InterceptorComparator(webBeansContext));
+ List<Interceptor<?>> cdiConstructorInterceptors = new
ArrayList<Interceptor<?>>(allUsedConstructorCdiInterceptors);
+ Collections.sort(cdiConstructorInterceptors, new
InterceptorComparator(webBeansContext));
+
if (Modifier.isFinal(annotatedType.getJavaClass().getModifiers()) &&
(allUsedEjbInterceptors.size() > 0 ||
allUsedCdiInterceptors.size() > 0 ||
@@ -192,7 +196,9 @@ public class InterceptorResolutionServic
+
annotatedType.getJavaClass().getName());
}
- return new BeanInterceptorInfo(decorators, allUsedEjbInterceptors,
cdiInterceptors, selfInterceptorBean,
+ return new BeanInterceptorInfo(decorators, allUsedEjbInterceptors,
+ cdiInterceptors,
cdiConstructorInterceptors,
+ selfInterceptorBean,
constructorInterceptorInfos,
businessMethodInterceptorInfos,
nonInterceptedMethods,
lifecycleMethodInterceptorInfos);
}
@@ -219,12 +225,15 @@ public class InterceptorResolutionServic
private <T> void addCdiClassLifecycleInterceptors(AnnotatedType<T>
annotatedType,
Set<Annotation>
classInterceptorBindings,
- Set<Interceptor<?>>
allUsedCdiInterceptors)
+ Set<Interceptor<?>>
allUsedCdiInterceptors,
+ Set<Interceptor<?>>
allUsedConstructorCdiInterceptors)
{
+ final BeanManagerImpl beanManagerImpl =
webBeansContext.getBeanManagerImpl();
+
+ Annotation[] interceptorBindings = null;
if (classInterceptorBindings.size() > 0)
{
- final Annotation[] interceptorBindings =
AnnotationUtil.asArray(classInterceptorBindings);
- final BeanManagerImpl beanManagerImpl =
webBeansContext.getBeanManagerImpl();
+ interceptorBindings =
AnnotationUtil.asArray(classInterceptorBindings);
allUsedCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.POST_CONSTRUCT,
interceptorBindings));
allUsedCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.PRE_DESTROY,
interceptorBindings));
@@ -250,6 +259,45 @@ public class InterceptorResolutionServic
allUsedCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.AROUND_CONSTRUCT,
interceptorBindings));
}
}
+
+ if (!annotatedType.getConstructors().isEmpty())
+ {
+ for (final AnnotatedConstructor<?> c :
annotatedType.getConstructors())
+ {
+ final Set<Annotation> constructorAnnot =
webBeansContext.getAnnotationManager().getInterceptorAnnotations(c.getAnnotations());
+ if (constructorAnnot.isEmpty())
+ {
+ if (interceptorBindings != null)
+ {
+
allUsedConstructorCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.AROUND_CONSTRUCT,
interceptorBindings));
+ }
+ }
+ else
+ {
+ for (final Annotation classA : classInterceptorBindings)
+ {
+ boolean overriden = false;
+ for (final Annotation consA : constructorAnnot)
+ {
+ if (classA.annotationType() ==
consA.annotationType())
+ {
+ overriden = true;
+ break;
+ }
+ }
+ if (!overriden)
+ {
+ constructorAnnot.add(classA);
+ }
+ }
+
allUsedConstructorCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.AROUND_CONSTRUCT,
AnnotationUtil.asArray(constructorAnnot)));
+ }
+ }
+ }
+ else if (interceptorBindings != null)
+ {
+
allUsedConstructorCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.AROUND_CONSTRUCT,
interceptorBindings));
+ }
}
/**
@@ -632,7 +680,8 @@ public class InterceptorResolutionServic
{
public BeanInterceptorInfo(List<Decorator<?>> decorators,
LinkedHashSet<Interceptor<?>> ejbInterceptors,
- List<Interceptor<?>> cdiInterceptors,
SelfInterceptorBean<?> selfInterceptorBean,
+ List<Interceptor<?>> cdiInterceptors,
List<Interceptor<?>> constructorCdiInterceptors,
+ SelfInterceptorBean<?> selfInterceptorBean,
Map<Constructor<?>,
BusinessMethodInterceptorInfo> constructorInterceptorInfos,
Map<Method, BusinessMethodInterceptorInfo>
businessMethodsInfo,
List<Method> nonInterceptedMethods,
@@ -641,6 +690,7 @@ public class InterceptorResolutionServic
this.decorators = decorators;
this.ejbInterceptors = ejbInterceptors;
this.cdiInterceptors = cdiInterceptors;
+ this.constructorCdiInterceptors = constructorCdiInterceptors;
this.selfInterceptorBean = selfInterceptorBean;
this.businessMethodsInfo = businessMethodsInfo;
this.constructorInterceptorInfos = constructorInterceptorInfos;
@@ -661,6 +711,8 @@ public class InterceptorResolutionServic
*/
private List<Interceptor<?>> cdiInterceptors;
+ private final List<Interceptor<?>> constructorCdiInterceptors;
+
/**
* Set if this class intercepts itself.
*/
@@ -706,6 +758,11 @@ public class InterceptorResolutionServic
return cdiInterceptors;
}
+ public List<Interceptor<?>> getConstructorCdiInterceptors()
+ {
+ return constructorCdiInterceptors;
+ }
+
public SelfInterceptorBean<?> getSelfInterceptorBean()
{
return selfInterceptorBean;
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java?rev=1606406&r1=1606405&r2=1606406&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java
Sat Jun 28 22:47:57 2014
@@ -177,6 +177,11 @@ public abstract class AbstractProducer<T
creationalContextImpl.putContextual(interceptorBean);
interceptorInstances.put(interceptorBean,
interceptorBean.create(creationalContext));
}
+ for (final Interceptor interceptorBean :
interceptorInfo.getConstructorCdiInterceptors())
+ {
+ creationalContextImpl.putContextual(interceptorBean);
+ interceptorInstances.put(interceptorBean,
interceptorBean.create(creationalContext));
+ }
}
creationalContextImpl.putContextual(oldContextual);
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java?rev=1606406&r1=1606405&r2=1606406&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
Sat Jun 28 22:47:57 2014
@@ -141,7 +141,7 @@ public class InjectionTargetImpl<T> exte
Collections.<Interceptor<?>>emptyList() :
asList(constructorEjbInterceptorArray);
aroundConstructInterceptors = getLifecycleInterceptors(
constructorEjbInterceptors,
- interceptorInfo.getCdiInterceptors(),
+ interceptorInfo.getConstructorCdiInterceptors(),
InterceptionType.AROUND_CONSTRUCT);
}