openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1559930 - in /openwebbeans/trunk/webbeans-impl: ./ src/main/java/org/apache/webbeans/component/ src/main/java/org/apache/webbeans/config/ src/main/java/org/apache/webbeans/container/ src/main/java/org/apache/webbeans/intercept/ src/main/ja...
Date Tue, 21 Jan 2014 07:46:55 GMT
Author: arne
Date: Tue Jan 21 07:46:55 2014
New Revision: 1559930

URL: http://svn.apache.org/r1559930
Log:
OWB-897: Moved proxy-creation to AbstractProducer

Removed:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/extension/InjectionTargetBeanOWB897Test.java
Modified:
    openwebbeans/trunk/webbeans-impl/pom.xml
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewManagedBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ExtensionProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.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/InstanceProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/MetadataProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessInjectionTargetImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java

Modified: openwebbeans/trunk/webbeans-impl/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/pom.xml?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/pom.xml (original)
+++ openwebbeans/trunk/webbeans-impl/pom.xml Tue Jan 21 07:46:55 2014
@@ -44,6 +44,7 @@
         <dependency>
             <groupId>org.apache.xbean</groupId>
             <artifactId>xbean-asm4-shaded</artifactId>
+            <version>3.15</version>
         </dependency>
 
         <dependency>

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=1559930&r1=1559929&r2=1559930&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 Tue Jan 21 07:46:55 2014
@@ -18,14 +18,6 @@
  */
 package org.apache.webbeans.component;
 
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-
 import javax.enterprise.inject.spi.AnnotatedType;
 
 import org.apache.webbeans.component.spi.BeanAttributes;
@@ -34,16 +26,8 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.container.InjectionTargetFactoryImpl;
 
 import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.InterceptionType;
-import javax.enterprise.inject.spi.Interceptor;
-import javax.interceptor.AroundInvoke;
-
-import org.apache.webbeans.intercept.InterceptorResolutionService;
-import org.apache.webbeans.portable.InjectionTargetImpl;
-import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
-import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.CDI11s;
 
+import org.apache.webbeans.util.Asserts;
 
 /**
  * Abstract class for injection target beans.
@@ -102,117 +86,4 @@ public class InjectionTargetBean<T> exte
     {
         return annotatedType;
     }
-
-    /**
-     *
-     * Configure bean instance interceptor stack.
-     *
-     * This method gets invoked in the ValidateBean phase and will fill all the
-     * interceptor information into the given InjectionTargetBean
-     *
-     */
-    public <T> void defineBeanInterceptorStack()
-    {
-        if (this instanceof InterceptedMarker && getInjectionTarget() instanceof InjectionTargetImpl)
-        {
-            InjectionTargetImpl<T> injectionTarget = (InjectionTargetImpl<T>) getInjectionTarget();
-            InterceptorResolutionService.BeanInterceptorInfo interceptorInfo = webBeansContext.getInterceptorResolutionService().
-                    calculateInterceptorInfo(getTypes(), getQualifiers(), getAnnotatedType());
-
-            Map<Method, List<Interceptor<?>>> methodInterceptors = new HashMap<Method, List<Interceptor<?>>>();
-            for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo> miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
-            {
-                Method interceptedMethod = miEntry.getKey();
-                InterceptorResolutionService.BusinessMethodInterceptorInfo mii = miEntry.getValue();
-                List<Interceptor<?>> activeInterceptors = new ArrayList<Interceptor<?>>();
-
-                if (mii.getEjbInterceptors() != null)
-                {
-                    Collections.addAll(activeInterceptors, mii.getEjbInterceptors());
-                }
-                if (mii.getCdiInterceptors() != null)
-                {
-                    Collections.addAll(activeInterceptors, mii.getCdiInterceptors());
-                }
-                if (interceptorInfo.getSelfInterceptorBean() != null)
-                {
-                    if (interceptedMethod.getAnnotation(AroundInvoke.class) == null) // this check is a dirty hack for now to prevent infinite loops
-                    {
-                        // add self-interception as last interceptor in the chain.
-                        activeInterceptors.add(interceptorInfo.getSelfInterceptorBean());
-                    }
-                }
-
-                if (activeInterceptors.size() > 0)
-                {
-                    methodInterceptors.put(interceptedMethod, activeInterceptors);
-                }
-                else if (mii.getMethodDecorators() != null)
-                {
-                    methodInterceptors.put(interceptedMethod, Collections.EMPTY_LIST);
-                }
-            }
-
-            List<Interceptor<?>> postConstructInterceptors
-                    = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(), interceptorInfo.getCdiInterceptors(), InterceptionType.POST_CONSTRUCT);
-
-            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)
-            {
-                // we only need to create a proxy class for intercepted or decorated Beans
-                InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
-
-                ClassLoader classLoader = getBeanClass().getClassLoader();
-
-                Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
-                Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new Method[interceptorInfo.getNonInterceptedMethods().size()]);
-
-                proxyClass = (Class<? extends T>) pf.createProxyClass(this, classLoader, getReturnType(), businessMethods, nonInterceptedMethods);
-
-                // now we collect the post-construct and pre-destroy interceptors
-
-            }
-
-            injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors, postConstructInterceptors, preDestroyInterceptors, aroundConstruct, getId());
-        }
-
-    }
-
-
-    private List<Interceptor<?>> getLifecycleInterceptors(LinkedHashSet<Interceptor<?>> ejbInterceptors, List<Interceptor<?>> cdiInterceptors, InterceptionType interceptionType)
-    {
-        List<Interceptor<?>> lifecycleInterceptors = new ArrayList<Interceptor<?>>();
-
-        for (Interceptor<?> ejbInterceptor : ejbInterceptors)
-        {
-            if (ejbInterceptor.intercepts(interceptionType))
-            {
-                lifecycleInterceptors.add(ejbInterceptor);
-            }
-        }
-        for (Interceptor<?> cdiInterceptor : cdiInterceptors)
-        {
-            if (cdiInterceptor.intercepts(interceptionType))
-            {
-                lifecycleInterceptors.add(cdiInterceptor);
-            }
-        }
-
-        return lifecycleInterceptors;
-    }
-
-
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewManagedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewManagedBean.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewManagedBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewManagedBean.java Tue Jan 21 07:46:55 2014
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.portable.AbstractProducer;
 
 /**
  * Component definition with {@link javax.enterprise.inject.New} binding annotation.
@@ -44,7 +45,11 @@ public class NewManagedBean<T> extends M
                           Set<InjectionPoint> injectionPoints)
     {
         super(webBeansContext, webBeansType, annotatedType, beanAttributes, beanClass);
-        defineBeanInterceptorStack();
+        if (getProducer() instanceof AbstractProducer)
+        {
+            AbstractProducer<T> producer = (AbstractProducer<T>)getProducer();
+            producer.defineInterceptorStack(this, annotatedType, webBeansContext);
+        }
     }
 
     /**

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=1559930&r1=1559929&r2=1559930&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 Tue Jan 21 07:46:55 2014
@@ -25,7 +25,6 @@ import org.apache.webbeans.component.Cdi
 import org.apache.webbeans.component.DecoratorBean;
 import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.InjectionTargetBean;
-import org.apache.webbeans.component.InterceptedMarker;
 import org.apache.webbeans.component.ManagedBean;
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.component.ProducerFieldBean;
@@ -50,6 +49,7 @@ import org.apache.webbeans.exception.inj
 import org.apache.webbeans.exception.inject.DeploymentException;
 import org.apache.webbeans.exception.inject.InconsistentSpecializationException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.portable.AbstractProducer;
 import org.apache.webbeans.portable.AnnotatedElementFactory;
 import org.apache.webbeans.portable.events.ProcessAnnotatedTypeImpl;
 import org.apache.webbeans.portable.events.ProcessBeanImpl;
@@ -82,6 +82,7 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import java.io.IOException;
@@ -427,7 +428,7 @@ public class BeansDeployer
      * 
      * @param beans deployed beans
      */
