openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1362839 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/container/ test/java/org/apache/webbeans/newtests/ test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/
Date Wed, 18 Jul 2012 10:08:38 GMT
Author: struberg
Date: Wed Jul 18 10:08:38 2012
New Revision: 1362839

URL: http://svn.apache.org/viewvc?rev=1362839&view=rev
Log:
OWB-667 clarify getBeans() vs resolve()

getBeans() now returns all enabled beans and does 
Alternative filtering only later in resolve().
This behaviour will get clarified in CDI-1.1 finally.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=1362839&r1=1362838&r2=1362839&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
Wed Jul 18 10:08:38 2012
@@ -853,15 +853,15 @@ public final class DefinitionUtil
             Type type = AnnotationUtil.getMethodFirstParameterWithAnnotation(declaredMethod,
Disposes.class);
             Annotation[] annot = annotationManager.getMethodFirstParameterQualifierWithGivenAnnotation(declaredMethod,
Disposes.class);
 
-            InjectionResolver instance = webBeansContext.getBeanManagerImpl().getInjectionResolver();
+            InjectionResolver injectionResolver = webBeansContext.getBeanManagerImpl().getInjectionResolver();
 
-            Set<Bean<?>> set = instance.implResolveByType(type, annot);
-            if (set.isEmpty())
+            Set<Bean<?>> set = injectionResolver.implResolveByType(type, annot);
+            Bean<?> bean = injectionResolver.resolve(set);
+            if (bean == null)
             {
                 throwUnsatisfiedResolutionException(clazz, declaredMethod, annot);
             }
             
-            Bean<?> bean = set.iterator().next();
             ProducerMethodBean<?> pr = null;
 
             if (!(bean instanceof ProducerMethodBean))

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1362839&r1=1362838&r2=1362839&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Wed Jul 18 10:08:38 2012
@@ -94,7 +94,6 @@ import org.apache.webbeans.util.ClassUti
 import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.webbeans.xml.WebBeansXMLConfigurator;
 
