openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1606391 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ component/creation/ config/ decorator/ inject/ intercept/ portable/ portable/events/discovery/ util/
Date Sat, 28 Jun 2014 20:31:11 GMT
Author: rmannibucau
Date: Sat Jun 28 20:31:11 2014
New Revision: 1606391

URL: http://svn.apache.org/r1606391
Log:
starting to rework @AroundConstruct

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClass.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    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/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/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.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/DefaultInterceptorHandler.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/InterceptorsManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java?rev=1606391&r1=1606390&r2=1606391&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java Sat Jun 28 20:31:11 2014
@@ -124,13 +124,13 @@ public abstract class AbstractOwbBean<T>
 
             final Producer<T> producer = getProducer();
             final T instance = producer.produce(creationalContext);
-            if (producer instanceof InjectionTarget)
+            if (producer instanceof InjectionTarget && instance != null) // @AroundConstruct can skip proceed and then it returns null
             {
                 final InjectionTarget<T> injectionTarget = (InjectionTarget<T>)producer;
                 injectionTarget.inject(instance, creationalContext);
                 injectionTarget.postConstruct(instance);
             }
-            if (getScope().equals(Dependent.class))
+            if (getScope().equals(Dependent.class) && instance != null)
             {
                 ((CreationalContextImpl<T>)creationalContext).addDependent(this, instance);
             }

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -48,10 +48,9 @@ public class CdiInterceptorBean<T> exten
                               Class<T> beanClass,
                               Set<Annotation> interceptorBindings,
                               boolean enabled,
-                              Map<InterceptionType, Method[]> interceptionMethods,
-                              Method aroundConstruct)
+                              Map<InterceptionType, Method[]> interceptionMethods)
     {
-        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods, aroundConstruct);
+        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods);
         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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -43,10 +43,9 @@ public class EjbInterceptorBean<T> exten
                               AnnotatedType<T> annotated,
                               BeanAttributes<T> beanAttributes,
                               Class<T> beanClass,