-    private void validate(Set<Bean<?>> beans)
+    private <T> void validate(Set<Bean<?>> beans)
     {
         BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
         
@@ -448,10 +449,23 @@ public class BeansDeployer
                     beanNames.push(beanName);
                 }
                 
-                
-                if (bean instanceof InjectionTargetBean && bean instanceof InterceptedMarker)
+                if (bean instanceof OwbBean && !(bean instanceof Interceptor) && !(bean instanceof Decorator))
                 {
-                    ((InjectionTargetBean<Object>) bean).defineBeanInterceptorStack();
+                    OwbBean<T> owbBean = (OwbBean<T>)bean;
+                    if (owbBean.getProducer() instanceof AbstractProducer)
+                    {
+                        AbstractProducer<T> producer = (AbstractProducer<T>)owbBean.getProducer();
+                        AnnotatedType<T> annotatedType;
+                        if (owbBean instanceof InjectionTargetBean)
+                        {
+                            annotatedType = ((InjectionTargetBean<T>)owbBean).getAnnotatedType();
+                        }
+                        else
+                        {
+                            annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(owbBean.getReturnType());
+                        }
+                        producer.defineInterceptorStack(owbBean, annotatedType, webBeansContext);
+                    }
                 }
                 
                 //Check passivation scope

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java Tue Jan 21 07:46:55 2014
@@ -58,7 +58,7 @@ public class InjectionTargetFactoryImpl<
     {
         final InjectionTargetImpl<T> injectionTarget
             = new InjectionTargetImpl<T>(annotatedType, createInjectionPoints(bean), webBeansContext, getPostConstructMethods(), getPreDestroyMethods());
-        return webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEvent(injectionTarget, annotatedType).getCompleteInjectionTarget();
+        return webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEvent(injectionTarget, annotatedType).getInjectionTarget();
     }
 
     protected Set<InjectionPoint> createInjectionPoints(Bean<T> bean)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DecoratorHandler.java Tue Jan 21 07:46:55 2014
@@ -22,7 +22,7 @@ import org.apache.webbeans.component.Owb
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
 import org.apache.webbeans.intercept.InterceptorResolutionService.BusinessMethodInterceptorInfo;
-import org.apache.webbeans.portable.InjectionTargetImpl;
+import org.apache.webbeans.portable.AbstractProducer;
 import org.apache.webbeans.proxy.InterceptorHandler;
 import org.apache.webbeans.util.ExceptionUtil;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -188,12 +188,12 @@ public class DecoratorHandler implements
 
         passivationId = in.readUTF();
         final Bean<?> bean = beanManager.getPassivationCapableBean(passivationId);
-        if (OwbBean.class.isInstance(bean))
+        if (bean instanceof OwbBean)
         {
-            final Producer injectionTarget = OwbBean.class.cast(bean).getProducer();
-            if (InjectionTargetImpl.class.isInstance(injectionTarget))
+            final Producer<?> producer = ((OwbBean<?>)bean).getProducer();
+            if (producer instanceof AbstractProducer)
             {
-                interceptorInfo = InjectionTargetImpl.class.cast(injectionTarget).getInterceptorInfo();
+                interceptorInfo = ((AbstractProducer<?>)producer).getInterceptorInfo();
             }
             else
             {

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=1559930&r1=1559929&r2=1559930&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 Tue Jan 21 07:46:55 2014
@@ -63,12 +63,7 @@ public class InterceptorInvocationContex
         }
         else
         {
-            return realProceed();
+            return super.proceed();
         }
     }
