openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1520857 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/container/ main/java/org/apache/webbeans/portable/ main/java/org/apache/webbea...
Date Sun, 08 Sep 2013 12:00:40 GMT
Author: rmannibucau
Date: Sun Sep  8 12:00:40 2013
New Revision: 1520857

URL: http://svn.apache.org/r1520857
Log:
OWB-897 defining interceptors even for custom InjectionTargets - note: if someone has some
more time it would be great to split InjectionTargetImpl in 3 implementations (the previous
one, a DelegatingInjectionTarget and a SimpleInjectionTarget which doesn't hold any proxy
info)

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/extension/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/extension/InjectionTargetBeanOWB897Test.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/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/portable/InjectionTargetImpl.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/portable/events/generics/GProcessInjectionTarget.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.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=1520857&r1=1520856&r2=1520857&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
Sun Sep  8 12:00:40 2013
@@ -18,13 +18,11 @@
  */
 package org.apache.webbeans.component;
 
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.apache.webbeans.component.spi.BeanAttributes;
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
@@ -32,12 +30,13 @@ import javax.enterprise.inject.CreationE
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.Producer;
-
-import org.apache.webbeans.component.spi.BeanAttributes;
-import org.apache.webbeans.config.OWBLogConst;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Abstract implementation of the {@link OwbBean} contract. 
@@ -115,11 +114,11 @@ public abstract class AbstractOwbBean<T>
                 creationalContext = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(creationalContext,
this);
             }
 
-            Producer<T> producer = getProducer();
-            T instance = producer.produce(creationalContext);
+            final Producer<T> producer = getProducer();
+            final T instance = producer.produce(creationalContext);
             if (producer instanceof InjectionTarget)
             {
-                InjectionTarget<T> injectionTarget = (InjectionTarget<T>)producer;
+                final InjectionTarget<T> injectionTarget = (InjectionTarget<T>)producer;
                 injectionTarget.inject(instance, creationalContext);
                 injectionTarget.postConstruct(instance);
             }

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=1520857&r1=1520856&r2=1520857&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
Sun Sep  8 12:00:40 2013
@@ -908,13 +908,6 @@ public class BeansDeployer
             webBeansContext.getWebBeansUtil().inspectErrorStack(
                 "There are errors that are added by ProcessInjectionTarget event observers.
Look at logs for further details");
 
-            //Sets custom InjectionTarget instance
-            if(processInjectionTargetEvent.isSet())
-            {
-                //Adding injection target
-                manager.putProducerForJavaEeComponent(beanClass, processInjectionTargetEvent.getInjectionTarget());
-            }
-            
             //Checks that not contains @Inject InjectionPoint
             webBeansContext.getAnnotationManager().checkInjectionPointForInjectInjectionPoint(beanClass);
         }

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=1520857&r1=1520856&r2=1520857&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
Sun Sep  8 12:00:40 2013
@@ -18,9 +18,10 @@
  */
 package org.apache.webbeans.container;
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import org.apache.webbeans.component.spi.InjectionTargetFactory;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.portable.InjectionTargetImpl;
+import org.apache.webbeans.util.Asserts;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
@@ -29,11 +30,9 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
-
-import org.apache.webbeans.component.spi.InjectionTargetFactory;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.portable.InjectionTargetImpl;
-import org.apache.webbeans.util.Asserts;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 public class InjectionTargetFactoryImpl<T> implements InjectionTargetFactory<T>
 {
@@ -57,9 +56,9 @@ public class InjectionTargetFactoryImpl<
     @Override
     public InjectionTarget<T> createInjectionTarget(Bean<T> bean)
     {
-        InjectionTarget<T> injectionTarget
+        final InjectionTargetImpl<T> injectionTarget
             = new InjectionTargetImpl<T>(annotatedType, createInjectionPoints(bean),
webBeansContext, getPostConstructMethods(), getPreDestroyMethods());
-        return webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEvent(injectionTarget,
annotatedType).getInjectionTarget();
+        return webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEvent(injectionTarget,
annotatedType).getCompleteInjectionTarget();
     }
 
     protected Set<InjectionPoint> createInjectionPoints(Bean<T> bean)

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=1520857&r1=1520856&r2=1520857&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
Sun Sep  8 12:00:40 2013
@@ -135,6 +135,8 @@ public class InjectionTargetImpl<T> exte
      * 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,
@@ -147,6 +149,17 @@ public class InjectionTargetImpl<T> exte
         this.webBeansContext = webBeansContext;
         this.postConstructMethods = postConstructMethods;
         this.preDestroyMethods = preDestroyMethods;
+        this.noProxy = false;
+    }
+
+    public InjectionTargetImpl(final InjectionTargetImpl<T> delegate)
+    {
+        super(delegate.getInjectionPoints());
+        this.noProxy = true;
+        this.annotatedType = delegate.annotatedType;
+        this.webBeansContext = delegate.webBeansContext;
+        this.postConstructMethods = delegate.postConstructMethods;
+        this.preDestroyMethods = delegate.preDestroyMethods;
     }
 
     public BeanInterceptorInfo getInterceptorInfo()
