openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1504132 - in /openwebbeans/trunk: webbeans-cdi11/ webbeans-impl/src/main/java/org/apache/webbeans/component/ webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ webbeans-impl/src/main/java/org/apache/webbeans/inject/ webbea...
Date Wed, 17 Jul 2013 13:39:13 GMT
Author: rmannibucau
Date: Wed Jul 17 13:39:12 2013
New Revision: 1504132

URL: http://svn.apache.org/r1504132
Log:
OWB-883 basic @AroundConstruct impl

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AroundConstruct.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/CDI11s.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/constructor/AroundConstructTest.java
Modified:
    openwebbeans/trunk/webbeans-cdi11/pom.xml
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.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/LifecycleInterceptorInvocationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java

Modified: openwebbeans/trunk/webbeans-cdi11/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-cdi11/pom.xml?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-cdi11/pom.xml (original)
+++ openwebbeans/trunk/webbeans-cdi11/pom.xml Wed Jul 17 13:39:12 2013
@@ -83,11 +83,19 @@
             <artifactId>openwebbeans-spi</artifactId>
         </dependency>
 
+        <!--
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-interceptor_1.1_spec</artifactId>
             <optional>true</optional>
         </dependency>
+        -->
+        <dependency>
+            <groupId>org.jboss.spec.javax.interceptor</groupId>
+            <artifactId>jboss-interceptors-api_1.2_spec</artifactId>
+            <version>1.0.0.Alpha1</version>
+            <optional>true</optional>
+        </dependency>
 
         <dependency>
             <groupId>junit</groupId>
@@ -188,6 +196,10 @@
                             <token>import org.apache.webbeans.annotation.Decorated</token>
                             <value>import javax.enterprise.inject.Decorated</value>
                         </replacement>
+                        <replacement>
+                            <token>import org.apache.webbeans.intercept.AroundConstruct</token>
+                            <value>import javax.interceptor.AroundConstruct</value>
+                        </replacement>
                     </replacements>
                 </configuration>
             </plugin>

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
Wed Jul 17 13:39:12 2013
@@ -46,9 +46,10 @@ public class CdiInterceptorBean<T> exten
                               Class<T> beanClass,
                               Set<Annotation> interceptorBindings,
                               boolean enabled,
-                              Map<InterceptionType, Method[]> interceptionMethods)
+                              Map<InterceptionType, Method[]> interceptionMethods,
+                              Method aroundConstruct)
     {
-        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods);
+        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods,
aroundConstruct);
         this.interceptorBindings = interceptorBindings;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java
Wed Jul 17 13:39:12 2013
@@ -41,9 +41,10 @@ public class EjbInterceptorBean<T> exten
                               AnnotatedType<T> annotated,
                               BeanAttributesImpl<T> beanAttributes,
                               Class<T> beanClass,