-import static org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException;
 import static org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeanName;
 
 /**
@@ -1102,30 +1101,7 @@ public class BeanManagerImpl implements 
 
     public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans)
     {
-        if (beans == null || beans.isEmpty())
-        {
-            return null;
-        }
-
-        Set set = new HashSet<Bean<Object>>();
-        for(Bean<? extends X> obj : beans)
-        {
-            set.add(obj);
-        }
-        
-        set = injectionResolver.findByAlternatives(set);
-
-        if(set.size() > 1)
-        {
-            set = injectionResolver.findBySpecialization(set);
-        }
-        
-        if(set.size() > 1)
-        {
-            throwAmbiguousResolutionException(set);
-        }
-        
-        return (Bean<? extends X>)set.iterator().next();
+        return injectionResolver.resolve(beans);
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1362839&r1=1362838&r2=1362839&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Wed Jul 18 10:08:38 2012
@@ -42,6 +42,7 @@ import javax.enterprise.util.Nonbinding;
 import org.apache.webbeans.annotation.AnyLiteral;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.inject.NullableDependencyException;
@@ -51,7 +52,9 @@ import org.apache.webbeans.spi.ScannerSe
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.InjectionExceptionUtils;
 import org.apache.webbeans.util.WebBeansUtil;
+import static org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException;
 
 /**
  * Injection point resolver class.
@@ -158,7 +161,7 @@ public class InjectionResolver
         WebBeansUtil.checkInjectionPointNamedQualifier(injectionPoint);
 
         Type type = injectionPoint.getType();
-        Class<?> clazz = null;
+        Class<?> clazz;
 
         if (ClassUtil.isTypeVariable(type))
         {
@@ -199,15 +202,20 @@ public class InjectionResolver
             }
         }
 
-        webBeansContext.getResolutionUtil().checkResolvedBeans(beanSet, clazz, qualifiers,
injectionPoint);
+        Bean<?> bean = resolve(beanSet);
+
+        if (bean == null)
+        {
+            InjectionExceptionUtils.throwUnsatisfiedResolutionException(clazz, injectionPoint,
qualifiers);
+        }
 
-        Bean<?> bean = beanSet.iterator().next();
 
         if (clazz.isPrimitive())
         {
             if (bean.isNullable())
             {
-                throw new NullableDependencyException("Injection point type : " + injectionPoint
+ " type is primitive but resolved bean can have nullable objects!");
+                throw new NullableDependencyException("Injection point type : " + injectionPoint
+
+                                                      " type is primitive but resolved bean
can have nullable objects!");
             }
         }
 
@@ -224,14 +232,12 @@ public class InjectionResolver
     {
 
         Type type = injectionPoint.getType();
-        Class<?> clazz = null;
+        Class<?> clazz;
 
         if (type instanceof ParameterizedType)
         {
             ParameterizedType pt = (ParameterizedType) type;
             clazz = (Class<?>) pt.getRawType();
-
-
         }
         else
         {
@@ -267,14 +273,14 @@ public class InjectionResolver
                 {
                     beanSet.add(webBeansContext.getWebBeansUtil().createNewComponent(newQualifier.value(),
null));
                 }
-
+            }
+            else
+            {
+                InjectionExceptionUtils.throwUnsatisfiedResolutionException(clazz, injectionPoint,
qualifiers);
             }
         }
 
-        webBeansContext.getResolutionUtil().checkResolvedBeans(beanSet, clazz, qualifiers,
injectionPoint);
-
-        return beanSet.iterator().next();
-
+        return resolve(beanSet);
     }
 
 
@@ -492,6 +498,12 @@ public class InjectionResolver
 
         for (Bean<?> component : webBeansContext.getBeanManagerImpl().getBeans())
         {
+            // no need to check instanceof OwbBean as we always wrap in a
+            // ThirdpartyBeanImpl at least
+            if (!((OwbBean) component).isEnabled())
+            {
+                continue;
+            }
 
             if (returnAll)
             {
@@ -514,15 +526,6 @@ public class InjectionResolver
         // Look for qualifiers
         resolvedComponents = findByQualifier(resolvedComponents, qualifiers);
 
-        if (!injectionPointType.equals(Object.class))
-        {
-            // see OWB-658 skip if all Object.class instances are requested
-            // as there is no way to Alternative Object.class
-
-            // Look for alternative
-            resolvedComponents = findByAlternatives(resolvedComponents, bdaBeansXMLFilePath);
-        }
-
         // Ambigious resolution, check for specialization
         if (resolvedComponents.size() > 1)
         {
@@ -809,6 +812,40 @@ public class InjectionResolver
         return enableSet;
     }
 
+    public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans)
+    {
+        if (beans == null || beans.isEmpty())
+        {
+            return null;
+        }
+
+        Set set = new HashSet<Bean<Object>>();
+        for(Bean<? extends X> obj : beans)
+        {
+            set.add(obj);
+        }
+
+        set = findByAlternatives(set);
+
+        if (set == null || set.isEmpty())
+        {
+            return null;
+        }
+
+        if(set.size() > 1)
+        {
+            set = findBySpecialization(set);
+        }
+
+        if(set.size() > 1)
+        {
+            throwAmbiguousResolutionException(set);
+        }
+
+        return (Bean<? extends X>)set.iterator().next();
+    }
+
+
     private boolean isAltBeanInInjectionPointBDA(String bdaBeansXMLFilePath, Bean<?>
altBean)
     {
 

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=1362839&r1=1362838&r2=1362839&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
Wed Jul 18 10:08:38 2012
@@ -115,9 +115,8 @@ public abstract class AbstractUnitTest
     {
         Set<Bean<?>> beans = getBeanManager().getBeans(type, qualifiers);
         Assert.assertNotNull(beans);
-        Assert.assertTrue("resolving bean with type" + type + " is ambiguous or bean is not
found!", beans.size() == 1);
-        
-        Bean<T> bean = (Bean<T>) beans.iterator().next();
+
+        Bean<?> bean = getBeanManager().resolve(beans);
         
         return (T) getBeanManager().getReference(bean, type, getBeanManager().createCreationalContext(bean));
     }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java?rev=1362839&r1=1362838&r2=1362839&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
Wed Jul 18 10:08:38 2012
@@ -63,7 +63,7 @@ public class AlternativeBeanResolvingTes
         // available but not enabled in beans.xml
         beanClasses.add(AlternativeOnClassOnlyBean.class);
 
-        startContainer(beanClasses, null);
+        startContainer(beanClasses, beanXmls);
 
         Set<Bean<?>> beans = getBeanManager().getBeans(Object.class, new AnnotationLiteral<Pen>(){});
         Assert.assertNotNull(beans);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java?rev=1362839&r1=1362838&r2=1362839&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java
Wed Jul 18 10:08:38 2012
@@ -55,6 +55,8 @@ public class AlternativeOnProducerFieldT
         Set<Bean<?>> beans = getBeanManager().getBeans(Pencil.class, new AnnotationLiteral<Pen>(){});
         Assert.assertEquals(0, beans.size());
 
+        Assert.assertNull(getBeanManager().resolve(beans));
+
         shutDownContainer();
     }
 
@@ -76,6 +78,9 @@ public class AlternativeOnProducerFieldT
         Assert.assertNotNull(pencil);
         Assert.assertEquals(42, pencil.getNr());
 
+        beans = getBeanManager().getBeans(PencilProducerBean.class);
+        Assert.assertEquals(1, beans.size());
+
         shutDownContainer();
     }
 



Mime
View raw message