@@ -185,6 +198,11 @@ public class InjectionTargetImpl<T> exte
     public T produce(CreationalContext<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();
@@ -221,6 +239,10 @@ public class InjectionTargetImpl<T> exte
                     @Override
                     protected Object realProceed() throws Exception
                     {
+                        if (delegate != null)
+                        {
+                            return delegate.produce(creationalContextImpl);
+                        }
                         return injectableConstructor.doInjection();
                     }
                 }.proceed();
@@ -233,7 +255,14 @@ public class InjectionTargetImpl<T> exte
         }
         else
         {
-            instance = newInstance(creationalContextImpl);
+            if (delegate != null)
+            {
+                instance = delegate.produce(creationalContextImpl);
+            }
+            else
+            {
+                instance = newInstance(creationalContextImpl);
+            }
         }
 
         if (proxyClass != null)
@@ -299,13 +328,23 @@ public class InjectionTargetImpl<T> exte
     @Override
     public void dispose(T instance)
     {
+        if (delegate != null)
+        {
+            delegate.dispose(instance);
+        }
     }
 
     @Override
     public void inject(T instance, CreationalContext<T> context)
     {
-
-        inject(instance.getClass(), unwrapProxyInstance(instance), (CreationalContextImpl<T>)
context);
+        if (delegate == null)
+        {
+            inject(instance.getClass(), unwrapProxyInstance(instance), (CreationalContextImpl<T>)
context);
+        }
+        else
+        {
+            delegate.inject(instance, context);
+        }
     }
 
 
@@ -401,6 +440,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;
 
@@ -435,6 +480,12 @@ 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;
 
@@ -547,4 +598,14 @@ public class InjectionTargetImpl<T> exte
         }
         return false;
     }
+
+    public void setDelegate(final InjectionTarget<T> delegate)
+    {
+        this.delegate = delegate;
+    }
+
+    public InjectionTarget<T> simpleInstance()
+    {
+        return new InjectionTargetImpl<T>(this);
+    }
 }

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=1520857&r1=1520856&r2=1520857&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
Sun Sep  8 12:00:40 2013
@@ -18,12 +18,13 @@
  */
 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}.
  * 
@@ -37,8 +38,8 @@ public class ProcessInjectionTargetImpl<
     private final AnnotatedType<X> annotatedType;
     
     /**Injection target that is used by container to inject dependencies*/
-    private InjectionTarget<X> injectionTarget = null;
-    
+    private InjectionTargetImpl<X> injectionTarget = null;
+
     /**Injection target is set or not*/
     private boolean set = false;
     
@@ -47,12 +48,12 @@ public class ProcessInjectionTargetImpl<
      * 
      * @param injectionTarget injection target
      */
-    public ProcessInjectionTargetImpl(InjectionTarget<X> injectionTarget, AnnotatedType<X>
annotatedType)
+    public ProcessInjectionTargetImpl(InjectionTargetImpl<X> injectionTarget, AnnotatedType<X>
annotatedType)
     {
         this.injectionTarget = injectionTarget;
         this.annotatedType = annotatedType;
     }
-    
+
     /**
      * {@inheritDoc}
      */
@@ -74,6 +75,11 @@ public class ProcessInjectionTargetImpl<
     @Override
     public InjectionTarget<X> getInjectionTarget()
     {
+        return injectionTarget.simpleInstance();
+    }
+
+    public InjectionTarget<X> getCompleteInjectionTarget()
+    {
         return injectionTarget;
     }
 
