Search in sources :

Example 1 with MethodInfo

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);
}
Also used : Context(javax.ws.rs.core.Context) Blocking(ren.yale.java.annotation.Blocking) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) ArgInfo(ren.yale.java.method.ArgInfo) After(ren.yale.java.aop.After) Parameter(java.lang.reflect.Parameter) MethodInfo(ren.yale.java.method.MethodInfo) Interceptor(ren.yale.java.interceptor.Interceptor) ClassInfo(ren.yale.java.method.ClassInfo)

Example 2 with MethodInfo

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));
            }
        }
    }
}
Also used : MethodInfo(ren.yale.java.method.MethodInfo) Route(io.vertx.ext.web.Route) ClassInfo(ren.yale.java.method.ClassInfo)

Aggregations

ClassInfo (ren.yale.java.method.ClassInfo)2 MethodInfo (ren.yale.java.method.MethodInfo)2 Route (io.vertx.ext.web.Route)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Context (javax.ws.rs.core.Context)1 Blocking (ren.yale.java.annotation.Blocking)1 After (ren.yale.java.aop.After)1 Interceptor (ren.yale.java.interceptor.Interceptor)1 ArgInfo (ren.yale.java.method.ArgInfo)1