openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1622322 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: container/InjectionResolver.java exception/inject/NullableDependencyException.java inject/AbstractInjectable.java util/ClassUtil.java
Date Wed, 03 Sep 2014 19:19:38 GMT
Author: arne
Date: Wed Sep  3 19:19:38 2014
New Revision: 1622322

URL: http://svn.apache.org/r1622322
Log:
OWB-1000: Implemented

Removed:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/NullableDependencyException.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java

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=1622322&r1=1622321&r2=1622322&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 Sep  3 19:19:38 2014
@@ -48,7 +48,6 @@ import org.apache.webbeans.component.Owb
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import javax.enterprise.inject.spi.DefinitionException;
-import org.apache.webbeans.exception.inject.NullableDependencyException;
 import org.apache.webbeans.inject.AlternativesManager;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.spi.BDABeansXmlScanner;
@@ -203,16 +202,6 @@ public class InjectionResolver
         {
             InjectionExceptionUtil.throwUnsatisfiedResolutionException(clazz, injectionPoint,
qualifiers);
         }
-
-
-        if (clazz.isPrimitive())
-        {
-            if (bean.isNullable())
-            {
-                throw new NullableDependencyException("Injection point type : " + injectionPoint
+
-                                                      " type is primitive but resolved bean
can have nullable objects!");
-            }
-        }
     }
 
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1622322&r1=1622321&r2=1622322&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
Wed Sep  3 19:19:38 2014
@@ -36,6 +36,7 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
 /**
@@ -109,9 +110,17 @@ public abstract class AbstractInjectable
         //Gets injectable reference for injected bean
         injected = (T) beanManager.getInjectableReference(injectionPoint, injectionPointContext);
 
-        if (injected == null && beanManager.isNormalScope(injectedBean.getScope()))
+        if (injected == null)
         {
-            throw new IllegalStateException("InjectableReference is 'null' for " + injectionPoint.toString());
+            if (beanManager.isNormalScope(injectedBean.getScope()))
+            {
+                throw new IllegalStateException("InjectableReference is 'null' for " + injectionPoint.toString());
+            }
+            Class<?> type = ClassUtil.getClass(injectionPoint.getType());
+            if (type.isPrimitive())
+            {
+                injected = (T) ClassUtil.getDefaultValue(type);
+            }
         }
 
         /*X TODO see spec issue CDI-140 */

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=1622322&r1=1622321&r2=1622322&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
Wed Sep  3 19:19:38 2014
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.util;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -27,6 +28,7 @@ import java.lang.reflect.TypeVariable;
 import java.lang.reflect.WildcardType;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -36,6 +38,7 @@ import java.util.Set;
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.webbeans.exception.WebBeansException;
+
 import javax.enterprise.inject.spi.DefinitionException;
 
 /**
@@ -46,19 +49,32 @@ import javax.enterprise.inject.spi.Defin
  */
 public final class ClassUtil
 {
-    public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPERS_MAP
= new HashMap<Class<?>, Class<?>>();
+    public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPERS_MAP;
+    public static final Map<Class<?>, Object> DEFAULT_VALUES_MAP;
 
     static
     {
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Integer.TYPE,Integer.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Float.TYPE,Float.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Double.TYPE,Double.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Character.TYPE,Character.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Long.TYPE,Long.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Byte.TYPE,Byte.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Short.TYPE,Short.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Boolean.TYPE,Boolean.class);
-        PRIMITIVE_TO_WRAPPERS_MAP.put(Void.TYPE,Void.class);
+        Map<Class<?>, Class<?>> primitiveToWrappersMap = new HashMap<Class<?>,
Class<?>>();
+        primitiveToWrappersMap.put(Integer.TYPE,Integer.class);
+        primitiveToWrappersMap.put(Float.TYPE,Float.class);
+        primitiveToWrappersMap.put(Double.TYPE,Double.class);
+        primitiveToWrappersMap.put(Character.TYPE,Character.class);
+        primitiveToWrappersMap.put(Long.TYPE,Long.class);
+        primitiveToWrappersMap.put(Byte.TYPE,Byte.class);
+        primitiveToWrappersMap.put(Short.TYPE,Short.class);
+        primitiveToWrappersMap.put(Boolean.TYPE,Boolean.class);
+        primitiveToWrappersMap.put(Void.TYPE,Void.class);
+        PRIMITIVE_TO_WRAPPERS_MAP = Collections.unmodifiableMap(primitiveToWrappersMap);
+        Map<Class<?>, Object> defaultValuesMap = new HashMap<Class<?>,
Object>();
+        defaultValuesMap.put(Integer.TYPE, Integer.valueOf(0));
+        defaultValuesMap.put(Float.TYPE, Float.valueOf(0F));
+        defaultValuesMap.put(Double.TYPE, Double.valueOf(0D));
+        defaultValuesMap.put(Character.TYPE, Character.valueOf('\u0000'));
+        defaultValuesMap.put(Long.TYPE, Long.valueOf(0L));
+        defaultValuesMap.put(Byte.TYPE, Byte.valueOf((byte)0));
+        defaultValuesMap.put(Short.TYPE, Short.valueOf((short)0));
+        defaultValuesMap.put(Boolean.TYPE, Boolean.FALSE);
+        DEFAULT_VALUES_MAP = Collections.unmodifiableMap(defaultValuesMap);
     }
 
     public static final Type[] NO_TYPES = new Type[0];
