openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1434461 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/intercept/ main/java/org/apache/webbeans/portable/ main/java/org/apache/webbeans/proxy/ test/java/org/apache/webbeans/test/component/ test/java/org/apache/we...
Date Wed, 16 Jan 2013 22:43:22 GMT
Author: struberg
Date: Wed Jan 16 22:43:22 2013
New Revision: 1434461

URL: http://svn.apache.org/viewvc?rev=1434461&view=rev
Log:
OWB-344 unwrap proxy instance for injection

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/PostConstructDoubleInterceptorComponent.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructComponentTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructDoubleInterceptorComponentTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1434461&r1=1434460&r2=1434461&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
Wed Jan 16 22:43:22 2013
@@ -155,6 +155,7 @@ public class InterceptorResolutionServic
                 InterceptionType.POST_CONSTRUCT,
                 PostConstruct.class,
                 allUsedCdiInterceptors,
+                allUsedEjbInterceptors,
                 classLevelEjbInterceptors,
                 classInterceptorBindings,
                 true);
@@ -165,6 +166,7 @@ public class InterceptorResolutionServic
                 InterceptionType.PRE_DESTROY,
                 PreDestroy.class,
                 allUsedCdiInterceptors,
+                allUsedEjbInterceptors,
                 classLevelEjbInterceptors,
                 classInterceptorBindings,
                 true);
@@ -211,7 +213,8 @@ public class InterceptorResolutionServic
                                      AnnotatedType<?> annotatedType,
                                      InterceptionType interceptionType,
                                      Class<? extends Annotation> annotation,
-                                     Set<Interceptor<?>> allUsedInterceptors,
+                                     Set<Interceptor<?>> allUsedCdiInterceptors,
+                                     Set<Interceptor<?>> allUsedEjbInterceptors,
                                      List<Interceptor<?>> classLevelEjbInterceptors,
                                      Set<Annotation> classInterceptorBindings,
                                      boolean parentFirst)
@@ -228,9 +231,9 @@ public class InterceptorResolutionServic
             if (lifecycleMethod.getParameters().size() == 0)
             {
                 foundMethods.add(lifecycleMethod);
-                calculateEjbMethodInterceptors(methodInterceptorInfo, allUsedInterceptors,
classLevelEjbInterceptors, lifecycleMethod);
+                calculateEjbMethodInterceptors(methodInterceptorInfo, allUsedEjbInterceptors,
classLevelEjbInterceptors, lifecycleMethod);
 
-                calculateCdiMethodInterceptors(methodInterceptorInfo, allUsedInterceptors,
lifecycleMethod, classInterceptorBindings);
+                calculateCdiMethodInterceptors(methodInterceptorInfo, allUsedCdiInterceptors,
lifecycleMethod, classInterceptorBindings);
             }
         }
 

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=1434461&r1=1434460&r2=1434461&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
Wed Jan 16 22:43:22 2013
@@ -146,6 +146,20 @@ public class InjectionTargetImpl<T> exte
         this.preDestroyInterceptors = preDestroyInterceptors;
     }
 
+    /**
+     * 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)
+        {
+            return webBeansContext.getInterceptorDecoratorProxyFactory().getInternalInstance(probableProxyInstance);
+        }
+
+        return probableProxyInstance;
+    }
+
     @Override
     public T produce(CreationalContext<T> creationalContext)
     {
@@ -193,10 +207,12 @@ public class InjectionTargetImpl<T> exte
     @Override
     public void inject(T instance, CreationalContext<T> context)
     {
-        inject(instance.getClass(), instance, (CreationalContextImpl<T>) context);
+
+        inject(instance.getClass(), unwrapProxyInstance(instance), (CreationalContextImpl<T>)
context);
     }
 
-    private void inject(Class<?> type, T instance, CreationalContextImpl<T> context)
+
+    private void inject(Class<?> type, final T instance, CreationalContextImpl<T>
context)
     {
         if (type == null || type.equals(Object.class))
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java?rev=1434461&r1=1434460&r2=1434461&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
Wed Jan 16 22:43:22 2013
@@ -94,7 +94,7 @@ public class InterceptorDecoratorProxyFa
     /**
      * @return the internal instance which gets proxied.
      */