-                              Map<InterceptionType, Method[]> interceptionMethods)
+                              Map<InterceptionType, Method[]> interceptionMethods,
+                              Method aroundConstruct)
     {
-        super(webBeansContext, annotated, beanAttributes, beanClass, interceptionMethods);
+        super(webBeansContext, annotated, beanAttributes, beanClass, interceptionMethods,
aroundConstruct);
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
Wed Jul 17 13:39:12 2013
@@ -42,6 +42,7 @@ import org.apache.webbeans.intercept.Int
 import org.apache.webbeans.portable.InjectionTargetImpl;
 import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.CDI11s;
 
 
 /**
@@ -158,6 +159,16 @@ public class InjectionTargetBean<T> exte
             List<Interceptor<?>> preDestroyInterceptors
                     = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(), interceptorInfo.getCdiInterceptors(),
InterceptionType.PRE_DESTROY);
 
+            final List<Interceptor<?>> aroundConstruct;
+            if (CDI11s.AROUND_CONSTRUCT != null)
+            {
+                aroundConstruct = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(),
interceptorInfo.getCdiInterceptors(), CDI11s.AROUND_CONSTRUCT);
+            }
+            else
+            {
+                aroundConstruct = new ArrayList<Interceptor<?>>();
+            }
+
             Class<? extends T> proxyClass = null;
             if (methodInterceptors.size() > 0 || postConstructInterceptors.size() >
0 || preDestroyInterceptors.size() > 0)
             {
@@ -175,8 +186,7 @@ public class InjectionTargetBean<T> exte
 
             }
 
-            injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors,
postConstructInterceptors, preDestroyInterceptors, getId());
-
+            injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors,
postConstructInterceptors, preDestroyInterceptors, aroundConstruct, getId());
         }
 
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
Wed Jul 17 13:39:12 2013
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.Inter
 import javax.enterprise.inject.spi.Interceptor;
 import javax.interceptor.InvocationContext;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Collections;
@@ -33,6 +34,7 @@ import org.apache.webbeans.component.spi
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.InjectionTargetFactoryImpl;
 import org.apache.webbeans.container.InterceptorInjectionTargetFactory;
+import org.apache.webbeans.util.CDI11s;
 import org.apache.webbeans.util.ExceptionUtil;
 
 /**
@@ -55,12 +57,14 @@ public abstract class InterceptorBean<T>
      * This is for performance reasons
      */
     protected Method aroundInvokeMethod = null;
+    protected Method aroundConstructMethod = null;
 
     protected InterceptorBean(WebBeansContext webBeansContext,
                                   AnnotatedType<T> annotatedType,
                                   BeanAttributes<T> beanAttributes,
                                   Class<T> beanClass,
                                   Map<InterceptionType, Method[]> interceptionMethods,
+                                  Method aroundConstruct,
                                   InjectionTargetFactoryImpl<T> factory)
     {
         super(webBeansContext,
@@ -81,6 +85,13 @@ public abstract class InterceptorBean<T>
                 }
             }
         }
+
+        this.aroundConstructMethod = aroundConstruct;
+        if (aroundConstructMethod != null && !aroundConstructMethod.isAccessible())
+        {
+            aroundConstructMethod.setAccessible(true);
+        }
+
         Method[] aroundInvokeMethods = interceptionMethods.get(InterceptionType.AROUND_INVOKE);
         if (aroundInvokeMethods != null && aroundInvokeMethods.length == 1)
         {
@@ -92,9 +103,10 @@ public abstract class InterceptorBean<T>
                            AnnotatedType<T> annotatedType,
                            BeanAttributesImpl<T> beanAttributes,
                            Class<T> beanClass,
-                           Map<InterceptionType, Method[]> interceptionMethods)
+                           Map<InterceptionType, Method[]> interceptionMethods,
+                           Method aroundConstructMethod)
     {
-        this(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods,
+        this(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods,
aroundConstructMethod,
                 new InterceptorInjectionTargetFactory<T>(annotatedType, webBeansContext));
     }
 
@@ -121,7 +133,7 @@ public abstract class InterceptorBean<T>
     @Override
     public boolean intercepts(InterceptionType interceptionType)
     {
-        return interceptionMethods.containsKey(interceptionType);
+        return interceptionMethods.containsKey(interceptionType) || (interceptionType.equals(CDI11s.AROUND_CONSTRUCT)
&& aroundConstructMethod != null);
     }
 
     @Override
@@ -129,6 +141,11 @@ public abstract class InterceptorBean<T>
     {
         try
         {
+            if (interceptionType.equals(CDI11s.AROUND_CONSTRUCT) && aroundConstructMethod
!= null)
+            {
+                return aroundConstructMethod.invoke(instance, invocationContext);
+            }
+
             if (InterceptionType.AROUND_INVOKE == interceptionType && aroundInvokeMethod
!= null)
             {
                 return aroundInvokeMethod.invoke(instance, invocationContext);
@@ -272,6 +289,12 @@ public abstract class InterceptorBean<T>
         {
             wrapped.setParameters(parameters);
         }
+
+        // @Override
+        public Constructor getConstructor()
+        {
+            return null;
+        }
     }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
Wed Jul 17 13:39:12 2013
@@ -46,9 +46,10 @@ public class SelfInterceptorBean<T> exte
                                AnnotatedType<T> annotatedType,
                                BeanAttributesImpl<T> beanAttributes,
                                Class<T> beanClass,
-                               Map<InterceptionType, Method[]> interceptionMethods)
+                               Map<InterceptionType, Method[]> interceptionMethods,
+                               Method aroundConstruct)
     {
-        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods,
+        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods,
aroundConstruct,
                 new InjectionTargetFactoryImpl<T>(annotatedType, webBeansContext));
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
Wed Jul 17 13:39:12 2013
@@ -72,8 +72,8 @@ public class CdiInterceptorBeanBuilder<T
     }
 
     @Override
