diff --git a/src/dev/peerat/framework/Router.java b/src/dev/peerat/framework/Router.java index 81f716d..6048916 100644 --- a/src/dev/peerat/framework/Router.java +++ b/src/dev/peerat/framework/Router.java @@ -5,17 +5,14 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.lang.reflect.Parameter; import java.net.ServerSocket; import java.net.Socket; import java.security.Key; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; -import java.util.regex.Pattern; import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocketFactory; @@ -34,7 +31,7 @@ import org.jose4j.lang.JoseException; public class Router{ - public static void main(String[] args) { + public static void main(String[] args){ } @@ -106,6 +103,7 @@ public class Router{ Route route = method.getAnnotation(Route.class); this.mappers[route.type().ordinal()].register(response, method, route); + System.out.println("Registered route "+method+" ["+route.type()+" "+route.path()+"]"); }catch(Exception e){ throw new IllegalArgumentException(e); } @@ -117,13 +115,16 @@ public class Router{ } public Router registerClass(Class clazz, DependencyInjector injector) throws Exception{ - Constructor[] constructors = clazz.getDeclaredConstructors(); - if(constructors.length != 1) throw new IllegalArgumentException("Class with multiple constructor. Not supported by this framework for the moment."); - Object instance = constructors[0].newInstance(injector.apply(constructors[0])); + Object instance = null; for(Method method : clazz.getDeclaredMethods()){ Route route = method.getAnnotation(Route.class); if(route == null) continue; + if(instance == null){ + Constructor[] constructors = clazz.getDeclaredConstructors(); + if(constructors.length != 1) throw new IllegalArgumentException("Class with multiple constructor. Not supported by this framework for the moment."); + instance = constructors[0].newInstance(injector.apply(constructors[0])); + } this.mappers[route.type().ordinal()].register(instance, method, route); System.out.println("Registered route "+method+" ["+route.type()+" "+route.path()+"]"); @@ -153,11 +154,11 @@ public class Router{ String line; while((line = reader.readLine()) != null){ if(line.endsWith(".class")){ - Class clazz = Class.forName(name+"."+line.substring(0, line.lastIndexOf('.'))); + Class clazz = Class.forName(name+"."+line.substring(0, line.length()-6)); registerClass(clazz, injector); - }else{ - registerPackages(name+"."+line, injector); + continue; } + if(!line.contains(".")) registerPackages(name+"."+line, injector); } reader.close(); }catch(Exception e){