openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r916942 - /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
Date Sat, 27 Feb 2010 11:36:39 GMT
Author: gerdogdu
Date: Sat Feb 27 11:36:38 2010
New Revision: 916942

URL: http://svn.apache.org/viewvc?rev=916942&view=rev
Log:
[OWB-307] InvocationContext.setParameters() and primitive vs. wrapped types

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java?rev=916942&r1=916941&r2=916942&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
Sat Feb 27 11:36:38 2010
@@ -27,6 +27,7 @@
 
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.util.ClassUtil;
 
 /**
  * Implementation of the {@link InvocationContext} interface.
@@ -295,29 +296,48 @@
         {
             if (params == null)
             {
-                if (this.parameters.length > 0)
+                if (this.parameters.length >= 0)
                 {
-                    throw new IllegalArgumentException("Parameters is null");
+                    throw new IllegalArgumentException("Gvien parameters is null but expected
not null parameters");
                 }
             }
             else
             {
-                List<Class<?>> src = new ArrayList<Class<?>>();
-
                 if (params.length != this.parameters.length)
                 {
-                    throw new IllegalArgumentException("Parameters length not match");
-                }
-
-                for (Object param : params)
-                {
-                    src.add(param.getClass());
+                	 throw new IllegalArgumentException("Expected " + this.parameters.length
+ " " +
+                	 		"parameters, but only got " + params.length + " parameters"); 
                 }
 
-                for (Class<?> param : this.method.getParameterTypes())
+                Class<?>[] methodParameters = this.method.getParameterTypes();
+                int i = 0;
+                for (Object obj : params)
                 {
-                    if (!src.contains(param))
-                        throw new IllegalArgumentException("Parameters types not match");
+                	Class<?> parameterType = methodParameters[i++];
+                    if (obj == null) 
+                    {
+                        if (parameterType.isPrimitive()) 
+                        {
+                            throw new IllegalArgumentException("Expected parameter " + i
+ " to be primitive type " + parameterType.getName() +
+                                ", but got a parameter that is null");
+                        }
+                    }
+                    else
+                    {
+                    	//Primitive check
+                    	if(parameterType.isPrimitive())
+                    	{
+                    		//First change to wrapper for comparision
+                    		parameterType = ClassUtil.getPrimitiveWrapper(parameterType);
+                    	}
+                    	
+                    	//Actual check
+                    	if (!parameterType.isInstance(obj))                    	
+                    	{
+                            throw new IllegalArgumentException("Expected parameter " + i
+ " to be of type " + parameterType.getName() +
+                                    ", but got a parameter of type " + obj.getClass().getName());
                                       		
+                    	}                    	
+                    }
                 }
 
                 System.arraycopy(params, 0, this.parameters, 0, params.length);
@@ -332,6 +352,5 @@
     {
         // TODO Auto-generated method stub
         return null;
-    }
-
+    }    
 }
\ No newline at end of file



Mime
View raw message