-    protected CdiInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled,
Map<InterceptionType, Method[]> interceptionMethods)
+    protected CdiInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled,
Map<InterceptionType, Method[]> interceptionMethods, Method aroundConstruct)
     {
-        return new CdiInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes,
beanClass, interceptorBindings, enabled, interceptionMethods);
+        return new CdiInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes,
beanClass, interceptorBindings, enabled, interceptionMethods, aroundConstruct);
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java
Wed Jul 17 13:39:12 2013
@@ -68,8 +68,8 @@ public class EjbInterceptorBeanBuilder<T
     }
 
     @Override
-    protected EjbInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled,
Map<InterceptionType, Method[]> interceptionMethods)
+    protected EjbInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled,
Map<InterceptionType, Method[]> interceptionMethods, Method aroundConstruct)
     {
-        return new EjbInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes,
beanClass, interceptionMethods);
+        return new EjbInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes,
beanClass, interceptionMethods, aroundConstruct);
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
Wed Jul 17 13:39:12 2013
@@ -43,6 +43,7 @@ import org.apache.webbeans.component.Bea
 import org.apache.webbeans.component.InterceptorBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.intercept.AroundConstruct;
 import org.apache.webbeans.plugins.OpenWebBeansEjbLCAPlugin;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
@@ -62,7 +63,8 @@ public abstract class InterceptorBeanBui
     private final Class<? extends Annotation> postActivateClass;
 
     private Map<InterceptionType, Method[]> interceptionMethods;
-    
+    private Method interceptionConstructor = null;
+
     protected InterceptorBeanBuilder(WebBeansContext webBeansContext, AnnotatedType<T>
annotatedType, BeanAttributesImpl<T> beanAttributes)
     {
         Asserts.assertNotNull(webBeansContext, "webBeansContext may not be null");
@@ -150,6 +152,14 @@ public abstract class InterceptorBeanBui
             {
                 if (clazz == m.getJavaMember().getDeclaringClass())
                 {
+                    if (m.getAnnotation(AroundConstruct.class) != null)
+                    {
+                        if (interceptionConstructor != null)
+                        {
+                            throw new WebBeansConfigurationException("only one AroundConstruct
allowed per Interceptor");
+                        }
+                        interceptionConstructor = m.getJavaMember();
+                    }
 
                     // we only take methods from this very class and not sub- or superclasses
                     if (m.getAnnotation(AroundInvoke.class) != null)
@@ -331,10 +341,11 @@ public abstract class InterceptorBeanBui
 
     protected abstract B createBean(Class<T> beanClass,
                                     boolean enabled,
-                                    Map<InterceptionType, Method[]> interceptionMethods);
+                                    Map<InterceptionType, Method[]> interceptionMethods,
+                                    Method aroundConstruct);
 
     public B getBean()
     {
-        return createBean(annotatedType.getJavaClass(), isInterceptorEnabled(), interceptionMethods);
+        return createBean(annotatedType.getJavaClass(), isInterceptorEnabled(), interceptionMethods,
interceptionConstructor);
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java
Wed Jul 17 13:39:12 2013
@@ -59,8 +59,8 @@ public class SelfInterceptorBeanBuilder<
     }
 
     @Override
-    protected SelfInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled,
Map<InterceptionType, Method[]> interceptionMethods)
+    protected SelfInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled,
Map<InterceptionType, Method[]> interceptionMethods, Method aroundConstruct)
     {
-        return new SelfInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes,
beanClass, interceptionMethods);
+        return new SelfInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes,
beanClass, interceptionMethods, aroundConstruct);
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
Wed Jul 17 13:39:12 2013
@@ -42,6 +42,9 @@ public class InjectableConstructor<T> ex
     /** Injectable constructor instance */
     protected Constructor<T> con;
 