-
-    protected Object realProceed() throws Exception
-    {
-        return super.proceed();
-    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java Tue Jan 21 07:46:55 2014
@@ -18,16 +18,45 @@
  */
 package org.apache.webbeans.portable;
 
+import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
+import javax.decorator.Delegate;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.PassivationCapable;
 import javax.enterprise.inject.spi.Producer;
+import javax.interceptor.AroundInvoke;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.intercept.DecoratorHandler;
+import org.apache.webbeans.intercept.DefaultInterceptorHandler;
+import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
+import org.apache.webbeans.intercept.InterceptorResolutionService.BusinessMethodInterceptorInfo;
+import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
+import org.apache.webbeans.proxy.InterceptorHandler;
+import org.apache.webbeans.proxy.OwbInterceptorProxy;
 
 public abstract class AbstractProducer<T> implements Producer<T>
 {
 
     private Set<InjectionPoint> injectionPoints;
+    private Class<? extends T> proxyClass;
+    private String passivationId;
+    private BeanInterceptorInfo interceptorInfo;
+    private InterceptorDecoratorProxyFactory proxyFactory;
+    private Map<Method, List<Interceptor<?>>> methodInterceptors;
 
     public AbstractProducer()
     {
@@ -39,6 +68,78 @@ public abstract class AbstractProducer<T
         // this shares the InjectionPoints with the owning component for now
         injectionPoints = points;
     }
+
+    /**
+     *
+     * Configure bean instance interceptor stack.
+     *
+     * This method gets invoked in the ValidateBean phase and will fill all the
+     * interceptor information into the given InjectionTargetBean
+     *
+     */
+    public void defineInterceptorStack(Bean<T> bean, AnnotatedType<T> annotatedType, WebBeansContext webBeansContext)
+    {
+        interceptorInfo = webBeansContext.getInterceptorResolutionService().
+                calculateInterceptorInfo(bean.getTypes(), bean.getQualifiers(), annotatedType);
+        proxyFactory = webBeansContext.getInterceptorDecoratorProxyFactory();
+        if (bean instanceof PassivationCapable)
+        {
+            PassivationCapable passivationCapable = (PassivationCapable)bean;
+            passivationId = passivationCapable.getId();
+        }
+
+        methodInterceptors = new HashMap<Method, List<Interceptor<?>>>();
+        for (Map.Entry<Method, BusinessMethodInterceptorInfo> miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
+        {
+            Method interceptedMethod = miEntry.getKey();
+            BusinessMethodInterceptorInfo mii = miEntry.getValue();
+            List<Interceptor<?>> activeInterceptors = new ArrayList<Interceptor<?>>();
+
+            if (mii.getEjbInterceptors() != null)
+            {
+                Collections.addAll(activeInterceptors, mii.getEjbInterceptors());
+            }
+            if (mii.getCdiInterceptors() != null)
+            {
+                Collections.addAll(activeInterceptors, mii.getCdiInterceptors());
+            }
+            if (interceptorInfo.getSelfInterceptorBean() != null)
+            {
+                if (interceptedMethod.getAnnotation(AroundInvoke.class) == null) // this check is a dirty hack for now to prevent infinite loops
+                {
+                    // add self-interception as last interceptor in the chain.
+                    activeInterceptors.add(interceptorInfo.getSelfInterceptorBean());
+                }
+            }
+
+            if (activeInterceptors.size() > 0)
+            {
+                methodInterceptors.put(interceptedMethod, activeInterceptors);
+            }
+            else if (mii.getMethodDecorators() != null)
+            {
+                methodInterceptors.put(interceptedMethod, Collections.EMPTY_LIST);
+            }
+        }
+
+        defineLifecycleInterceptors(bean, annotatedType, webBeansContext);
+
+        if (needsProxy())
+        {
+            // we only need to create a proxy class for intercepted or decorated Beans
+            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
+
+            ClassLoader classLoader = annotatedType.getJavaClass().getClassLoader();
+
+            Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
+            Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new Method[interceptorInfo.getNonInterceptedMethods().size()]);
+
+            proxyClass = (Class<? extends T>) pf.createProxyClass(bean, classLoader, annotatedType.getJavaClass(), businessMethods, nonInterceptedMethods);
+
+            // now we collect the post-construct and pre-destroy interceptors
+
+        }
+    }
     
     @Override
     public Set<InjectionPoint> getInjectionPoints()
@@ -46,8 +147,121 @@ public abstract class AbstractProducer<T
         return injectionPoints;
     }
 
+    public BeanInterceptorInfo getInterceptorInfo()
+    {
+        return interceptorInfo;
+    }
+
+    @Override
+    public T produce(CreationalContext<T> creationalContext)
+    {
+        final CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>) creationalContext;
+
+        final Map<Interceptor<?>,Object> interceptorInstances  = new HashMap<Interceptor<?>, Object>();
+        final Contextual<T> oldContextual = creationalContextImpl.getContextual();
+
+        if (interceptorInfo != null)
+        {
+            // apply interceptorInfo
+
+            // create EJB-style interceptors
+            for (final Interceptor interceptorBean : interceptorInfo.getEjbInterceptors())
+            {
+                creationalContextImpl.putContextual(interceptorBean);
+                interceptorInstances.put(interceptorBean, interceptorBean.create(creationalContext));
+            }
+
+            // create CDI-style interceptors
+            for (final Interceptor interceptorBean : interceptorInfo.getCdiInterceptors())
+            {
+                creationalContextImpl.putContextual(interceptorBean);
+                interceptorInstances.put(interceptorBean, interceptorBean.create(creationalContext));
+            }
+        }
+
+        T instance = produce(interceptorInstances, creationalContextImpl);
+
+        if (interceptorInfo != null)
+        {
+            // register the bean itself for self-interception
+            if (interceptorInfo.getSelfInterceptorBean() != null)
+            {
+                interceptorInstances.put(interceptorInfo.getSelfInterceptorBean(), instance);
+            }
+
+            T delegate = instance;
+            if (interceptorInfo.getDecorators() != null && !isDelegateInjection(creationalContextImpl))
+            {
+                List<Decorator<?>> decorators = interceptorInfo.getDecorators();
+                Map<Decorator<?>, Object> instances = new HashMap<Decorator<?>, Object>();
+                for (int i = decorators.size(); i > 0; i--)
+                {
+                    Decorator decorator = decorators.get(i - 1);
+                    creationalContextImpl.putContextual(decorator);
+                    creationalContextImpl.putDelegate(delegate);
+                    Object decoratorInstance = decorator.create((CreationalContext) creationalContext);
+                    instances.put(decorator, decoratorInstance);
+                    delegate = proxyFactory.createProxyInstance(proxyClass, instance, new DecoratorHandler(interceptorInfo, instances, i - 1, instance, passivationId));
+                }
+            }
+            InterceptorHandler interceptorHandler = new DefaultInterceptorHandler<T>(instance, delegate, methodInterceptors, interceptorInstances, passivationId);
+
+            T proxyInstance = proxyFactory.createProxyInstance(proxyClass, instance, interceptorHandler);
+            instance = proxyInstance;
+            creationalContextImpl.putContextual(oldContextual);
+        }
+
+        return instance;
+    }
+
     @Override
     public void dispose(T instance)
     {
     }
