You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ar...@apache.org on 2013/06/15 21:25:06 UTC

svn commit: r1493408 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/config/BeansDeployer.java main/java/org/apache/webbeans/util/ClassUtil.java test/java/org/apache/webbeans/newtests/producer/AmbigousProducerTest.java

Author: arne
Date: Sat Jun 15 19:25:06 2013
New Revision: 1493408

URL: http://svn.apache.org/r1493408
Log:
OWB-846: Improved generic handling and aligned exception handling to CDI 1.1 

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/AmbigousProducerTest.java

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=1493408&r1=1493407&r2=1493408&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 Sat Jun 15 19:25:06 2013
@@ -71,8 +71,10 @@ import org.apache.webbeans.util.WebBeans
 import org.apache.webbeans.xml.WebBeansXMLConfigurator;
 
 import javax.enterprise.context.NormalScope;
+import javax.enterprise.inject.AmbiguousResolutionException;
 import javax.enterprise.inject.Model;
 import javax.enterprise.inject.Specializes;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
 import javax.enterprise.inject.spi.AnnotatedField;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
@@ -206,7 +208,19 @@ public class BeansDeployer
                 webBeansContext.getAnnotatedElementFactory().clear();
             }
         }
-        catch(Exception e)
+        catch (UnsatisfiedResolutionException e)
+        {
+            throw new DeploymentException(e);
+        }
+        catch (AmbiguousResolutionException e)
+        {
+            throw new DeploymentException(e);
+        }
+        catch (WebBeansConfigurationException e)
+        {
+            throw new DeploymentException(e);
+        }
+        catch (Exception e)
         {
             throw ExceptionUtil.throwAsRuntimeException(e);
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1493408&r1=1493407&r2=1493408&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Sat Jun 15 19:25:06 2013
@@ -20,6 +20,7 @@ package org.apache.webbeans.util;
 
 import org.apache.webbeans.config.BeanTypeSetResolver;
 import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.exception.inject.DefinitionException;
 
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.spi.InjectionPoint;
@@ -979,24 +980,61 @@ public final class ClassUtil
      */
     public static Class<?> getClazz(Type type)
     {
-        Class<?> raw = null;
-        
         if(type instanceof ParameterizedType)
         {
             ParameterizedType pt = (ParameterizedType)type;
-            raw = (Class<?>)pt.getRawType();                
+            return (Class<?>)pt.getRawType();                
         }
         else if(type instanceof Class)
         {
-            raw = (Class<?>)type;
+            return (Class<?>)type;
         }
         else if(type instanceof GenericArrayType)
         {
             GenericArrayType arrayType = (GenericArrayType)type;
-            raw = getClazz(arrayType.getGenericComponentType());
+            return getClazz(arrayType.getGenericComponentType());
+        }
+        else if (type instanceof WildcardType)
+        {
+            WildcardType wildcardType = (WildcardType)type;
+            Type[] bounds = wildcardType.getUpperBounds();
+            if (bounds.length > 1)
+            {
+                throw new DefinitionException("Illegal use of wild card type with more than one upper bound: " + wildcardType);
+            }
+            else if (bounds.length == 0)
+            {
+                return Object.class;
+            }
+            else
+            {
+                return getClass(bounds[0]);
+            }
+        }
+        else if (type instanceof TypeVariable)
+        {
+            TypeVariable<?> typeVariable = (TypeVariable<?>)type;
+            if (typeVariable.getBounds().length > 1)
+            {
+                throw new DefinitionException("Illegal use of type variable with more than one bound: " + typeVariable);
+            }
+            else
+            {
+                Type[] bounds = typeVariable.getBounds();
+                if (bounds.length == 0)
+                {
+                    return Object.class;
+                }
+                else
+                {
+                    return getClass(bounds[0]);
+                }
+            }
+        }
+        else
+        {
+            throw new DefinitionException("Unsupported type " + type);
         }
-        
-        return raw;
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/AmbigousProducerTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/AmbigousProducerTest.java?rev=1493408&r1=1493407&r2=1493408&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/AmbigousProducerTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/AmbigousProducerTest.java Sat Jun 15 19:25:06 2013
@@ -26,6 +26,7 @@ import javax.enterprise.inject.Ambiguous
 import junit.framework.Assert;
 
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.inject.DeploymentException;
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.junit.Test;
 
@@ -47,7 +48,8 @@ public class AmbigousProducerTest extend
         }
         catch (WebBeansConfigurationException e)
         {
-            Assert.assertEquals(AmbiguousResolutionException.class, e.getCause().getClass());
+            Assert.assertEquals(DeploymentException.class, e.getCause().getClass());
+            Assert.assertEquals(AmbiguousResolutionException.class, e.getCause().getCause().getClass());
         }
         shutDownContainer();