-                              Map<InterceptionType, Method[]> interceptionMethods,
-                              Method aroundConstruct)
+                              Map<InterceptionType, Method[]> interceptionMethods)
     {
-        super(webBeansContext, annotated, beanAttributes, beanClass, interceptionMethods, aroundConstruct);
+        super(webBeansContext, annotated, beanAttributes, beanClass, interceptionMethods);
     }
 
     /**

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -56,14 +56,12 @@ 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,
@@ -85,12 +83,6 @@ public abstract class InterceptorBean<T>
             }
         }
 
-        aroundConstructMethod = aroundConstruct;
-        if (aroundConstructMethod != null && !aroundConstructMethod.isAccessible())
-        {
-            aroundConstructMethod.setAccessible(true);
-        }
-
         Method[] aroundInvokeMethods = interceptionMethods.get(InterceptionType.AROUND_INVOKE);
         if (aroundInvokeMethods != null && aroundInvokeMethods.length == 1)
         {
@@ -102,10 +94,9 @@ public abstract class InterceptorBean<T>
                            AnnotatedType<T> annotatedType,
                            BeanAttributes<T> beanAttributes,
                            Class<T> beanClass,
-                           Map<InterceptionType, Method[]> interceptionMethods,
-                           Method aroundConstructMethod)
+                           Map<InterceptionType, Method[]> interceptionMethods)
     {
-        this(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods, aroundConstructMethod,
+        this(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods,
                 new InterceptorInjectionTargetFactory<T>(annotatedType, webBeansContext));
     }
 
@@ -132,8 +123,7 @@ public abstract class InterceptorBean<T>
     @Override
     public boolean intercepts(InterceptionType interceptionType)
     {
-        return interceptionMethods.containsKey(interceptionType)
-                || (interceptionType == InterceptionType.AROUND_CONSTRUCT && aroundConstructMethod != null);
+        return interceptionMethods.containsKey(interceptionType);
     }
 
     @Override
@@ -141,11 +131,6 @@ public abstract class InterceptorBean<T>
     {
         try
         {
-            if (InterceptionType.AROUND_CONSTRUCT == interceptionType && aroundConstructMethod != null)
-            {
-                return aroundConstructMethod.invoke(instance, invocationContext);
-            }
-
             if (InterceptionType.AROUND_INVOKE == interceptionType && aroundInvokeMethod != null)
             {
                 return aroundInvokeMethod.invoke(instance, invocationContext);

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -47,10 +47,9 @@ public class SelfInterceptorBean<T> exte
                                AnnotatedType<T> annotatedType,
                                BeanAttributes<T> beanAttributes,
                                Class<T> beanClass,
-                               Map<InterceptionType, Method[]> interceptionMethods,
-                               Method aroundConstruct)
+                               Map<InterceptionType, Method[]> interceptionMethods)
     {
-        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods, aroundConstruct,
+        super(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods,
                 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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -79,8 +79,8 @@ public class CdiInterceptorBeanBuilder<T
     }
 
     @Override
-    protected CdiInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled, Map<InterceptionType, Method[]> interceptionMethods, Method aroundConstruct)
+    protected CdiInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled, Map<InterceptionType, Method[]> interceptionMethods)
     {
-        return new CdiInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes, beanClass, interceptorBindings, enabled, interceptionMethods, aroundConstruct);
+        return new CdiInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes, beanClass, interceptorBindings, enabled, interceptionMethods);
     }
 }

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -68,8 +68,8 @@ public class EjbInterceptorBeanBuilder<T
     }
 
     @Override
-    protected EjbInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled, Map<InterceptionType, Method[]> interceptionMethods, Method aroundConstruct)
+    protected EjbInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled, Map<InterceptionType, Method[]> interceptionMethods)
     {
-        return new EjbInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods, aroundConstruct);
+        return new EjbInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods);
     }
 }

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -63,7 +63,6 @@ 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, BeanAttributes<T> beanAttributes)
     {
@@ -136,6 +135,7 @@ public abstract class InterceptorBeanBui
         List<AnnotatedMethod> postConstructMethods = new ArrayList<AnnotatedMethod>();
         List<AnnotatedMethod> preDestroyMethods = new ArrayList<AnnotatedMethod>();
         List<AnnotatedMethod> aroundTimeoutMethods = new ArrayList<AnnotatedMethod>();
+        List<AnnotatedMethod> aroundConstructMethods = new ArrayList<AnnotatedMethod>();
 
         // EJB related interceptors
         List<AnnotatedMethod> prePassivateMethods = new ArrayList<AnnotatedMethod>();
@@ -150,15 +150,17 @@ public abstract class InterceptorBeanBui
 
             for (AnnotatedMethod m : methods)
             {
+                int arouncConstructCount = 0;
                 if (clazz == m.getJavaMember().getDeclaringClass())
                 {
                     if (m.getAnnotation(AroundConstruct.class) != null)
                     {
-                        if (interceptionConstructor != null)
+                        if (arouncConstructCount > 0)
                         {
                             throw new WebBeansConfigurationException("only one AroundConstruct allowed per Interceptor");
                         }
-                        interceptionConstructor = m.getJavaMember();
+                        arouncConstructCount++;
+                        aroundConstructMethods.add(m);
                     }
 
                     // we only take methods from this very class and not sub- or superclasses
@@ -266,6 +268,11 @@ public abstract class InterceptorBeanBui
             interceptorFound = true;
             interceptionMethods.put(InterceptionType.POST_ACTIVATE, getMethodArray(postActivateMethods));
         }
+        if (aroundConstructMethods.size() > 0)
+        {
+            interceptorFound = true;
+            interceptionMethods.put(InterceptionType.AROUND_CONSTRUCT, getMethodArray(aroundConstructMethods));
+        }
 
         return interceptorFound;
     }
@@ -341,11 +348,10 @@ public abstract class InterceptorBeanBui
 
     protected abstract B createBean(Class<T> beanClass,
                                     boolean enabled,
-                                    Map<InterceptionType, Method[]> interceptionMethods,
-                                    Method aroundConstruct);
+                                    Map<InterceptionType, Method[]> interceptionMethods);
 
     public B getBean()
     {
-        return createBean(annotatedType.getJavaClass(), isInterceptorEnabled(), interceptionMethods, interceptionConstructor);
+        return createBean(annotatedType.getJavaClass(), isInterceptorEnabled(), interceptionMethods);
     }
 }

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -59,8 +59,8 @@ public class SelfInterceptorBeanBuilder<
     }
 
     @Override
-    protected SelfInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled, Map<InterceptionType, Method[]> interceptionMethods, Method aroundConstruct)
+    protected SelfInterceptorBean<T> createBean(Class<T> beanClass, boolean enabled, Map<InterceptionType, Method[]> interceptionMethods)
     {
-        return new SelfInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods, aroundConstruct);
+        return new SelfInterceptorBean<T>(webBeansContext, annotatedType, beanAttributes, beanClass, interceptionMethods);
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1606391&r1=1606390&r2=1606391&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java Sat Jun 28 20:31:11 2014
@@ -305,6 +305,7 @@ public class BeansDeployer
     private void registerAlternativesDecoratorsAndInterceptorsWithPriority(List<AnnotatedType<?>> annotatedTypes)
     {
         AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
+        InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();
 
         for (AnnotatedType<?> annotatedType : annotatedTypes)
         {
@@ -316,8 +317,26 @@ public class BeansDeployer
                     alternativesManager.addPriorityClazzAlternative(annotatedType.getJavaClass(), priority);
                 }
             }
-
-            //X TODO handle interceptors and decorators as well
+            if (annotatedType.getAnnotation(javax.interceptor.Interceptor.class) != null)
+            {
+                Priority priority = annotatedType.getAnnotation(Priority.class);
+                if (priority != null)
+                {
+                    final Class<?> javaClass = annotatedType.getJavaClass();
+                    interceptorsManager.addPriorityClazzInterceptor(javaClass, priority);
+                    interceptorsManager.addEnabledInterceptorClass(javaClass);
+                }
+            }
+            if (annotatedType.getAnnotation(javax.decorator.Decorator.class) != null)
+            {
+                Priority priority = annotatedType.getAnnotation(Priority.class);
+                if (priority != null)
+                {
+                    final Class<?> javaClass = annotatedType.getJavaClass();
+                    decoratorsManager.addPriorityClazzDecorator(javaClass, priority);
+                    decoratorsManager.addEnabledDecorator(javaClass);
+                }
+            }
         }
     }
 
@@ -453,11 +472,12 @@ public class BeansDeployer
      */
     private void fireAfterTypeDiscoveryEvent()
     {
-        AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
-        List<Class<?>> sortedAlternatives = alternativesManager.getPrioritizedAlternatives();
-
-        BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
-        manager.fireLifecycleEvent(new AfterTypeDiscoveryImpl(webBeansContext, sortedAlternatives));
+        final BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
+        manager.fireLifecycleEvent(new AfterTypeDiscoveryImpl(
+                webBeansContext,
+                webBeansContext.getInterceptorsManager().getPrioritizedInterceptors(),
+                webBeansContext.getDecoratorsManager().getPrioritizedDecorators(),
+                webBeansContext.getAlternativesManager().getPrioritizedAlternatives()));
         // we do not need to set back the sortedAlternatives to the AlternativesManager as the API
         // and all layers in between use a mutable List. Not very elegant but spec conform.
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java?rev=1606391&r1=1606390&r2=1606391&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorsManager.java Sat Jun 28 20:31:11 2014
@@ -27,6 +27,7 @@ import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
+import javax.annotation.Priority;
 import javax.enterprise.inject.spi.Decorator;
 
 import org.apache.webbeans.annotation.DefaultLiteral;
@@ -36,6 +37,7 @@ import org.apache.webbeans.exception.Web
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.GenericsUtil;
+import org.apache.webbeans.util.PriorityClasses;
 
 public class DecoratorsManager
 {
@@ -52,7 +54,7 @@ public class DecoratorsManager
      */
     private Set<Decorator<?>> webBeansDecorators = new CopyOnWriteArraySet<Decorator<?>>();
 
-
+    private final PriorityClasses priorityDecorators = new PriorityClasses();
 
     public DecoratorsManager(WebBeansContext webBeansContext)
     {
@@ -230,12 +232,20 @@ public class DecoratorsManager
         return ok;
     }
 
-
-
-
     public void clear()
     {
         additionalDecoratorClasses.clear();
         webBeansDecorators.clear();
+        priorityDecorators.clear();
+    }
+
+    public List<Class<?>> getPrioritizedDecorators()
+    {
+        return priorityDecorators.getSorted();
+    }
+
+    public void addPriorityClazzDecorator(final Class<?> javaClass, final Priority priority)
+    {
+        priorityDecorators.add(javaClass, priority);
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java?rev=1606391&r1=1606390&r2=1606391&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java Sat Jun 28 20:31:11 2014
@@ -19,8 +19,6 @@
 package org.apache.webbeans.inject;
 
 import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -32,6 +30,7 @@ import javax.enterprise.inject.spi.Bean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.PriorityClasses;
 
 /**
  * This class has 2 responsibilities.
@@ -67,15 +66,7 @@ public class AlternativesManager
      */
     private final Set<Class<? extends Annotation>> configuredStereotypeAlternatives = new HashSet<Class<? extends Annotation>>();
 
-    /**
-     * All the stereotypes which are either configured via XML &lt;class&gt; or
-     * have a &#064;Priority annotation.
-     * key: the class
-     * value: the priority. Alternatives from beans.xml have -1 as they are lowest prio.
-     */
-    private final List<PriorityAlternative> priorityAlternatives = new ArrayList<PriorityAlternative>();
-
-    private List<Class<?>> prioritizedAlternatives = null;
+    private final PriorityClasses priorityAlternatives = new PriorityClasses();
 
 
 
@@ -140,7 +131,7 @@ public class AlternativesManager
      */
     public void addPriorityClazzAlternative(Class<?> clazz, Priority priority)
     {
-        priorityAlternatives.add(new PriorityAlternative(clazz, priority.value()));
+        priorityAlternatives.add(clazz, priority);
     }
 
     /**
@@ -150,20 +141,7 @@ public class AlternativesManager
      */
     public List<Class<?>> getPrioritizedAlternatives()
     {
-        if (prioritizedAlternatives == null)
-        {
-            Collections.sort(priorityAlternatives);
-
-            prioritizedAlternatives = new ArrayList<Class<?>>(priorityAlternatives.size());
-
-            for (PriorityAlternative priorityAlternative : priorityAlternatives)
-            {
-                // add in reverse order
-                prioritizedAlternatives.add(priorityAlternative.clazz);
-            }
-        }
-
-        return prioritizedAlternatives;
+        return priorityAlternatives.getSorted();
     }
 
 
@@ -181,7 +159,7 @@ public class AlternativesManager
     public boolean isAlternative(Class<?> beanType, Set<Class<? extends Annotation>> stereotypes)
     {
         if(configuredAlternatives.contains(beanType) ||
-           prioritizedAlternatives.contains(beanType))
+            priorityAlternatives.contains(beanType))
         {
             return true;
         }
@@ -203,34 +181,6 @@ public class AlternativesManager
         configuredAlternatives.clear();
         configuredStereotypeAlternatives.clear();
         priorityAlternatives.clear();
-
-        prioritizedAlternatives = null;
     }
 
-    private static class PriorityAlternative implements Comparable<PriorityAlternative>
-    {
-        private final int priority;
-        private final Class<?> clazz;
-
-        public PriorityAlternative(Class<?> clazz, int priority)
-        {
-            this.clazz = clazz;
-            this.priority = priority;
-        }
-
-        @Override
-        public int compareTo(PriorityAlternative o)
-        {
-            if (priority != o.priority)
-            {
-                // sort descending
-                return (priority > o.priority) ? -1 : ((priority == o.priority) ? 0 : 1);
-            }
-
-            // we additionally sort according to the class name to at least
-            // prevent randomness if 2 classes have the same ordinal.
-            // see CDI-437 for more info about why it's broken in CDI-1.1.
-            return clazz.getName().compareTo(o.clazz.getName());
-        }
-    }
 }

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -25,6 +25,7 @@ import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.inject.Provider;
 import javax.interceptor.InvocationContext;
 
 import org.apache.webbeans.util.ExceptionUtil;
@@ -32,13 +33,14 @@ import org.apache.webbeans.util.Exceptio
 public abstract class AbstractInvocationContext<T> implements InvocationContext
 {
 
-    private T target;
+    private Provider<T> target;
     private AccessibleObject member;
     private Object[] parameters;
     private Map<String, Object> contextData;
     private Object timer;
+    private Object newInstance = null;
 
-    public AbstractInvocationContext(T target, AccessibleObject member, Object[] parameters)
+    public AbstractInvocationContext(Provider<T> target, AccessibleObject member, Object[] parameters)
     {
         this.target = target;
         this.member = member;
@@ -49,7 +51,7 @@ public abstract class AbstractInvocation
         }
     }
 
-    public AbstractInvocationContext(T target, Method method, Object[] parameters, Object timer)
+    public AbstractInvocationContext(Provider<T> target, Method method, Object[] parameters, Object timer)
     {
         this(target, method, parameters);
         this.timer = timer;
@@ -58,7 +60,7 @@ public abstract class AbstractInvocation
     @Override
     public T getTarget()
     {
-        return target;
+        return target.get();
     }
 
     @Override
@@ -102,14 +104,24 @@ public abstract class AbstractInvocation
     @Override
     public Object proceed() throws Exception
     {
+        return doProceed();
+    }
+
+    public Object doProceed() throws Exception
+    {
+        if (newInstance != null) // already called
+        {
+            return newInstance;
+        }
         try
         {
             final Method m = getMethod();
             if (m != null)
             {
-                return m.invoke(target, parameters);
+                return m.invoke(target.get(), parameters);
             }
-            return getConstructor().newInstance(parameters);
+            newInstance = getConstructor().newInstance(parameters);
+            return newInstance;
         }
         catch (final InvocationTargetException ite)
         {
@@ -118,6 +130,11 @@ public abstract class AbstractInvocation
         }
     }
 
+    public Object getNewInstance()
+    {
+        return newInstance;
+    }
+
     // @Override
     public Constructor getConstructor()
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java?rev=1606391&r1=1606390&r2=1606391&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java Sat Jun 28 20:31:11 2014
@@ -32,6 +32,7 @@ import javax.enterprise.inject.spi.BeanM
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
+import javax.inject.Provider;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.NotSerializableException;
@@ -133,7 +134,7 @@ public class DefaultInterceptorHandler<T
             }
 
             InterceptorInvocationContext<T> ctx
-                = new InterceptorInvocationContext<T>(delegate, InterceptionType.AROUND_INVOKE, methodInterceptors, instances, method, parameters);
+                = new InterceptorInvocationContext<T>(new InstanceProvider(delegate), InterceptionType.AROUND_INVOKE, methodInterceptors, instances, method, parameters);
 
             return ctx.proceed();
         }