+
+    protected abstract T produce(Map<Interceptor<?>, ?> interceptorInstances, CreationalContextImpl<T> creationalContext);
+    
+    protected InterceptorDecoratorProxyFactory getProxyFactory()
+    {
+        return proxyFactory;
+    }
+
+    protected Map<Method, List<Interceptor<?>>> getMethodInterceptors()
+    {
+        return methodInterceptors;
+    }
+    
+    protected boolean needsProxy()
+    {
+        return methodInterceptors.size() != 0;
+    }
+
+    protected boolean isDelegateInjection(final CreationalContextImpl<?> cc)
+    {
+        final InjectionPoint ip = cc.getInjectionPoint();
+        if (ip == null)
+        {
+            return false;
+        }
+        return ip.getAnnotated().isAnnotationPresent(Delegate.class);
+    }
+
+    /**
+     * Helper method to unwrap the internal proxy instance.
+     * Returns the instance directly if this is not a proxied instance.
+     */
+    protected T unwrapProxyInstance(T probableProxyInstance)
+    {
+        if (proxyFactory != null && probableProxyInstance instanceof OwbInterceptorProxy)
+        {
+            return proxyFactory.unwrapInstance(probableProxyInstance);
+        }
+
+        return probableProxyInstance;
+    }
+
+    protected void defineLifecycleInterceptors(Bean<T> bean, AnnotatedType<T> annotatedType, WebBeansContext webBeansContext)
+    {
+        
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java Tue Jan 21 07:46:55 2014
@@ -18,11 +18,14 @@
  */
 package org.apache.webbeans.portable;
 
-import javax.enterprise.context.spi.CreationalContext;
+import java.util.Map;
+
 import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.InjectableBeanManager;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 
 public class BeanManagerProducer extends AbstractProducer<BeanManager>
 {
@@ -36,7 +39,7 @@ public class BeanManagerProducer extends
     }
 
     @Override
-    public BeanManager produce(CreationalContext<BeanManager> creationalContext)
+    protected BeanManager produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<BeanManager> creationalContext)
     {
         if (manager == null)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanMetadataProducer.java Tue Jan 21 07:46:55 2014
@@ -18,8 +18,10 @@
  */
 package org.apache.webbeans.portable;
 
+import java.util.Map;
+
 import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 
@@ -27,7 +29,7 @@ public class BeanMetadataProducer<T> ext
 {
 
     @Override
-    public Contextual<T> produce(CreationalContext<Contextual<T>> creationalContext)
+    protected Contextual<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Contextual<T>> creationalContext)
     {
         if (!(creationalContext instanceof CreationalContextImpl))
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java Tue Jan 21 07:46:55 2014
@@ -21,10 +21,11 @@ package org.apache.webbeans.portable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.Map;
 
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
@@ -45,7 +46,7 @@ public class EventProducer<T> extends Ab
      * {@inheritDoc}
      */
     @Override
-    public Event<T> produce(CreationalContext<Event<T>> creationalContext)
+    protected Event<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Event<T>> creationalContext)
     {
         Event<T> instance = null;
         InjectionPoint injectionPoint = null;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ExtensionProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ExtensionProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ExtensionProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ExtensionProducer.java Tue Jan 21 07:46:55 2014
@@ -18,9 +18,11 @@
  */
 package org.apache.webbeans.portable;
 
-import javax.enterprise.context.spi.CreationalContext;
+import java.util.Map;
+
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
@@ -39,7 +41,7 @@ public class ExtensionProducer<R> extend
     }
 
     @Override
-    public R produce(CreationalContext<R> creationalContext)
+    protected R produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<R> creationalContext)
     {
         ExtensionLoader loader = webBeansContext.getExtensionLoader();
         

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java Tue Jan 21 07:46:55 2014
@@ -18,8 +18,10 @@
  */
 package org.apache.webbeans.portable;
 
-import javax.enterprise.context.spi.CreationalContext;
+import java.util.Map;
+
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.util.ClassUtil;
@@ -31,7 +33,7 @@ public class InjectionPointProducer exte
      * {@inheritDoc}
      */
     @Override
-    public InjectionPoint produce(CreationalContext<InjectionPoint> creationalContext)
+    protected InjectionPoint produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<InjectionPoint> creationalContext)
     {
         if (!(creationalContext instanceof CreationalContextImpl))
         {

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=1559930&r1=1559929&r2=1559930&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 Tue Jan 21 07:46:55 2014
@@ -26,7 +26,6 @@ import org.apache.webbeans.exception.Web
 import org.apache.webbeans.inject.InjectableConstructor;
 import org.apache.webbeans.inject.InjectableField;
 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;
@@ -40,8 +39,6 @@ import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.CDI11s;
 import org.apache.webbeans.util.ExceptionUtil;
 
-import javax.decorator.Delegate;
-import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Disposes;
@@ -50,7 +47,7 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.InterceptionType;
@@ -64,8 +61,9 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.text.MessageFormat;
-import java.util.HashMap;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -108,37 +106,6 @@ public class InjectionTargetImpl<T> exte
 
     private List<Interceptor<?>> aroundConstructInterceptors;
 
-    /**
-     * static information about Interceptors and Decorators of that bean
-     */
-    private BeanInterceptorInfo interceptorInfo = null;
-
-    /**
-     * The passivationId of the bean this InjectionTarget serves.
-     * We need this to restore the interceptor proxy on de-serialisation.
-     * Only needed for Beans which are {@link javax.enterprise.inject.spi.PassivationCapable}.
-     */
-    private String beanPassivationId = null;
-
-    /**
-     * Defines the interceptor/decorator stack for the InjectionTargetBean.
-     * In case this is already defined, we get the ProxyClass for the Bean
-     * or <code>null</code> if this Bean doesn't need any proxy.
-     * This logic is handled inside the Bean and not in the BeanBuilder as
-     * this can also be created lazily
-     *
-     * the Proxy Class or <code>null</code> if this Bean is not intercepted nor decorated.
-     */
-    private Class<? extends T>  proxyClass;
-
-    /**
-     * List of all Interceptors per Method.
-     */
-    private Map<Method, List<Interceptor<?>>> methodInterceptors = null;
-    private InjectionTarget<T> delegate = null;
-    private final boolean noProxy; // Mark this injection target usable as a delegate ni a custom InjectionTarget
-
-
     public InjectionTargetImpl(AnnotatedType<T> annotatedType, Set<InjectionPoint> points, WebBeansContext webBeansContext,
                                List<AnnotatedMethod<?>> postConstructMethods, List<AnnotatedMethod<?>> preDestroyMethods)
     {
@@ -149,104 +116,40 @@ public class InjectionTargetImpl<T> exte
         this.webBeansContext = webBeansContext;
         this.postConstructMethods = postConstructMethods;
         this.preDestroyMethods = preDestroyMethods;
-        noProxy = false;
     }
-
-    public InjectionTargetImpl(final InjectionTargetImpl<T> delegate)
+    
+    @Override
+    protected void defineLifecycleInterceptors(Bean<T> bean, AnnotatedType<T> annotatedType, WebBeansContext webBeansContext)
     {
-        super(delegate.getInjectionPoints());
-        noProxy = true;
-        annotatedType = delegate.annotatedType;
-        webBeansContext = delegate.webBeansContext;
-        postConstructMethods = delegate.postConstructMethods;
-        preDestroyMethods = delegate.preDestroyMethods;
-    }
+        BeanInterceptorInfo interceptorInfo = getInterceptorInfo();
+        
+        postConstructInterceptors
+            = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(), interceptorInfo.getCdiInterceptors(), InterceptionType.POST_CONSTRUCT);
 
-    public BeanInterceptorInfo getInterceptorInfo()
-    {
-        return interceptorInfo;
-    }
+        preDestroyInterceptors
+            = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(), interceptorInfo.getCdiInterceptors(), InterceptionType.PRE_DESTROY);
 
