Resource.java 文件源码

java
阅读 37 收藏 0 点赞 0 评论 0

项目:echidna 作者:
/**
 * Find all handler mehtods of the resource.
 *
 * @param resourceInstance The instance.
 */
private void findResourceMethods(Object resourceInstance) {
    for (Method declaredMethod : resourceInstance.getClass().getDeclaredMethods()) {
        Path methodPath = declaredMethod.getAnnotation(Path.class);

        if (methodPath == null) {
            continue;
        }

        Consumes consumes = declaredMethod.getAnnotation(Consumes.class);
        Produces produces = declaredMethod.getAnnotation(Produces.class);

        HTTPMethod method = HTTPMethod.GET;

        if (declaredMethod.isAnnotationPresent(POST.class)) {
            method = HTTPMethod.POST;
        } else if (declaredMethod.isAnnotationPresent(DELETE.class)) {
            method = HTTPMethod.DELETE;
        } else if (declaredMethod.isAnnotationPresent(PUT.class)) {
            method = HTTPMethod.PUT;
        } else if (declaredMethod.isAnnotationPresent(PATCH.class)) {
            method = HTTPMethod.PATCH;
        }

        ResourceMethod resourceMethod = new ResourceMethod(methodPath.value(), method,
            consumes.value(), produces.value(), declaredMethod, resourceInstance);

        for (Parameter parameter : declaredMethod.getParameters()) {
            if (parameter.isAnnotationPresent(PostKey.class)) {
                resourceMethod.addPostParam(parameter.getAnnotation(PostKey.class).value());
            }
        }

        this.resourceMethods.put(methodPath.value(), resourceMethod);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号