You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2013/01/16 16:21:10 UTC

svn commit: r1433980 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: intercept/WebBeansInterceptorConfig.java portable/InjectionTargetImpl.java

Author: struberg
Date: Wed Jan 16 15:21:09 2013
New Revision: 1433980

URL: http://svn.apache.org/viewvc?rev=1433980&view=rev
Log:
OWB-344 provide postconstruct and predestroy interceptors

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.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/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1433980&r1=1433979&r2=1433980&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 15:21:09 2013
@@ -43,6 +43,7 @@ import javax.enterprise.context.Dependen
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
 import javax.interceptor.AroundInvoke;
 import java.lang.annotation.Annotation;
@@ -147,7 +148,27 @@ public final class WebBeansInterceptorCo
 
                 Class proxyClass = pf.createProxyClass(classLoader, bean.getReturnType(), businessMethods, nonInterceptedMethods);
 
-                injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors);
+                // now we collect the post-construct and pre-destroy interceptors
+                List<Interceptor<?>> postConstructInterceptors = new ArrayList<Interceptor<?>>();
+                List<Interceptor<?>> preDestroyInterceptors = new ArrayList<Interceptor<?>>();
+                for (Interceptor<?> interceptor : interceptorInfo.getInterceptors())
+                {
+                    if (interceptor.intercepts(InterceptionType.POST_CONSTRUCT))
+                    {
+                        postConstructInterceptors.add(interceptor);
+                    }
+                    if (interceptor.intercepts(InterceptionType.PRE_DESTROY))
+                    {
+                        preDestroyInterceptors.add(interceptor);
+                    }
+                }
+
+                // and sort them
+                InterceptorComparator interceptorComparator = new InterceptorComparator(webBeansContext);
+                Collections.sort(postConstructInterceptors, interceptorComparator);
+                Collections.sort(preDestroyInterceptors, interceptorComparator);
+
+                injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors, postConstructInterceptors, preDestroyInterceptors);
             }
 
         }

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=1433980&r1=1433979&r2=1433980&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 Wed Jan 16 15:21:09 2013
@@ -85,6 +85,12 @@ public class InjectionTargetImpl<T> exte
     private List<AnnotatedMethod<?>> postConstructMethods;
 
     /**
+     * Interceptors which should get triggered for &#064;PostConstruct.
+     * Ordered in parent-class first
+     */
+    private List<Interceptor<?>> postConstructInterceptors;
+
+    /**
      * If the InjectionTarget has a &#064;PreDestroy method, <code>null</code> if not.
      * This methods only gets used if the produced instance is not intercepted.
      * This methods must have the signature <code>void METHOD();</code>
@@ -93,6 +99,12 @@ public class InjectionTargetImpl<T> exte
     private List<AnnotatedMethod<?>> preDestroyMethods;
 
     /**
+     * Interceptors which should get triggered for &#064;PreDestroy.
+     * Ordered in sub-class first
+     */
+    private List<Interceptor<?>> preDestroyInterceptors;
+
+    /**
      * static information about Interceptors and Decorators of that bean
      */
     private BeanInterceptorInfo interceptorInfo = null;
@@ -126,11 +138,14 @@ public class InjectionTargetImpl<T> exte
         this.preDestroyMethods = preDestroyMethods;
     }
 
-    public void setInterceptorInfo(BeanInterceptorInfo interceptorInfo, Class<? extends T> proxyClass, Map<Method, List<Interceptor<?>>> methodInterceptors)
+    public void setInterceptorInfo(BeanInterceptorInfo interceptorInfo, Class<? extends T> proxyClass, Map<Method, List<Interceptor<?>>> methodInterceptors,
+                                   List<Interceptor<?>> postConstructInterceptors, List<Interceptor<?>> preDestroyInterceptors)
     {
         this.interceptorInfo = interceptorInfo;
         this.proxyClass = proxyClass;
         this.methodInterceptors = methodInterceptors;
+        this.postConstructInterceptors = postConstructInterceptors;
+        this.preDestroyInterceptors = preDestroyInterceptors;
     }
 
     @Override
@@ -277,7 +292,6 @@ public class InjectionTargetImpl<T> exte
 
 
         Map<Interceptor<?>, ?> interceptorInstances = null;
-        List<Interceptor<?>> postConstructInterceptors = null;
         T internalInstance = instance;
 
         if (interceptorInfo != null && instance instanceof OwbInterceptorProxy)
@@ -316,7 +330,6 @@ public class InjectionTargetImpl<T> exte
         }
 
         Map<Interceptor<?>, ?> interceptorInstances = null;
-        List<Interceptor<?>> preDestroyInterceptors = null;
         T internalInstance = instance;
 
         if (interceptorInfo != null && instance instanceof OwbInterceptorProxy)