-    public void setInterceptorInfo(BeanInterceptorInfo interceptorInfo, Class<? extends T> proxyClass, Map<Method, List<Interceptor<?>>> methodInterceptors,
-                                   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;
-        aroundConstructInterceptors = aroundConstruct;
-        this.beanPassivationId = beanPassivationId;
-    }
-
-    /**
-     * Helper method to unwrap the internal proxy instance.
-     * Returns the instance directly if this is not a proxied instance.
-     */
-    protected T unwrapProxyInstance(T probableProxyInstance)
-    {
-        if (probableProxyInstance instanceof OwbInterceptorProxy)
+        if (CDI11s.AROUND_CONSTRUCT != null)
         {
-            return webBeansContext.getInterceptorDecoratorProxyFactory().unwrapInstance(probableProxyInstance);
+            aroundConstructInterceptors = getLifecycleInterceptors(interceptorInfo.getEjbInterceptors(), interceptorInfo.getCdiInterceptors(), CDI11s.AROUND_CONSTRUCT);
+        }
+        else
+        {
+            aroundConstructInterceptors = new ArrayList<Interceptor<?>>();
         }
-
-        return probableProxyInstance;
     }
 
     @Override
-    public T produce(CreationalContext<T> creationalContext)
+    public T produce(Map<Interceptor<?>, ?> interceptorInstances, CreationalContextImpl<T> creationalContext)
     {
-        final CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>) creationalContext;
-        if (noProxy)
-        {
-            return newInstance(creationalContextImpl);
-        }
-
-        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 || hasAroundConstruct)
-        {
-            // apply interceptorInfo
-
-            // create EJB-style interceptors
-            for (final Interceptor interceptorBean : interceptorInfo.getEjbInterceptors())
-            {
-                creationalContextImpl.putContextual(interceptorBean);
-                interceptorInstances.put(interceptorBean, interceptorBean.create(creationalContext));
-            }
-
-            // create CDI-style interceptors
-            for (final Interceptor interceptorBean : interceptorInfo.getCdiInterceptors())
-            {
-                creationalContextImpl.putContextual(interceptorBean);
-                interceptorInstances.put(interceptorBean, interceptorBean.create(creationalContext));
-            }
-        }
-
-        T instance;
-        if (hasAroundConstruct)
+        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
-                    {
-                        if (delegate != null)
-                        {
-                            return delegate.produce(creationalContextImpl);
-                        }
-                        return injectableConstructor.doInjection();
-                    }
-                }.proceed();
-                instance = injectableConstructor.getInstance();
+                final InjectableConstructor<T> injectableConstructor = new InjectableConstructor<T>(cons, this, creationalContext);
+                return (T)new InterceptorInvocationContext<T>(null, CDI11s.AROUND_CONSTRUCT, aroundConstructInterceptors, interceptorInstances,
+                                                    cons, injectableConstructor.createParameters()).proceed();
             }
             catch (final Exception e) // CDI 1.0
             {
@@ -255,99 +158,32 @@ public class InjectionTargetImpl<T> exte
         }
         else
         {
-            if (delegate != null)
-            {
-                instance = delegate.produce(creationalContextImpl);
-            }
-            else
-            {
-                instance = newInstance(creationalContextImpl);
-            }
+            return newInstance(creationalContext);
         }