-    public <T> T getInternalInstance(OwbInterceptorProxy proxyInstance)
+    public <T> T getInternalInstance(T proxyInstance)
     {
         try
         {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/PostConstructDoubleInterceptorComponent.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/PostConstructDoubleInterceptorComponent.java?rev=1434461&r1=1434460&r2=1434461&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/PostConstructDoubleInterceptorComponent.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/PostConstructDoubleInterceptorComponent.java
Wed Jan 16 22:43:22 2013
@@ -33,7 +33,6 @@ public class PostConstructDoubleIntercep
 {
     private @Inject @Check(type = "CHECK") IPayment payment;
 
-    @SuppressWarnings("unused")
     private IPayment p = null;
 
     static String setininterceptor2 = null;
@@ -42,12 +41,11 @@ public class PostConstructDoubleIntercep
     public void init()
     {
         this.p = payment;
-
     }
 
     public IPayment getP()
     {
-        return payment;
+        return p;
     }
 
     public static String getValue()

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructComponentTest.java?rev=1434461&r1=1434460&r2=1434461&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructComponentTest.java
Wed Jan 16 22:43:22 2013
@@ -75,11 +75,6 @@ public class PostConstructComponentTest 
 
         CheckWithCheckPayment chk = (CheckWithCheckPayment) pcc.getP();
 
-        ManagedBean<PostConstructComponent> s = (ManagedBean<PostConstructComponent>)
comps.get(1);
-        List<InterceptorData> stack = s.getInterceptorStack();
-
-        Assert.assertEquals(1, stack.size());
-
         Assert.assertNotNull(pcc.getP());
         Assert.assertSame(object.getValue(), chk.getValue());
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructDoubleInterceptorComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructDoubleInterceptorComponentTest.java?rev=1434461&r1=1434460&r2=1434461&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructDoubleInterceptorComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/PostConstructDoubleInterceptorComponentTest.java
Wed Jan 16 22:43:22 2013
@@ -18,70 +18,39 @@
  */
 package org.apache.webbeans.test.unittests.intercept;
 
-import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
 
 import junit.framework.Assert;
 
-import org.apache.webbeans.component.AbstractOwbBean;
-import org.apache.webbeans.component.ManagedBean;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
-import org.apache.webbeans.intercept.InterceptorData;
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.test.component.CheckWithCheckPayment;
 import org.apache.webbeans.test.component.PostConstructDoubleInterceptorComponent;
-import org.junit.Before;
 import org.junit.Test;
 
-public class PostConstructDoubleInterceptorComponentTest extends TestContext
+public class PostConstructDoubleInterceptorComponentTest extends AbstractUnitTest
 {
 
-    public PostConstructDoubleInterceptorComponentTest()
-    {
-        super(PostConstructDoubleInterceptorComponentTest.class.getSimpleName());
-    }
-
-    @Before
-    public void init()
-    {
-        super.init();
-    }
 
-    @SuppressWarnings("unchecked")
     @Test
-    public void testTypedComponent() throws Throwable
+    public void testTypedComponent() throws Exception
     {
-        clear();
 
-        defineManagedBean(CheckWithCheckPayment.class);
-        defineManagedBean(PostConstructDoubleInterceptorComponent.class);
-        List<AbstractOwbBean<?>> comps = getComponents();
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(CheckWithCheckPayment.class);
+        beanClasses.add(PostConstructDoubleInterceptorComponent.class);
 
-        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
-        contextFactory.initRequestContext(null);
+        startContainer(beanClasses, null);
 
-        Assert.assertEquals(2, comps.size());
-
-        Object object = getManager().getInstance(comps.get(0));
-        Object object2 = getManager().getInstance(comps.get(1));
-
-        Assert.assertTrue(object instanceof CheckWithCheckPayment);
-        Assert.assertTrue(object2 instanceof PostConstructDoubleInterceptorComponent);
-
-        PostConstructDoubleInterceptorComponent pcc = (PostConstructDoubleInterceptorComponent)
object2;
-
-        ManagedBean<PostConstructDoubleInterceptorComponent> s = (ManagedBean<PostConstructDoubleInterceptorComponent>)
comps.get(1);
+        PostConstructDoubleInterceptorComponent pcc = getInstance(PostConstructDoubleInterceptorComponent.class);
 
         Assert.assertNotNull(pcc.getP());
 
-        List<InterceptorData> stack = s.getInterceptorStack();
-
-        Assert.assertEquals(5, stack.size());
 
         Assert.assertNotNull(PostConstructDoubleInterceptorComponent.getValue());
         Assert.assertEquals("value1", PostConstructDoubleInterceptorComponent.getValue());
 
-        contextFactory.destroyRequestContext(null);
+        shutDownContainer();
     }
 
 }



Mime
View raw message