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:48 UTC

svn commit: r696910 - /labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java

Author: simoneg
Date: Thu Sep 18 20:49:48 2008
New Revision: 696910

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

Modified:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java?rev=696910&r1=696909&r2=696910&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java (original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java Thu Sep 18 20:49:48 2008
@@ -17,13 +17,18 @@
 package org.apache.magma.website;
 
 import org.apache.magma.basics.MagmaException;
+import org.apache.magma.basics.utils.GenericClass;
+import org.apache.magma.basics.utils.GenericClass.MethodDef;
 import org.apache.magma.conversion.Converter;
 import org.apache.magma.conversion.Converters;
 import org.apache.magma.website.templating.Template;
 
 import java.lang.reflect.Method;
 import java.util.Arrays;
+import java.util.List;
 
+// TODO optimization : GenericClass could be taken only once
+// TODO optimization : getRightMethod could return a MethodRef directly
 public class WebHandler implements Templatable {
 
 	public static final String defaultPostfix = "_default";
@@ -131,7 +136,8 @@
 	}
 
 	Object[] bindParameters(Method rightMethod, String[] info) {
-		Class<?>[] types = rightMethod.getParameterTypes();
+		GenericClass gc = GenericClass.forClass(getClass());
+		Class<?>[] types = GenericClass.toRawClasses(gc.getParameterTypes(rightMethod));
 		if (types.length == 0) return null;
 		int consumed = getConsumed(info);
 		boolean isfinal = rightMethod.getName().startsWith("do");
@@ -190,6 +196,26 @@
 
 	Method findMethodFor(String segment) {
 		if (segment.length() == 0) segment=defaultPostfix;
+		GenericClass genericClass = GenericClass.forClass(getClass());
+		Method rightMethod = null;
+		
+		List<MethodDef> methods = genericClass.findAllMethods("do" + segment);
+		for (MethodDef methodDef : methods) {
+			if (Producer.class.isAssignableFrom(methodDef.getReturnType().getBaseClass())) {
+				rightMethod = methodDef.getBaseMethod();
+				break;				
+			}
+		}
+		if (rightMethod == null) {
+			methods = genericClass.findAllMethods("handle" + segment);
+			for (MethodDef methodDef : methods) {
+				if (WebHandler.class.isAssignableFrom(methodDef.getReturnType().getBaseClass())) {
+					rightMethod = methodDef.getBaseMethod();
+					break;				
+				}
+			}
+		}
+		/*
 		Method[] methods = getClass().getMethods();
 		Method rightMethod = null;
 		for (Method method : methods) {
@@ -205,8 +231,9 @@
 				}				
 			}
 		}
+		*/
 		if (rightMethod == null) {
-			// TODO throw an error? go for a default one if provided?
+			// TODO throw a "page not found" error
 			return null;
 		}
 		return rightMethod;



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