-
-        if (proxyClass != null)
-        {
-            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
-
-            // register the bean itself for self-interception
-            if (interceptorInfo.getSelfInterceptorBean() != null)
-            {
-                interceptorInstances.put(interceptorInfo.getSelfInterceptorBean(), instance);
-            }
-
-            T delegate = instance;
-            if (interceptorInfo.getDecorators() != null && !isDelegateInjection(creationalContext))
-            {
-                List<Decorator<?>> decorators = interceptorInfo.getDecorators();
-                Map<Decorator<?>, Object> instances = new HashMap<Decorator<?>, Object>();
-                for (int i = decorators.size(); i > 0; i--)
-                {
-                    Decorator decorator = decorators.get(i - 1);
-                    creationalContextImpl.putContextual(decorator);
-                    creationalContextImpl.putDelegate(delegate);
-                    Object decoratorInstance = decorator.create((CreationalContext) creationalContext);
-                    instances.put(decorator, decoratorInstance);
-                    delegate = pf.createProxyInstance(proxyClass, instance, new DecoratorHandler(interceptorInfo, instances, i - 1, instance, beanPassivationId));
-                }
-            }
-            InterceptorHandler interceptorHandler = new DefaultInterceptorHandler<T>(instance, delegate, methodInterceptors, interceptorInstances, beanPassivationId);
-
-            T proxyInstance = pf.createProxyInstance(proxyClass, instance, interceptorHandler);
-            instance = proxyInstance;
-            creationalContextImpl.putContextual(oldContextual);
-        }
-
-        return instance;
     }
 
-    protected boolean isDelegateInjection(final CreationalContext<?> cc)
+    @Override
+    protected boolean needsProxy()
     {
-        if (CreationalContextImpl.class.isInstance(cc))
-        {
-            final InjectionPoint ip = CreationalContextImpl.class.cast(cc).getInjectionPoint();
-            if (ip == null)
-            {
-                return false;
-            }
-
-            final Member member = ip.getMember();
-            if (member != null
-                    && Field.class.isInstance(member) && Field.class.cast(member).getAnnotation(Delegate.class) != null)
-            {
-                return true;
-            }
-        }
-        return false;
+        return super.needsProxy() || postConstructInterceptors.size() != 0 || preDestroyInterceptors.size() != 0;
     }
     
-    protected T newInstance(CreationalContextImpl<T> creationalContext)
+    protected boolean hasAroundConstruct()
     {
-        return new InjectableConstructor<T>(getConstructor().getJavaMember(), this, creationalContext).doInjection();
+        return aroundConstructInterceptors != null && !aroundConstructInterceptors.isEmpty();
     }
-
-    @Override
-    public void dispose(T instance)
+    
+    protected T newInstance(CreationalContextImpl<T> creationalContext)
     {
-        if (delegate != null)
-        {
-            delegate.dispose(instance);
-        }
+        return new InjectableConstructor<T>(getConstructor().getJavaMember(), this, creationalContext).doInjection();
     }
 
     @Override
     public void inject(T instance, CreationalContext<T> context)
     {
-        if (delegate == null)
-        {
-            inject(instance.getClass(), unwrapProxyInstance(instance), (CreationalContextImpl<T>) context);
-        }
-        else
-        {
-            delegate.inject(instance, context);
-        }
+        inject(instance.getClass(), unwrapProxyInstance(instance), (CreationalContextImpl<T>) context);
     }
 