+    private Object[] params = null;
+    private T instance;
+
     /**
      * Sets the constructor.
      * 
@@ -59,12 +62,37 @@ public class InjectableConstructor<T> ex
      */
     public T doInjection()
     {
-        T instance;
-        
-        List<InjectionPoint> injectedPoints = getInjectionPoints(con);
-        List<Object> list = new ArrayList<Object>();
-                
-        
+        try
+        {
+            if(!con.isAccessible())
+            {
+                getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(con,
true);
+            }
+            
+            instance = con.newInstance(createParameters());
+            return instance;
+        }
+        catch (Exception e)
+        {
+            throw new WebBeansException(e);
+        }
+    }
+
+    public T getInstance()
+    {
+        return instance;
+    }
+
+    public Object[] createParameters()
+    {
+        if (params != null)
+        {
+            return params;
+        }
+
+        final List<Object> list = new ArrayList<Object>();
+        final List<InjectionPoint> injectedPoints = getInjectionPoints(con);
+
         for(int i=0;i<injectedPoints.size();i++)
         {
             for(InjectionPoint point : injectedPoints)
@@ -82,22 +110,7 @@ public class InjectableConstructor<T> ex
                 }
             }
         }
-
-        try
-        {
-            if(!con.isAccessible())
-            {
-                getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(con,
true);
-            }
-            
-            instance = con.newInstance(list.toArray());
-
-        }
-        catch (Exception e)
-        {
-            throw new WebBeansException(e);
-        }
-
-        return instance;
+        params = list.toArray(new Object[list.size()]);
+        return params;
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
Wed Jul 17 13:39:12 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.webbeans.intercept;
 
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
@@ -31,19 +33,19 @@ public abstract class AbstractInvocation
 {
 
     private T target;
-    private Method method;
+    private AccessibleObject member;
     private Object[] parameters;
     private Map<String, Object> contextData;
     private Object timer;
 
-    public AbstractInvocationContext(T target, Method method, Object[] parameters)
+    public AbstractInvocationContext(T target, AccessibleObject member, Object[] parameters)
     {
         this.target = target;
-        this.method = method;
+        this.member = member;
         this.parameters = parameters;
-        if (!method.isAccessible())
+        if (!member.isAccessible())
         {
-            method.setAccessible(true);
+            member.setAccessible(true);
         }
     }
 
@@ -62,7 +64,11 @@ public abstract class AbstractInvocation
     @Override
     public Method getMethod()
     {
-        return method;
+        if (Method.class.isInstance(member))
+        {
+            return Method.class.cast(member);
+        }
+        return null;
     }
 
     @Override
@@ -98,12 +104,27 @@ public abstract class AbstractInvocation
     {
         try
         {
-            return method.invoke(target, parameters);
+            final Method m = getMethod();
+            if (m != null)
+            {
+                return m.invoke(target, parameters);
+            }
+            return getConstructor().newInstance(parameters);
         }
-        catch (InvocationTargetException ite)
+        catch (final InvocationTargetException ite)
         {
             // unpack the reflection Exception
             throw ExceptionUtil.throwAsRuntimeException(ite.getCause());
         }
     }
+
+    // @Override
+    public Constructor getConstructor()
+    {
+        if (Constructor.class.isInstance(member))
+        {
+            return Constructor.class.cast(member);
+        }
+        return null;
+    }
 }

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AroundConstruct.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AroundConstruct.java?rev=1504132&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AroundConstruct.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AroundConstruct.java
Wed Jul 17 13:39:12 2013
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.intercept;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AroundConstruct
+{
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java
Wed Jul 17 13:39:12 2013
@@ -18,7 +18,7 @@
  */
 package org.apache.webbeans.intercept;
 
-import java.lang.reflect.Method;
+import java.lang.reflect.AccessibleObject;
 import java.util.List;
 import java.util.Map;
 
@@ -31,12 +31,14 @@ import javax.enterprise.inject.spi.Inter
 public class InterceptorInvocationContext<T> extends AbstractInvocationContext<T>
 {
 
-    private InterceptionType type;
-    private List<Interceptor<?>> interceptors;
-    private Map<Interceptor<?>, ?> instances;
-    private int index = 0;
+    protected InterceptionType type;
+    protected List<Interceptor<?>> interceptors;
+    protected Map<Interceptor<?>, ?> instances;
+    protected int index = 0;
     
-    public InterceptorInvocationContext(T target, InterceptionType type, List<Interceptor<?>>
interceptors, Map<Interceptor<?>, ?> instances, Method method, Object[] parameters)
+    public InterceptorInvocationContext(T target, InterceptionType type,
+                                        List<Interceptor<?>> interceptors, Map<Interceptor<?>,
?> instances,
+                                        AccessibleObject method, Object[] parameters)
     {
         super(target, method, parameters);
         this.type = type;
@@ -61,7 +63,12 @@ public class InterceptorInvocationContex
         }
         else
         {
-            return super.proceed();
+            return realProceed();
         }
     }
+
+    protected Object realProceed() throws Exception
+    {
+        return super.proceed();
+    }
 }

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=1504132&r1=1504131&r2=1504132&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 Jul 17 13:39:12 2013
@@ -18,6 +18,20 @@
  */
 package org.apache.webbeans.intercept;
 
