openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1641684 - in /openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans: container/BeanManagerImpl.java container/InjectionResolver.java util/InjectionExceptionUtil.java
Date Tue, 25 Nov 2014 20:24:17 GMT
Author: struberg
Date: Tue Nov 25 20:24:17 2014
New Revision: 1641684

URL: http://svn.apache.org/r1641684
Log:
OWB-1031 improve error logging of injection point validation

Modified:
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1641684&r1=1641683&r2=1641684&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Tue Nov 25 20:24:17 2014
@@ -928,7 +928,7 @@ public class BeanManagerImpl extends Abs
     @Override
     public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans)
     {
-        return injectionResolver.resolve(beans);
+        return injectionResolver.resolve(beans, null);
     }
 
     /**

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1641684&r1=1641683&r2=1641684&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Tue Nov 25 20:24:17 2014
@@ -188,7 +188,7 @@ public class InjectionResolver
             }
         }
 
-        Bean<?> bean = resolve(beanSet);
+        Bean<?> bean = resolve(beanSet, injectionPoint);
 
         if (bean == null)
         {
@@ -251,7 +251,7 @@ public class InjectionResolver
             }
         }
 
-        return resolve(beanSet);
+        return resolve(beanSet, injectionPoint);
     }
 
     private void createNewBean(InjectionPoint injectionPoint, Type type, Annotation[] qualifiers,
Set<Bean<?>> beanSet)
@@ -529,16 +529,6 @@ public class InjectionResolver
         // Look for qualifiers
         resolvedComponents = findByQualifier(resolvedComponents, injectionPointType, qualifiers);
 
-        // Ambigious resolution, check for specialization
-        /*
-        // super beans are deactivated so it is useless
-        if (resolvedComponents.size() > 1)
-        {
-            //Look for specialization
-            resolvedComponents = findBySpecialization(resolvedComponents);
-        }
-        */
-
         resolvedBeansByType.put(cacheKey, resolvedComponents);
         if (logger.isLoggable(Level.FINE))
         {
@@ -682,7 +672,15 @@ public class InjectionResolver
         return enableSet;
     }
 
-    public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans)
+    /**
+     *
+     * @param beans
+     * @param injectionPoint only used for logging. Can be null.
+     * @param <X>
+     * @return the single resolved bean, null if none is activated
+     * @throws javax.enterprise.inject.AmbiguousResolutionException if more than 1 bean is
active
+     */
+    public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans,
InjectionPoint injectionPoint)
     {
         Set set = resolveAll(beans);
         
@@ -696,7 +694,7 @@ public class InjectionResolver
             set = findBySpecialization(set);
             if(set.size() > 1)
             {
-                throwAmbiguousResolutionException(set);
+                throwAmbiguousResolutionException(set, null, injectionPoint);
             }
         }
 
@@ -723,14 +721,6 @@ public class InjectionResolver
             return Collections.emptySet();
         }
 
-        /*
-        // specialized bean are disabled so no need to refilter
-        if(set.size() > 1)
-        {
-            set = findBySpecialization(set);
-        }
-        */
-
         return set;
     }
 

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java?rev=1641684&r1=1641683&r2=1641684&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
Tue Nov 25 20:24:17 2014
@@ -50,7 +50,7 @@ public class InjectionExceptionUtil
         ViolationMessageBuilder violationMessage =
                 newViolation("Api type [", type.getName(), "] is not found with the qualifiers
");
 
-        violationMessage.addLine(createQualifierMessage(qualifiers));
+        violationMessage.addLine(createQualifierMessage(injectionPoint, qualifiers));
 
         if (injectionPoint != null)
         {
@@ -73,22 +73,21 @@ public class InjectionExceptionUtil
 
     public static void throwAmbiguousResolutionException(Set<Bean<?>> beans,
Class type, InjectionPoint injectionPoint, Annotation... qualifiers)
     {
-        String qualifierMessage = createQualifierMessage(qualifiers);
+        String qualifierMessage = createQualifierMessage(injectionPoint, qualifiers);
 
-        ViolationMessageBuilder violationMessage;
-
-        if(type != null)
+        String classString = type != null ? ClassUtil.getClass(type).getName() : null;
+        if (classString == null && injectionPoint != null)
         {
-            violationMessage = newViolation("There is more than one api type with : ",
-                    ClassUtil.getClass(type).getName(), " with qualifiers : ", qualifierMessage);
-            if (injectionPoint != null)
-            {
-                violationMessage.addLine("for injection into ", injectionPoint.toString());
-            }
+            classString = ClassUtil.getClass(injectionPoint.getType()).getName();
         }
-        else
+
+        ViolationMessageBuilder violationMessage = newViolation("There is more than one Bean
",
+                classString != null ? "with type " + classString : ""
+                , qualifierMessage);
+
+        if (injectionPoint != null)
         {
-            violationMessage = newViolation("Ambiguous resolution");
+            violationMessage.addLine("for injection into ", injectionPoint.toString());
         }
 
         throwAmbiguousResolutionExceptionForBeans(beans, violationMessage);
@@ -123,11 +122,18 @@ public class InjectionExceptionUtil
         }
     }
 
-    private static String createQualifierMessage(Annotation... qualifiers)
+    private static String createQualifierMessage(InjectionPoint injectionPoint, Annotation...
qualifiers)
     {
         if(qualifiers == null || qualifiers.length == 0)
         {
-            return null;
+            if (injectionPoint != null)
+            {
+                qualifiers = injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]);
+            }
+            else
+            {
+                return "@Default";
+            }
         }
 
         //reused source-code



Mime
View raw message