use of ren.yale.java.method.MethodInfo in project Summer by yale8848.
the class MethodsProcessor method get.
public static void get(List<ClassInfo> classInfos, Class clazz) {
Path path = (Path) clazz.getAnnotation(Path.class);
if (path == null || path.value() == null) {
return;
}
ClassInfo classInfo = new ClassInfo();
classInfo.setClassPath(path.value());
classInfo.setClazzObj(newClass(clazz));
classInfo.setClazz(clazz);
Interceptor[] interceptorsClazz = getBefores((Before) clazz.getAnnotation(Before.class));
if (interceptorsClazz != null) {
classInfo.setBefores(interceptorsClazz);
}
interceptorsClazz = getAfters((After) clazz.getAnnotation(After.class));
if (interceptorsClazz != null) {
classInfo.setAfters(interceptorsClazz);
}
for (Method method : clazz.getMethods()) {
Class mt = method.getDeclaringClass();
if (mt == Object.class) {
continue;
}
MethodInfo methodInfo = new MethodInfo();
Interceptor[] interceptorsMethod = getBefores((Before) method.getAnnotation(Before.class));
if (interceptorsMethod != null) {
methodInfo.setBefores(interceptorsMethod);
}
interceptorsMethod = getAfters((After) method.getAnnotation(After.class));
if (interceptorsMethod != null) {
methodInfo.setAfters(interceptorsMethod);
}
Blocking blocking = method.getAnnotation(Blocking.class);
if (blocking != null) {
methodInfo.setBlocking(true);
}
Path pathMthod = (Path) method.getAnnotation(Path.class);
Produces produces = (Produces) method.getAnnotation(Produces.class);
methodInfo.setMethodPath(getPathValue(pathMthod));
methodInfo.setProducesType(getProducesValue(produces));
methodInfo.setHttpMethod(getHttpMethod(method));
methodInfo.setMethod(method);
Parameter[] parameters = method.getParameters();
Class<?>[] parameterTypes = method.getParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
int i = 0;
for (Annotation[] an : annotations) {
ArgInfo argInfo = new ArgInfo();
argInfo.setAnnotation(an);
argInfo.setClazz(parameterTypes[i]);
argInfo.setParameter(parameters[i]);
for (Annotation ant : an) {
if (ant instanceof Context) {
argInfo.setContext(true);
} else if (ant instanceof DefaultValue) {
argInfo.setDefaultValue(((DefaultValue) ant).value());
} else if (ant instanceof PathParam) {
argInfo.setPathParam(true);
argInfo.setPathParam(((PathParam) ant).value());
} else if (ant instanceof QueryParam) {
argInfo.setQueryParam(true);
argInfo.setQueryParam(((QueryParam) ant).value());
} else if (ant instanceof FormParam) {
argInfo.setFormParam(true);
argInfo.setFormParam(((FormParam) ant).value());
}
}
i++;
methodInfo.addArgInfo(argInfo);
}
classInfo.addMethodInfo(methodInfo);
}
classInfos.add(classInfo);
}
use of ren.yale.java.method.MethodInfo in project Summer by yale8848.
the class SummerRouter method registerResource.
public void registerResource(Class clazz) {
if (isRegister(clazz)) {
return;
}
MethodsProcessor.get(classInfos, clazz);
for (ClassInfo classInfo : classInfos) {
for (MethodInfo methodInfo : classInfo.getMethodInfoList()) {
String p = classInfo.getClassPath() + methodInfo.getMethodPath();
p = PathParamConverter.converter(p);
p = addContextPath(p);
Route route = null;
if (methodInfo.getHttpMethod() == null) {
route = router.route(p);
} else if (methodInfo.getHttpMethod() == GET.class) {
route = router.get(p);
} else if (methodInfo.getHttpMethod() == POST.class) {
route = router.post(p);
} else if (methodInfo.getHttpMethod() == PUT.class) {
route = router.put(p);
} else if (methodInfo.getHttpMethod() == DELETE.class) {
route = router.delete(p);
} else if (methodInfo.getHttpMethod() == OPTIONS.class) {
route = router.options(p);
} else if (methodInfo.getHttpMethod() == HEAD.class) {
route = router.head(p);
}
if (methodInfo.isBlocking()) {
route.blockingHandler(getHandler(classInfo, methodInfo));
} else {
route.handler(getHandler(classInfo, methodInfo));
}
}
}
}
Aggregations