+import org.apache.webbeans.annotation.AnnotationManager;
+import org.apache.webbeans.component.BeanAttributesImpl;
+import org.apache.webbeans.component.SelfInterceptorBean;
+import org.apache.webbeans.component.creation.BeanAttributesBuilder;
+import org.apache.webbeans.component.creation.SelfInterceptorBeanBuilder;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.CDI11s;
+import org.apache.webbeans.util.ClassUtil;
+
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.enterprise.inject.spi.Annotated;
@@ -47,18 +61,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.webbeans.annotation.AnnotationManager;
-import org.apache.webbeans.component.BeanAttributesImpl;
-import org.apache.webbeans.component.SelfInterceptorBean;
-import org.apache.webbeans.component.creation.BeanAttributesBuilder;
-import org.apache.webbeans.component.creation.SelfInterceptorBeanBuilder;
-import org.apache.webbeans.config.OpenWebBeansConfiguration;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.util.AnnotationUtil;
-import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.ClassUtil;
-
 /**
  * Class to calculate interceptor resolution information.
  * It also handles the proxy caching and applying.
@@ -205,11 +207,15 @@ public class InterceptorResolutionServic
     {
         if (classInterceptorBindings.size() > 0)
         {
-            allUsedCdiInterceptors.addAll(
-                    webBeansContext.getBeanManagerImpl().resolveInterceptors(InterceptionType.POST_CONSTRUCT,
AnnotationUtil.asArray(classInterceptorBindings)));
+            final Annotation[] interceptorBindings = AnnotationUtil.asArray(classInterceptorBindings);
+            final BeanManagerImpl beanManagerImpl = webBeansContext.getBeanManagerImpl();
 
-            allUsedCdiInterceptors.addAll(
-                    webBeansContext.getBeanManagerImpl().resolveInterceptors(InterceptionType.PRE_DESTROY,
AnnotationUtil.asArray(classInterceptorBindings)));
+            allUsedCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.POST_CONSTRUCT,
interceptorBindings));
+            allUsedCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(InterceptionType.PRE_DESTROY,
interceptorBindings));
+            if (CDI11s.AROUND_CONSTRUCT != null)
+            {
+                allUsedCdiInterceptors.addAll(beanManagerImpl.resolveInterceptors(CDI11s.AROUND_CONSTRUCT,
interceptorBindings));
+            }
         }
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/LifecycleInterceptorInvocationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/LifecycleInterceptorInvocationContext.java?rev=1504132&r1=1504131&r2=1504132&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/LifecycleInterceptorInvocationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/LifecycleInterceptorInvocationContext.java
Wed Jul 17 13:39:12 2013
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
 import javax.interceptor.InvocationContext;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
@@ -139,4 +140,10 @@ public class LifecycleInterceptorInvocat
     {
         return null;
     }
+
+    // @Override
+    public Constructor getConstructor()
+    {
+        return null;
+    }
 }

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=1504132&r1=1504131&r2=1504132&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 Jul 17 13:39:12 2013
@@ -28,6 +28,7 @@ import org.apache.webbeans.inject.Inject
 import org.apache.webbeans.inject.InjectableMethod;
 import org.apache.webbeans.intercept.DecoratorHandler;
 import org.apache.webbeans.intercept.DefaultInterceptorHandler;
+import org.apache.webbeans.intercept.InterceptorInvocationContext;
 import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
 import org.apache.webbeans.intercept.LifecycleInterceptorInvocationContext;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
@@ -36,6 +37,7 @@ import org.apache.webbeans.proxy.Interce
 import org.apache.webbeans.proxy.OwbInterceptorProxy;
 import org.apache.webbeans.spi.ResourceInjectionService;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.CDI11s;
 import org.apache.webbeans.util.ExceptionUtil;
 
 import javax.decorator.Delegate;
@@ -104,6 +106,8 @@ public class InjectionTargetImpl<T> exte
      */
     private List<Interceptor<?>> preDestroyInterceptors;
 
