You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2008/09/19 05:49:52 UTC

svn commit: r696911 - /labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java

Author: simoneg
Date: Thu Sep 18 20:49:52 2008
New Revision: 696911

URL: http://svn.apache.org/viewvc?rev=696911&view=rev
Log:
LABS-161 : Magma is now fully generics aware

Modified:
    labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java

Modified: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java?rev=696911&r1=696910&r2=696911&view=diff
==============================================================================
--- labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java (original)
+++ labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java Thu Sep 18 20:49:52 2008
@@ -20,6 +20,10 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.Collection;
+import java.util.List;
+
+import org.apache.magma.basics.utils.GenericClass;
+import org.apache.magma.basics.utils.GenericClass.MethodDef;
 
 public class PropertyInfo implements Cloneable {
 
@@ -58,16 +62,11 @@
 		this.type = descriptor.getPropertyType();
 		this.isCollection = Collection.class.isAssignableFrom(this.type);
 		if (this.isCollection && descriptor.getReadMethod() != null) {
-			Type retType = descriptor.getReadMethod().getGenericReturnType();
-			if (retType instanceof ParameterizedType) {
-				ParameterizedType parRet = (ParameterizedType) retType;
-				Type[] types = parRet.getActualTypeArguments();
-				if (types.length > 0) {
-					if (types[0] instanceof Class) {
-						this.collectionClass = (Class) types[0];
-					}
-				}
-			}
+			GenericClass returnType = GenericClass.forReturnType(descriptor.getReadMethod());
+			// It must have an add method
+			List<MethodDef> methods = returnType.findMethods("add", new Class<?>[] {null});
+			// It must have a single parameter of the type of the collection
+			this.collectionClass = methods.get(0).getParameterTypes()[0].getBaseClass();
 		}
 		this.readable = descriptor.getReadMethod() != null;
 		this.writeable = descriptor.getWriteMethod() != null;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org