@@ -322,4 +323,20 @@ public class DefaultInterceptorHandler<T
         }
         return (Interceptor<?>) beanManager.getPassivationCapableBean(id);
     }
+
+    private static class InstanceProvider<T> implements Provider<T>
+    {
+        private final T value;
+
+        public InstanceProvider(final T delegate)
+        {
+            this.value = delegate;
+        }
+
+        @Override
+        public T get()
+        {
+            return value;
+        }
+    }
 }

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=1606391&r1=1606390&r2=1606391&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 Sat Jun 28 20:31:11 2014
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
+import javax.inject.Provider;
 
 /**
  * InvocationContext for business method interceptors
@@ -36,11 +37,11 @@ public class InterceptorInvocationContex
     protected Map<Interceptor<?>, ?> instances;
     protected int index = 0;
     
-    public InterceptorInvocationContext(T target, InterceptionType type,
+    public InterceptorInvocationContext(Provider<T> provider, InterceptionType type,
                                         List<Interceptor<?>> interceptors, Map<Interceptor<?>, ?> instances,
                                         AccessibleObject method, Object[] parameters)
     {
-        super(target, method, parameters);
+        super(provider, method, parameters);
         this.type = type;
         this.interceptors = interceptors;
         this.instances = instances;

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=1606391&r1=1606390&r2=1606391&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 20:31:11 2014
@@ -35,6 +35,7 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.AnnotatedType;
@@ -46,6 +47,7 @@ import javax.interceptor.ExcludeClassInt
 import javax.interceptor.Interceptors;
 import javax.interceptor.InvocationContext;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
@@ -115,6 +117,7 @@ public class InterceptorResolutionServic
         allUsedEjbInterceptors.addAll(classLevelEjbInterceptors);
 
         Map<Method, BusinessMethodInterceptorInfo> businessMethodInterceptorInfos = new HashMap<Method, BusinessMethodInterceptorInfo>();
+        Map<Constructor<?>, BusinessMethodInterceptorInfo> constructorInterceptorInfos = new HashMap<Constructor<?>, BusinessMethodInterceptorInfo>();
 
         List<Method> nonInterceptedMethods = new ArrayList<Method>();
 
@@ -139,6 +142,17 @@ public class InterceptorResolutionServic
 
             businessMethodInterceptorInfos.put(annotatedMethod.getJavaMember(), methodInterceptorInfo);
         }
+        for (AnnotatedConstructor annotatedConstructor : annotatedType.getConstructors())
+        {
+            final BusinessMethodInterceptorInfo constructorInterceptorInfo = new BusinessMethodInterceptorInfo();
+            calculateEjbMethodInterceptors(constructorInterceptorInfo, allUsedEjbInterceptors, classLevelEjbInterceptors, annotatedConstructor);
+            if (constructorInterceptorInfo.isEmpty() && (selfInterceptorBean == null || !selfInterceptorBean.isAroundInvoke()))
+            {
+                continue;
+            }
+
+            constructorInterceptorInfos.put(annotatedConstructor.getJavaMember(), constructorInterceptorInfo);
+        }
 
         Map<InterceptionType, LifecycleMethodInfo> lifecycleMethodInterceptorInfos
                 = new HashMap<InterceptionType, LifecycleMethodInfo>();
@@ -179,7 +193,7 @@ public class InterceptorResolutionServic
         }
         
         return new BeanInterceptorInfo(decorators, allUsedEjbInterceptors, cdiInterceptors, selfInterceptorBean,
-                                       businessMethodInterceptorInfos,
+                                       constructorInterceptorInfos, businessMethodInterceptorInfos,
                                        nonInterceptedMethods, lifecycleMethodInterceptorInfos);
     }
 
@@ -260,6 +274,13 @@ public class InterceptorResolutionServic
                 calculateCdiMethodInterceptors(methodInterceptorInfo, interceptionType, allUsedCdiInterceptors, lifecycleMethod, classInterceptorBindings);
             }
         }
+        for (AnnotatedConstructor<?> lifecycleMethod : annotatedType.getConstructors())
+        {
+            // TODO: verifyLifecycleMethod(lifeycleAnnotation, lifecycleMethod);
+            calculateEjbMethodInterceptors(methodInterceptorInfo, allUsedEjbInterceptors, classLevelEjbInterceptors, lifecycleMethod);
+
+            calculateCdiMethodInterceptors(methodInterceptorInfo, interceptionType, allUsedCdiInterceptors, lifecycleMethod, classInterceptorBindings);
+        }
 
         if (foundMethods.size() > 0 )
         {
@@ -589,8 +610,8 @@ public class InterceptorResolutionServic
     {
 
         public BeanInterceptorInfo(List<Decorator<?>> decorators, LinkedHashSet<Interceptor<?>> ejbInterceptors,
-                                   List<Interceptor<?>> cdiInterceptors,
-                                   SelfInterceptorBean<?> selfInterceptorBean,
+                                   List<Interceptor<?>> cdiInterceptors, SelfInterceptorBean<?> selfInterceptorBean,
+                                   Map<Constructor<?>, BusinessMethodInterceptorInfo> constructorInterceptorInfos,
                                    Map<Method, BusinessMethodInterceptorInfo> businessMethodsInfo,
                                    List<Method> nonInterceptedMethods,
                                    Map<InterceptionType, LifecycleMethodInfo> lifecycleMethodInterceptorInfos)
@@ -600,6 +621,7 @@ public class InterceptorResolutionServic
             this.cdiInterceptors = cdiInterceptors;
             this.selfInterceptorBean = selfInterceptorBean;
             this.businessMethodsInfo = businessMethodsInfo;
+            this.constructorInterceptorInfos = constructorInterceptorInfos;
             this.nonInterceptedMethods = nonInterceptedMethods;
             this.lifecycleMethodInterceptorInfos = lifecycleMethodInterceptorInfos;
         }
@@ -632,6 +654,7 @@ public class InterceptorResolutionServic
          * If there is no entry then the method has neither a decorator nor an interceptor.
          */
         private Map<Method, BusinessMethodInterceptorInfo> businessMethodsInfo;