+    private List<Interceptor<?>> aroundConstructInterceptors;
+
     /**
      * static information about Interceptors and Decorators of that bean
      */
@@ -151,13 +155,15 @@ public class InjectionTargetImpl<T> exte
     }
 
     public void setInterceptorInfo(BeanInterceptorInfo interceptorInfo, Class<? extends
T> proxyClass, Map<Method, List<Interceptor<?>>> methodInterceptors,
-                                   List<Interceptor<?>> postConstructInterceptors,
List<Interceptor<?>> preDestroyInterceptors, String beanPassivationId)
+                                   List<Interceptor<?>> postConstructInterceptors,
List<Interceptor<?>> preDestroyInterceptors, List<Interceptor<?>>
aroundConstruct,
+                                   String beanPassivationId)
     {
         this.interceptorInfo = interceptorInfo;
         this.proxyClass = proxyClass;
         this.methodInterceptors = methodInterceptors;
         this.postConstructInterceptors = postConstructInterceptors;
         this.preDestroyInterceptors = preDestroyInterceptors;
+        this.aroundConstructInterceptors = aroundConstruct;
         this.beanPassivationId = beanPassivationId;
     }
 
@@ -178,30 +184,61 @@ public class InjectionTargetImpl<T> exte
     @Override
     public T produce(CreationalContext<T> creationalContext)
     {
-        CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>)
creationalContext;
-        T instance = newInstance(creationalContextImpl);
+        final CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>)
creationalContext;
+        final Map<Interceptor<?>,Object> interceptorInstances  = new HashMap<Interceptor<?>,
Object>();
+        final Contextual<T> oldContextual = creationalContextImpl.getContextual();
+        final boolean hasAroundConstruct = aroundConstructInterceptors != null &&
!aroundConstructInterceptors.isEmpty();
 