@@ -144,6 +160,11 @@ public final class ClassUtil
 
     }
 
+    public static Object getDefaultValue(Class<?> type)
+    {
+        return DEFAULT_VALUES_MAP.get(type);
+    }
+
     /**
      * Gets the class of the given type arguments.
      * <p>
@@ -452,60 +473,6 @@ public final class ClassUtil
 
         return !Modifier.isAbstract(modifier) && !Modifier.isInterface(modifier);
     }
-
-    /**
-     * Checks that event is applicable
-     * for the given observer type.
-     * @param eventType event type
-     * @param observerType observer type
-     * @return true if event is applicable
-     */
-//    public static boolean checkEventTypeAssignability(Type eventType, Type observerType)
-//    {
-//        //Observer type is a TypeVariable
-//        if(isTypeVariable(observerType))
-//        {
-//            Class<?> eventClass = getClass(eventType);
-//                        
-//            TypeVariable<?> tvBeanTypeArg = (TypeVariable<?>)observerType;
-//            Type tvBound = tvBeanTypeArg.getBounds()[0];
-//            
-//            if(tvBound instanceof Class)
-//            {
-//                Class<?> clazzTvBound = (Class<?>)tvBound;                
-//                if(clazzTvBound.isAssignableFrom(eventClass))
-//                {
-//                    return true;
-//                }                    
-//            }
-//        }
-//        //Both of them are ParametrizedType
-//        else if(observerType instanceof ParameterizedType && eventType instanceof
ParameterizedType)
-//        {
-//            return isAssignableForParametrized((ParameterizedType)eventType, (ParameterizedType)observerType);
-//        }
-//        //Observer is class and Event type is Parametrized
-//        else if(observerType instanceof Class && eventType instanceof ParameterizedType)
-//        {
-//            Class<?> clazzBeanType = (Class<?>)observerType;
-//            ParameterizedType ptEvent = (ParameterizedType)eventType;
-//            Class<?> eventClazz = (Class<?>)ptEvent.getRawType();
-//            
-//            if(isClassAssignable(clazzBeanType, eventClazz))
-//            {
-//                return true;
-//            }
-//            
-//            return false;            
-//        }
-//        //Both of them is class type
-//        else if(observerType instanceof Class && eventType instanceof Class)
-//        {
-//            return isClassAssignable((Class<?>)observerType, (Class<?>) eventType);
-//        }
-//        
-//        return false;
-//    }
     
     
     /**
@@ -751,7 +718,7 @@ public final class ClassUtil
         else if(type instanceof GenericArrayType)
         {
             GenericArrayType arrayType = (GenericArrayType)type;
-            return getClazz(arrayType.getGenericComponentType());
+            return Array.newInstance(getClazz(arrayType.getGenericComponentType()), 0).getClass();
         }
         else if (type instanceof WildcardType)
         {
@@ -885,7 +852,7 @@ public final class ClassUtil
         
         return false;
     }
-    
+
     private static boolean isSuperClass(Class<?> superClass, Class<?> subClass)
     {
         return superClass.isAssignableFrom(subClass) && !superClass.equals(subClass);



Mime
View raw message