+        private Map<Constructor<?>, BusinessMethodInterceptorInfo> constructorInterceptorInfos;
 
         /**
          * all non-intercepted methods
@@ -671,6 +694,11 @@ public class InterceptorResolutionServic
             return businessMethodsInfo;
         }
 
+        public Map<Constructor<?>, BusinessMethodInterceptorInfo> getConstructorInterceptorInfos()
+        {
+            return constructorInterceptorInfos;
+        }
+
         public List<Method> getNonInterceptedMethods()
         {
             return nonInterceptedMethods;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java?rev=1606391&r1=1606390&r2=1606391&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java Sat Jun 28 20:31:11 2014
@@ -45,6 +45,7 @@ import org.apache.webbeans.exception.Web
 import javax.annotation.Priority;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.PriorityClasses;
 
 /**
  * This class keeps all the enabled interceptor classes information of a certain BeanManager.
@@ -78,6 +79,8 @@ public class InterceptorsManager
     private Map<Class<? extends Annotation>, Set<Annotation>> additionalInterceptorBindingTypes
             = new HashMap<Class<? extends Annotation>, Set<Annotation>>();
 
+    private final PriorityClasses priorityInterceptors = new PriorityClasses();
+
 
     public InterceptorsManager(WebBeansContext webBeansContext)
     {
@@ -96,6 +99,7 @@ public class InterceptorsManager
         configuredInterceptorClasses.clear();
         cdiInterceptors.clear();
         ejbInterceptors.clear();
+        priorityInterceptors.clear();
     }
 
 
@@ -163,17 +167,17 @@ public class InterceptorsManager
             throw new IllegalArgumentException(target.getName() + " is not an enabled interceptor!");
         }
 
-        final Priority p1 = src.getAnnotation(Priority.class);
-        final Priority p2 = target.getAnnotation(Priority.class);
-        if (p1 != null && p2 != null)
+        final int p1 = priorityInterceptors.getSorted().indexOf(src);
+        final int p2 = priorityInterceptors.getSorted().indexOf(target);
+        if (p1 != -1 && p2 != -1)
         {
-            return p1.value() - p2.value();
+            return p1 - p2;
         }
-        if (p1 == null && p2 != null)
+        if (p1 == -1 && p2 != -1)
         {
             return -1;
         }
-        if (p1 != null)
+        if (p1 != -1)
         {
             return 1;
         }
@@ -199,7 +203,8 @@ public class InterceptorsManager
     {
         Asserts.nullCheckForClass(interceptorClazz, "interceptorClazz can not be null");
 
-        return configuredInterceptorClasses.contains(interceptorClazz);
+        return configuredInterceptorClasses.contains(interceptorClazz)
+                || priorityInterceptors.contains(interceptorClazz);
     }
 
     public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
@@ -317,6 +322,16 @@ public class InterceptorsManager
             {
                 throw new WebBeansConfigurationException("Given class : " + interceptorClass + " is not a interceptor class");
             }   
-        }                
-    }    
+        }
+    }
+
+    public List<Class<?>> getPrioritizedInterceptors()
+    {
+        return priorityInterceptors.getSorted();
+    }
+
+    public void addPriorityClazzInterceptor(final Class<?> javaClass, final Priority priority)
+    {
+        priorityInterceptors.add(javaClass, priority);
+    }
 }

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=1606391&r1=1606390&r2=1606391&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 20:31:11 2014
@@ -28,6 +28,7 @@ import org.apache.webbeans.inject.Inject
 import org.apache.webbeans.inject.InjectableMethod;
 import org.apache.webbeans.intercept.DefaultInterceptorHandler;
 import org.apache.webbeans.intercept.InterceptorInvocationContext;
+import org.apache.webbeans.intercept.InterceptorResolutionService;
 import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
 import org.apache.webbeans.intercept.LifecycleInterceptorInvocationContext;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
@@ -61,12 +62,15 @@ import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static java.util.Arrays.asList;
+
 public class InjectionTargetImpl<T> extends AbstractProducer<T> implements InjectionTarget<T>
 {
 
@@ -128,7 +132,17 @@ public class InjectionTargetImpl<T> exte
         preDestroyInterceptors
             = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(), interceptorInfo.getCdiInterceptors(), InterceptionType.PRE_DESTROY);
 
-        aroundConstructInterceptors = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(), interceptorInfo.getCdiInterceptors(), InterceptionType.AROUND_CONSTRUCT);
+        final Constructor<?> constructor = getConstructor().getJavaMember();
+        final InterceptorResolutionService.BusinessMethodInterceptorInfo constructorInterceptorInfo =
+                                interceptorInfo.getConstructorInterceptorInfos().get(getConstructor().getJavaMember());
+        final Interceptor<?>[] constructorEjbInterceptorArray = constructorInterceptorInfo == null ?
+                                            null : constructorInterceptorInfo.getEjbInterceptors();
+        final List<Interceptor<?>> constructorEjbInterceptors = constructorEjbInterceptorArray == null ?
+                                            Collections.<Interceptor<?>>emptyList() : asList(constructorEjbInterceptorArray);
+        aroundConstructInterceptors = getLifecycleInterceptors(
+                constructorEjbInterceptors,
+                interceptorInfo.getCdiInterceptors(),
+                InterceptionType.AROUND_CONSTRUCT);
     }
 
     @Override
@@ -140,8 +154,14 @@ public class InjectionTargetImpl<T> exte
             {
                 final Constructor<T> cons = getConstructor().getJavaMember();
                 final InjectableConstructor<T> injectableConstructor = new InjectableConstructor<T>(cons, this, creationalContext);
-                return (T)new InterceptorInvocationContext<T>(null, InterceptionType.AROUND_CONSTRUCT, aroundConstructInterceptors, interceptorInstances,
-                                                    cons, injectableConstructor.createParameters()).proceed();
+                final ConstructorInstanceProvider provider = new ConstructorInstanceProvider();
+                final InterceptorInvocationContext<T> invocationContext = new InterceptorInvocationContext<T>(
+                        provider,
+                        InterceptionType.AROUND_CONSTRUCT, aroundConstructInterceptors,
+                        interceptorInstances, cons, injectableConstructor.createParameters());
+                provider.setContext(invocationContext);
+                final Object proceed = invocationContext.proceed();
+                return (T) invocationContext.getNewInstance();
             }
             catch (final Exception e) // CDI 1.0
             {
@@ -414,7 +434,7 @@ public class InjectionTargetImpl<T> exte
         return false;
     }
 
-    private List<Interceptor<?>> getLifecycleInterceptors(LinkedHashSet<Interceptor<?>> ejbInterceptors, List<Interceptor<?>> cdiInterceptors, InterceptionType interceptionType)
+    private List<Interceptor<?>> getLifecycleInterceptors(Collection<Interceptor<?>> ejbInterceptors, List<Interceptor<?>> cdiInterceptors, InterceptionType interceptionType)
     {
         List<Interceptor<?>> lifecycleInterceptors = new ArrayList<Interceptor<?>>();
 
@@ -435,4 +455,28 @@ public class InjectionTargetImpl<T> exte
 
         return lifecycleInterceptors;
     }
+
+    private static class ConstructorInstanceProvider<T> implements javax.inject.Provider<T>
+    {
+        private InterceptorInvocationContext<T> context;
+
+        @Override
+        public T get()
+        {
+            try
+            {
+                return (T) context.doProceed();
+            }
+            catch (final Exception e)
+            {
+                throw new IllegalStateException(e);
+            }
+        }
+
+        // this dependency sucks, we should find something a bit more sexy
+        public void setContext(final InterceptorInvocationContext<T> context)
+        {
+            this.context = context;
+        }
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java?rev=1606391&r1=1606390&r2=1606391&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java Sat Jun 28 20:31:11 2014
@@ -32,11 +32,18 @@ public class AfterTypeDiscoveryImpl impl
 {
     private final WebBeansContext webBeansContext;
     private final List<Class<?>> sortedAlternatives;
+    private final List<Class<?>> sortedInterceptors;
+    private final List<Class<?>> sortedDecorators;
 
-    public AfterTypeDiscoveryImpl(WebBeansContext webBeansContext, List<Class<?>> sortedAlternatives)
+    public AfterTypeDiscoveryImpl(WebBeansContext webBeansContext,
+                                  List<Class<?>> sortedInterceptors,
+                                  List<Class<?>> sortedDecorators,
+                                  List<Class<?>> sortedAlternatives)
     {
         this.webBeansContext = webBeansContext;
         this.sortedAlternatives = sortedAlternatives;
+        this.sortedInterceptors = sortedInterceptors;
+        this.sortedDecorators = sortedDecorators;
     }
 
     @Override
@@ -48,13 +55,13 @@ public class AfterTypeDiscoveryImpl impl
     @Override
     public List<Class<?>> getInterceptors()
     {
-        return null; //X TODO
+        return sortedInterceptors;
     }
 
     @Override
     public List<Class<?>> getDecorators()
     {
-        return null; //X TODO
+        return sortedDecorators;
     }
 
     @Override

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClass.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClass.java?rev=1606391&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClass.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClass.java Sat Jun 28 20:31:11 2014
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+public class PriorityClass implements Comparable<PriorityClass>
+{
+    private final int priority;
+    private final Class<?> clazz;
+
+    public PriorityClass(Class<?> clazz, int priority)
+    {
+        this.clazz = clazz;
+        this.priority = priority;
+    }
+
+    public Class<?> getClazz()
+    {
+        return clazz;
+    }
+
+    public int getPriority()
+    {
+        return priority;
+    }
+
+    @Override
+    public int compareTo(PriorityClass o)
+    {
+        if (priority != o.priority)
+        {
+            // sort descending
+            return (priority > o.priority) ? -1 : ((priority == o.priority) ? 0 : 1);
+        }
+
+        // we additionally sort according to the class name to at least
+        // prevent randomness if 2 classes have the same ordinal.
+        // see CDI-437 for more info about why it's broken in CDI-1.1.
+        return clazz.getName().compareTo(o.clazz.getName());
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java?rev=1606391&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java Sat Jun 28 20:31:11 2014
@@ -0,0 +1,70 @@
+/*
+ * 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.annotation.Priority;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class PriorityClasses
+{
+    /**
+     * All the stereotypes which are either configured via XML &lt;class&gt; or
+     * have a &#064;Priority annotation.
+     * key: the class
+     * value: the priority. Alternatives from beans.xml have -1 as they are lowest prio.
+     */
+    private final List<PriorityClass> raw = new ArrayList<PriorityClass>();
+    private List<Class<?>> sorted = null;
+
+    public void add(final Class<?> clazz, final Priority priority)
+    {
+        raw.add(new PriorityClass(clazz, priority.value()));
+    }
+
+    public List<Class<?>> getSorted()
+    {
+        if (sorted == null)
+        {
+            Collections.sort(raw);
+
+            sorted = new ArrayList<Class<?>>(raw.size());
+
+            for (PriorityClass priorityAlternative : raw)
+            {
+                // add in reverse order
+                sorted.add(priorityAlternative.getClazz());
+            }
+        }
+
+        return sorted;
+    }
+
+    public boolean contains(final Class<?> beanType)
+    {
+        return getSorted().contains(beanType);
+    }
+
+    public void clear()
+    {
+        raw.clear();
+        sorted = null;
+    }
+}



Mime
View raw message