-        if (proxyClass != null)
+        if (proxyClass != null || hasAroundConstruct)
         {
-            Contextual<T> oldContextual = creationalContextImpl.getContextual();
             // apply interceptorInfo
-            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
-
-            Map<Interceptor<?>,Object> interceptorInstances  = new HashMap<Interceptor<?>,
Object>();
 
             // create EJB-style interceptors
-            for (Interceptor interceptorBean : interceptorInfo.getEjbInterceptors())
+            for (final Interceptor interceptorBean : interceptorInfo.getEjbInterceptors())
             {
                 creationalContextImpl.putContextual(interceptorBean);
                 interceptorInstances.put(interceptorBean, interceptorBean.create(creationalContext));
             }
 
             // create CDI-style interceptors
-            for (Interceptor interceptorBean : interceptorInfo.getCdiInterceptors())
+            for (final Interceptor interceptorBean : interceptorInfo.getCdiInterceptors())
             {
                 creationalContextImpl.putContextual(interceptorBean);
                 interceptorInstances.put(interceptorBean, interceptorBean.create(creationalContext));
             }
+        }
+
+        T instance;
+        if (hasAroundConstruct)
+        {
+            try
+            {
+                final Constructor<T> cons = getConstructor().getJavaMember();
+                final InjectableConstructor<T> injectableConstructor = new InjectableConstructor<T>(cons,
this, creationalContextImpl);
+                new InterceptorInvocationContext<T>(null, CDI11s.AROUND_CONSTRUCT,
aroundConstructInterceptors, interceptorInstances,
+                                                    cons, injectableConstructor.createParameters())
+                {
+                    @Override
+                    protected Object realProceed() throws Exception
+                    {
+                        return injectableConstructor.doInjection();
+                    }
+                }.proceed();
+                instance = injectableConstructor.getInstance();
+            }
+            catch (final Exception e) // CDI 1.0
+            {
+                throw ExceptionUtil.throwAsRuntimeException(e);
+            }
+        }
+        else
+        {
+            instance = newInstance(creationalContextImpl);
+        }
+
+        if (proxyClass != null)
+        {
+            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
 
             // register the bean itself for self-interception
             if (interceptorInfo.getSelfInterceptorBean() != null)

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/CDI11s.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/CDI11s.java?rev=1504132&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/CDI11s.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/CDI11s.java Wed
Jul 17 13:39:12 2013
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.util;
+
+import javax.enterprise.inject.spi.InterceptionType;
+
+public class CDI11s
+{
+    public static final InterceptionType AROUND_CONSTRUCT;
+    static {
+        InterceptionType type;
+        try
+        {
+            type = InterceptionType.class.cast(InterceptionType.class.getDeclaredField("AROUND_CONSTRUCT").get(null));
+        }
+        catch (final Throwable e)
+        {
+            type = null;
+        }
+        AROUND_CONSTRUCT = type;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/constructor/AroundConstructTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/constructor/AroundConstructTest.java?rev=1504132&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/constructor/AroundConstructTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/constructor/AroundConstructTest.java
Wed Jul 17 13:39:12 2013
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.interceptors.constructor;
+
+import org.apache.webbeans.intercept.AroundConstruct;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InterceptorBinding;
+import javax.interceptor.InvocationContext;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+
+public class AroundConstructTest extends AbstractUnitTest
+{
+    @Inject
+    private IAmBuiltWithMyConstructor bean;
+
+    @Test @Ignore("needs CDI 1.1")
+    public void checkBeanWasBuiltWithItsConstructorAndIntercepted()
+    {
+        addInterceptor(IllGetYourConstructorInvocation.class);
+
+        final Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(IAmBuiltWithMyConstructor.class);
+        beanClasses.add(Foo.class);
+
+        startContainer(beanClasses, Collections.<String>emptyList(), true);
+        assertEquals(1, IllGetYourConstructorInvocation.count);
+        shutDownContainer();
+
+    }
+
+    @ConstructorInterceptorBinding
+    public static class IAmBuiltWithMyConstructor
+    {
+        private final Foo foo;
+
+        @Inject
+        public IAmBuiltWithMyConstructor(final Foo foo)
+        {
+            if (foo == null) {
+                throw new NullPointerException();
+            }
+
+            this.foo = foo;
+        }
+    }
+
+    public static class Foo
+    {
+    }
+
+    @ConstructorInterceptorBinding
+    @Interceptor
+    public static class IllGetYourConstructorInvocation
+    {
+        public static int count = 0;
+
+        @AroundConstruct
+        public Object around(final InvocationContext ic) throws Exception
+        {
+            count++;
+            return ic.proceed();
+        }
+    }
+
+    @InterceptorBinding
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target( { ElementType.TYPE, ElementType.METHOD })
+    public @interface ConstructorInterceptorBinding
+    {
+    }
+}



Mime
View raw message