-
     private void inject(Class<?> type, final T instance, CreationalContextImpl<T> context)
     {
         if (type == null || type.equals(Object.class))
@@ -440,19 +276,12 @@ public class InjectionTargetImpl<T> exte
     @Override
     public void postConstruct(final T instance)
     {
-        if (delegate != null)
-        {
-            delegate.postConstruct(instance);
-            return; // TODO: sure?
-        }
-
         Map<Interceptor<?>, ?> interceptorInstances = null;
         T internalInstance = instance;
 
-        if (interceptorInfo != null && instance instanceof OwbInterceptorProxy)
+        if (getInterceptorInfo() != null && instance instanceof OwbInterceptorProxy)
         {
-            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
-            InterceptorHandler ih = pf.getInterceptorHandler((OwbInterceptorProxy) instance);
+            InterceptorHandler ih = getProxyFactory().getInterceptorHandler((OwbInterceptorProxy) instance);
             if (ih instanceof DefaultInterceptorHandler)
             {
                 DefaultInterceptorHandler dih = (DefaultInterceptorHandler) ih;
@@ -480,16 +309,10 @@ public class InjectionTargetImpl<T> exte
     @Override
     public void preDestroy(T instance)
     {
-        if (delegate != null)
-        {
-            delegate.preDestroy(instance);
-            return; // TODO: sure?
-        }
-
         Map<Interceptor<?>, ?> interceptorInstances = null;
         T internalInstance = instance;
 
-        if (interceptorInfo != null && instance instanceof OwbInterceptorProxy)
+        if (getInterceptorInfo() != null && instance instanceof OwbInterceptorProxy)
         {
             InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
             InterceptorHandler ih = pf.getInterceptorHandler((OwbInterceptorProxy) instance);
@@ -599,13 +422,25 @@ public class InjectionTargetImpl<T> exte
         return false;
     }
 
-    public void setDelegate(final InjectionTarget<T> delegate)
+    private List<Interceptor<?>> getLifecycleInterceptors(LinkedHashSet<Interceptor<?>> ejbInterceptors, List<Interceptor<?>> cdiInterceptors, InterceptionType interceptionType)
     {
-        this.delegate = delegate;
-    }
+        List<Interceptor<?>> lifecycleInterceptors = new ArrayList<Interceptor<?>>();
 
-    public InjectionTarget<T> simpleInstance()
-    {
-        return new InjectionTargetImpl<T>(this);
+        for (Interceptor<?> ejbInterceptor : ejbInterceptors)
+        {
+            if (ejbInterceptor.intercepts(interceptionType))
+            {
+                lifecycleInterceptors.add(ejbInterceptor);
+            }
+        }
+        for (Interceptor<?> cdiInterceptor : cdiInterceptors)
+        {
+            if (cdiInterceptor.intercepts(interceptionType))
+            {
+                lifecycleInterceptors.add(cdiInterceptor);
+            }
+        }
+
+        return lifecycleInterceptors;
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java Tue Jan 21 07:46:55 2014
@@ -21,11 +21,12 @@ package org.apache.webbeans.portable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.Map;
 import java.util.Set;
 
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.component.InstanceBean;
 import org.apache.webbeans.config.WebBeansContext;
@@ -46,12 +47,12 @@ public class InstanceProducer<T> extends
     }
 
     @Override
-    public Instance<T> produce(CreationalContext<Instance<T>> creationalContext)
+    protected Instance<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Instance<T>> creationalContext)
     {
+        CreationalContextImpl<Instance<T>> creationalContextImpl = null;
         try
         {
             InjectionPoint injectionPoint = null;
-            CreationalContextImpl<Instance<T>> creationalContextImpl = null;
             if (creationalContext instanceof CreationalContextImpl)
             {
                 creationalContextImpl = (CreationalContextImpl<Instance<T>>)creationalContext;
@@ -77,15 +78,13 @@ public class InstanceProducer<T> extends
                 type = returnType;
             }
 
-            Instance<T> instance = new InstanceImpl<T>(type, injectionPoint, webBeansContext, creationalContextImpl, qualifiers.toArray(new Annotation[qualifiers.size()]));
-            
-            return instance;
+            return new InstanceImpl<T>(type, injectionPoint, webBeansContext, creationalContextImpl, qualifiers.toArray(new Annotation[qualifiers.size()]));
         }
         finally
         {
-            if (creationalContext instanceof CreationalContextImpl)
+            if (creationalContextImpl != null)
             {
-                ((CreationalContextImpl<Instance<T>>)creationalContext).removeInjectionPoint();
+                creationalContextImpl.removeInjectionPoint();
             }
         }
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/MetadataProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/MetadataProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/MetadataProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/MetadataProducer.java Tue Jan 21 07:46:55 2014
@@ -18,8 +18,10 @@
  */
 package org.apache.webbeans.portable;
 
+import java.util.Map;
+
 import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 
@@ -27,7 +29,7 @@ public class MetadataProducer<T> extends
 {
 
     @Override
-    public Contextual<T> produce(CreationalContext<Contextual<T>> creationalContext)
+    protected Contextual<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Contextual<T>> creationalContext)
     {
         if (!(creationalContext instanceof CreationalContextImpl))
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java Tue Jan 21 07:46:55 2014
@@ -21,15 +21,18 @@ package org.apache.webbeans.portable;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.util.Collections;
+import java.util.Map;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedField;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -53,7 +56,7 @@ public class ProducerFieldProducer<T, P>
     }
 
     @Override
-    public T produce(CreationalContext<T> creationalContext)
+    protected T produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<T> creationalContext)
     {
         T instance = null;
         P parentInstance = null;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java Tue Jan 21 07:46:55 2014
@@ -20,12 +20,14 @@ package org.apache.webbeans.portable;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Map;
 import java.util.Set;
 
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
@@ -89,7 +91,7 @@ public class ProducerMethodProducer<T, P
     }
 
     @Override
-    public T produce(CreationalContext<T> creationalContext)
+    protected T produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<T> creationalContext)
     {
         P parentInstance = null;
         CreationalContext<P> parentCreationalContext = null;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProducer.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProducer.java Tue Jan 21 07:46:55 2014
@@ -18,10 +18,13 @@
  */
 package org.apache.webbeans.portable;
 
-import javax.enterprise.context.spi.CreationalContext;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.Interceptor;
 import javax.inject.Provider;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.proxy.NormalScopeProxyFactory;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -43,7 +46,7 @@ public class ProviderBasedProducer<T> ex
     }
 
     @Override
-    public T produce(CreationalContext<T> creationalContext)
+    protected T produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<T> creationalContext)
     {
         if (proxyInstance == null)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessInjectionTargetImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessInjectionTargetImpl.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessInjectionTargetImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessInjectionTargetImpl.java Tue Jan 21 07:46:55 2014
@@ -18,13 +18,12 @@
  */
 package org.apache.webbeans.portable.events;
 
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.portable.InjectionTargetImpl;
-
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.ProcessInjectionTarget;
 
+import org.apache.webbeans.config.WebBeansContext;
+
 /**
  * Implementation of the {@link ProcessInjectionTarget}.
  * 
@@ -38,8 +37,8 @@ public class ProcessInjectionTargetImpl<
     private final AnnotatedType<X> annotatedType;
     
     /**Injection target that is used by container to inject dependencies*/
-    private InjectionTargetImpl<X> injectionTarget = null;
-
+    private InjectionTarget<X> injectionTarget = null;
+    
     /**Injection target is set or not*/
     private boolean set = false;
     
@@ -48,22 +47,20 @@ public class ProcessInjectionTargetImpl<
      * 
      * @param injectionTarget injection target
      */
-    public ProcessInjectionTargetImpl(InjectionTargetImpl<X> injectionTarget, AnnotatedType<X> annotatedType)
+    public ProcessInjectionTargetImpl(InjectionTarget<X> injectionTarget, AnnotatedType<X> annotatedType)
     {
         this.injectionTarget = injectionTarget;
         this.annotatedType = annotatedType;
     }
-
+    
     /**
      * {@inheritDoc}
      */
-    @Override
     public void addDefinitionError(Throwable t)
     {
         WebBeansContext.getInstance().getBeanManagerImpl().getErrorStack().pushError(t);
     }
 
-    @Override
     public AnnotatedType<X> getAnnotatedType()
     {
         return annotatedType;
@@ -72,24 +69,17 @@ public class ProcessInjectionTargetImpl<
     /**
      * {@inheritDoc}
      */
-    @Override
     public InjectionTarget<X> getInjectionTarget()
     {
-        return injectionTarget.simpleInstance();
-    }
-
-    public InjectionTarget<X> getCompleteInjectionTarget()
-    {
         return injectionTarget;
     }
 
     /**
      * {@inheritDoc}
      */
-    @Override
     public void setInjectionTarget(InjectionTarget<X> injectionTarget)
     {
-        this.injectionTarget.setDelegate(injectionTarget); // wrap it to keep interceptors info
+        this.injectionTarget = injectionTarget;
         set = true;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Tue Jan 21 07:46:55 2014
@@ -58,6 +58,7 @@ import org.apache.webbeans.exception.inj
 import org.apache.webbeans.exception.inject.InconsistentSpecializationException;
 import org.apache.webbeans.inject.AlternativesManager;
 import org.apache.webbeans.plugins.PluginLoader;
+import org.apache.webbeans.portable.AbstractProducer;
 import org.apache.webbeans.portable.InjectionTargetImpl;
 import org.apache.webbeans.portable.ProducerMethodProducer;
 import org.apache.webbeans.portable.events.discovery.ErrorStack;
@@ -1551,9 +1552,10 @@ public final class WebBeansUtil
         new ProducerFieldBeansBuilder(managedBean.getWebBeansContext(), managedBean.getAnnotatedType()).defineProducerFields(managedBean);
         new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext, managedBean.getAnnotatedType()).defineObserverMethods(managedBean);
 
-        if (managedBean instanceof InjectionTargetBean)
+        if (managedBean.getProducer() instanceof AbstractProducer)
         {
-            ((InjectionTargetBean) managedBean).defineBeanInterceptorStack();
+            AbstractProducer<T> producer = (AbstractProducer<T>)managedBean.getProducer();
+            producer.defineInterceptorStack(managedBean, managedBean.getAnnotatedType(), webBeansContext);
         }
 
         return managedBean;
@@ -1657,9 +1659,10 @@ public final class WebBeansUtil
         new ProducerFieldBeansBuilder(managedBean.getWebBeansContext(), managedBean.getAnnotatedType()).defineProducerFields(managedBean);
         new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext, managedBean.getAnnotatedType()).defineObserverMethods(managedBean);
 
-        if (managedBean instanceof InjectionTargetBean)
+        if (managedBean.getProducer() instanceof AbstractProducer)
         {
-            ((InjectionTargetBean) managedBean).defineBeanInterceptorStack();
+            AbstractProducer<T> producer = (AbstractProducer<T>)managedBean.getProducer();
+            producer.defineInterceptorStack(managedBean, managedBean.getAnnotatedType(), webBeansContext);
         }
         return managedBean;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=1559930&r1=1559929&r2=1559930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java Tue Jan 21 07:46:55 2014
@@ -57,6 +57,7 @@ import org.apache.webbeans.deployment.St
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.portable.AbstractProducer;
 import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType;
 import org.apache.webbeans.test.component.decorator.broken.DelegateAttributeIsnotInterface;
 import org.apache.webbeans.test.component.decorator.broken.DelegateAttributeMustImplementAllDecoratedTypes;
@@ -281,9 +282,10 @@ public abstract class TestContext implem
         bean = define(clazz, WebBeansType.MANAGED, webBeansContext.getAnnotatedElementFactory().newAnnotatedType(clazz));
         if (bean != null)
         {
-            if (bean instanceof InjectionTargetBean)
+            if (bean.getProducer() instanceof AbstractProducer)
             {
-                ((InjectionTargetBean) bean).defineBeanInterceptorStack();
+                AbstractProducer<T> producer = (AbstractProducer<T>)bean.getProducer();
+                producer.defineInterceptorStack(bean, bean.getAnnotatedType(), webBeansContext);
             }
 
             getComponents().add((AbstractOwbBean<?>) bean);



Mime
View raw message