openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1299032 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/InstanceBean.java test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
Date Fri, 09 Mar 2012 20:29:54 GMT
Author: struberg
Date: Fri Mar  9 20:29:54 2012
New Revision: 1299032

URL: http://svn.apache.org/viewvc?rev=1299032&view=rev
Log:
OWB-567 we cannot solve this problem, but we now are compatible with the RI

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java?rev=1299032&r1=1299031&r2=1299032&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InstanceBean.java
Fri Mar  9 20:29:54 2012
@@ -49,19 +49,26 @@ public class InstanceBean<T> extends Abs
     {
         try
         {
-            ParameterizedType injectedType = (ParameterizedType)local.get().getType();
-            Set<Annotation> qualifiers = local.get().getQualifiers();
-            Type type = injectedType.getActualTypeArguments()[0];
             InjectionPoint injectionPoint = local.get();
+            Set<Annotation> qualifiers;
+            Type type;
             Class injectionPointClass = null;
 
             if (injectionPoint != null)
             {
+                ParameterizedType injectedType = (ParameterizedType)injectionPoint.getType();
+                qualifiers = injectionPoint.getQualifiers();
+                type = injectedType.getActualTypeArguments()[0];
                 if (injectionPoint.getBean() != null)
                 {
                     injectionPointClass = injectionPoint.getBean().getBeanClass();
                 }
             }
+            else
+            {
+                qualifiers = getQualifiers();
+                type = getReturnType();
+            }
 
             Object ownerInstance = AbstractInjectable.instanceUnderInjection.get();
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java?rev=1299032&r1=1299031&r2=1299032&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
Fri Mar  9 20:29:54 2012
@@ -30,9 +30,14 @@ import org.apache.webbeans.test.componen
 import org.apache.webbeans.test.component.PaymentProcessorComponent;
 import org.junit.Test;
 
+import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.TypeLiteral;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Set;
+
 
 public class InjectedInstanceComponentTest extends AbstractUnitTest
 {
@@ -89,4 +94,33 @@ public class InjectedInstanceComponentTe
         Assert.assertTrue(DependentBean.properlyDestroyed);
     }
 
+    @Test
+    public void testManualInstanceResolving()
+    {
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+
+        beanClasses.add(PaymentProcessorComponent.class);
+        beanClasses.add(CheckWithCheckPayment.class);
+        beanClasses.add(CheckWithMoneyPayment.class);
+        beanClasses.add(IPayment.class);
+
+        startContainer(beanClasses, null);
+
+        Set<Bean<?>> beans =
+                getBeanManager().getBeans(new TypeLiteral<Instance<PaymentProcessorComponent>>()
{}.getType());
+        Bean<Instance<PaymentProcessorComponent>> bean =
+                (Bean<Instance<PaymentProcessorComponent>>) getBeanManager().resolve(beans);
+        CreationalContext<Instance<PaymentProcessorComponent>> creationalContext
=
+                getBeanManager().createCreationalContext(bean);
+        Instance<PaymentProcessorComponent> provider = bean.create(creationalContext);
+        Assert.assertNotNull(provider);
+
+        // please note that the provider will NOT create a PaymentProcessorComponent
+        // because the Bean doesn't know this information! This is compatible with Weld
+        // which also doesn't handle this case. This is due to the fact that the spec
+        // defines that there is only one InstanceBean.
+
+        shutDownContainer();
+    }
+
 }



Mime
View raw message