@@ -83,7 +89,7 @@ public class ProcessInjectionTargetImpl<
     @Override
     public void setInjectionTarget(InjectionTarget<X> injectionTarget)
     {
-        this.injectionTarget = injectionTarget;
+        this.injectionTarget.setDelegate(injectionTarget); // wrap it to keep interceptors
info
         set = true;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionTarget.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionTarget.java?rev=1520857&r1=1520856&r2=1520857&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionTarget.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessInjectionTarget.java
Sun Sep  8 12:00:40 2013
@@ -18,15 +18,15 @@
  */
 package org.apache.webbeans.portable.events.generics;
 
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.InjectionTarget;
-
+import org.apache.webbeans.portable.InjectionTargetImpl;
 import org.apache.webbeans.portable.events.ProcessInjectionTargetImpl;
 
+import javax.enterprise.inject.spi.AnnotatedType;
+
 @SuppressWarnings("unchecked")
 public class GProcessInjectionTarget extends ProcessInjectionTargetImpl implements GenericBeanEvent
 {
-    public GProcessInjectionTarget(InjectionTarget<?> injectionTarget,AnnotatedType<?>
annotatedType)
+    public GProcessInjectionTarget(InjectionTargetImpl<?> injectionTarget,AnnotatedType<?>
annotatedType)
     {
         super(injectionTarget, annotatedType);
     }

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=1520857&r1=1520856&r2=1520857&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
Sun Sep  8 12:00:40 2013
@@ -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.InjectionTargetImpl;
 import org.apache.webbeans.portable.ProducerMethodProducer;
 import org.apache.webbeans.portable.events.discovery.ErrorStack;
 import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType;
@@ -91,7 +92,6 @@ import javax.enterprise.inject.spi.Befor
 import javax.enterprise.inject.spi.BeforeShutdown;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.PassivationCapable;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
@@ -1213,9 +1213,9 @@ public final class WebBeansUtil
      * @param <T> bean type
      * @return event
      */
-    public <T> ProcessInjectionTarget<T> fireProcessInjectionTargetEvent(InjectionTarget<T>
injectionTarget, AnnotatedType<T> annotatedType)
+    public <T> GProcessInjectionTarget fireProcessInjectionTargetEvent(InjectionTargetImpl<T>
injectionTarget, AnnotatedType<T> annotatedType)
     {
-        GProcessInjectionTarget processInjectionTargetEvent = new GProcessInjectionTarget(injectionTarget,
annotatedType);
+        final GProcessInjectionTarget processInjectionTargetEvent = new GProcessInjectionTarget(injectionTarget,
annotatedType);
         return fireProcessInjectionTargetEvent(processInjectionTargetEvent);
     }
 
@@ -1223,7 +1223,6 @@ public final class WebBeansUtil
     {
         //Fires ProcessInjectionTarget
         webBeansContext.getBeanManagerImpl().fireEvent(processInjectionTargetEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
-
         return processInjectionTargetEvent;
     }
 
@@ -1234,9 +1233,9 @@ public final class WebBeansUtil
      */
     public <T> GProcessInjectionTarget fireProcessInjectionTargetEventForJavaEeComponents(Class<T>
componentClass)
     {
-        AnnotatedType<T> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(componentClass);
-        InjectionTarget<T> injectionTarget = webBeansContext.getBeanManagerImpl().createInjectionTarget(annotatedType);
-        GProcessInjectionTarget processInjectionTargetEvent = new GProcessInjectionTarget(injectionTarget,annotatedType);
+        final AnnotatedType<T> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(componentClass);
+        final InjectionTargetImpl<T> injectionTarget = InjectionTargetImpl.class.cast(webBeansContext.getBeanManagerImpl().createInjectionTarget(annotatedType));
+        final GProcessInjectionTarget processInjectionTargetEvent = new GProcessInjectionTarget(injectionTarget,annotatedType);
 
         //Fires ProcessInjectionTarget
         return fireProcessInjectionTargetEvent(processInjectionTargetEvent);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java?rev=1520857&r1=1520856&r2=1520857&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
Sun Sep  8 12:00:40 2013
@@ -18,19 +18,6 @@
  */
 package org.apache.webbeans.newtests;
 
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionTarget;
-
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
@@ -39,10 +26,19 @@ import org.apache.webbeans.lifecycle.tes
 import org.apache.webbeans.lifecycle.test.OpenWebBeansTestMetaDataDiscoveryService;
 import org.apache.webbeans.spi.ContainerLifecycle;
 import org.apache.webbeans.util.WebBeansUtil;
-
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.After;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
 
 
 public abstract class AbstractUnitTest
@@ -90,8 +86,11 @@ public abstract class AbstractUnitTest
         startContainer(beanClasses, beanXmls, false);
     }
 
-    protected void startContainer(Collection<Class<?>> beanClasses, Collection<String>
beanXmls, boolean inject)
+    protected void startContainer(Collection<Class<?>> rawBeanClasses, Collection<String>
beanXmls, boolean inject)
     {
+        final Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
// ensure it is updatable
+        beanClasses.addAll(rawBeanClasses);
+
         WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
         //Creates a new container
         testLifecycle = new OpenWebBeansTestLifeCycle();

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/extension/InjectionTargetBeanOWB897Test.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/extension/InjectionTargetBeanOWB897Test.java?rev=1520857&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/extension/InjectionTargetBeanOWB897Test.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/extension/InjectionTargetBeanOWB897Test.java
Sun Sep  8 12:00:40 2013
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.interceptors.extension;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InterceptorBinding;
+import javax.interceptor.InvocationContext;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class InjectionTargetBeanOWB897Test extends AbstractUnitTest
+{
+    @Inject
+    private TheBean bean;
+
+    @Test
+    public void doIt()
+    {
+        addExtension(new AnExtension());
+        addInterceptor(InterceptorImpl.class);
+        startContainer(Arrays.<Class<?>>asList(TheBean.class), Collections.<String>emptyList(),
true);
+        assertNotNull(bean);
+        assertEquals("ok", bean.intercepted());
+        assertEquals("set", bean.getMarker());
+        assertTrue(AnExtension.injectCalled);
+        assertTrue(AnExtension.postConstructCalled);
+        shutDownContainer();
+    }
+
+    public static class AnExtension implements Extension {
+        private static boolean injectCalled = false;
+        private static boolean postConstructCalled = false;
+
+        void pat(final @Observes ProcessAnnotatedType<TheBean> pat) {
+            final AnnotatedType<TheBean> at = pat.getAnnotatedType();
+            pat.setAnnotatedType(new AnnotatedType<TheBean>() {
+                @Override
+                public Class<TheBean> getJavaClass()
+                {
+                    return at.getJavaClass();
+                }
+
+                @Override
+                public Set<AnnotatedConstructor<TheBean>> getConstructors()
+                {
+                    return at.getConstructors();
+                }
+
+                @Override
+                public Set<AnnotatedMethod<? super TheBean>> getMethods()
+                {
+                    return at.getMethods();
+                }
+
+                @Override
+                public Set<AnnotatedField<? super TheBean>> getFields()
+                {
+                    return at.getFields();
+                }
+
+                @Override
+                public Type getBaseType()
+                {
+                    return at.getBaseType();
+                }
+
+                @Override
+                public Set<Type> getTypeClosure()
+                {
+                    return at.getTypeClosure();
+                }
+
+                @Override
+                public <T extends Annotation> T getAnnotation(final Class<T>
annotationType)
+                {
+                    return at.getAnnotation(annotationType);
+                }
+
+                @Override
+                public Set<Annotation> getAnnotations()
+                {
+                    final Set<Annotation> annotations = new HashSet<Annotation>();
+                    annotations.addAll(at.getAnnotations());
+                    annotations.add(new AnnotationLiteral<B>()
+                    {
+                    });
+                    return annotations;
+                }
+
+                @Override
+                public boolean isAnnotationPresent(final Class<? extends Annotation>
annotationType)
+                {
+                    return B.class.equals(annotationType) || at.isAnnotationPresent(annotationType);
+                }
+            });
+        }
+
+        void pij(final @Observes ProcessInjectionTarget<TheBean> pij) {
+            pij.setInjectionTarget(new InjectionTarget<TheBean>() {
+                @Override
+                public void inject(final TheBean instance, final CreationalContext<TheBean>
ctx)
+                {
+                    injectCalled = instance != null;
+                    pij.getInjectionTarget().inject(instance, ctx); // to check we don't
have an infinite loop
+                }
+
+                @Override
+                public void postConstruct(final TheBean instance)
+                {
+                    postConstructCalled = instance != null;
+                    pij.getInjectionTarget().postConstruct(instance); // to check we don't
have an infinite loop
+                }
+
+                @Override
+                public void preDestroy(final TheBean instance)
+                {
+                    assertNotNull(instance);
+                }
+
+                @Override
+                public TheBean produce(final CreationalContext<TheBean> creationalContext)
{
+                    final TheBean theBean = pij.getInjectionTarget().produce(creationalContext);
// to check we don't have an infinite loop;
+                    theBean.setMarker("set");
+                    return theBean;
+                }
+
+                @Override
+                public void dispose(final TheBean instance)
+                {
+                    assertNotNull(instance);
+                }
+
+                @Override
+                public Set<InjectionPoint> getInjectionPoints() {
+                    return Collections.emptySet();
+                }
+            });
+        }
+    }
+
+    public static class TheBean
+    {
+        private String marker = "not set";
+
+        public String intercepted()
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        public void setMarker(final String marker) {
+            this.marker = marker;
+        }
+
+        public String getMarker()
+        {
+            return marker;
+        }
+    }
+
+    @InterceptorBinding
+    @Target( { ElementType.TYPE, ElementType.METHOD })
+    @Retention(RetentionPolicy.RUNTIME)
+    public static @interface B
+    {
+    }
+
+    @Interceptor @B
+    public static class InterceptorImpl
+    {
+        @AroundInvoke
+        public Object around (final InvocationContext ic) throws Exception
+        {
+            if (ic.getMethod().getName().equals("intercepted")) {
+                return "ok";
+            }
+            return ic.proceed();
+        }
+    }
+}



Mime
View raw message