use of eu.okaeri.platform.web.annotation.Controller in project okaeri-platform by OkaeriPoland.
the class RequestHandlerMeta method of.
public static RequestHandlerMeta of(Class<?> parentClass, Method method) {
Annotation[] handlers = RequestHandlerHelper.findHandlers(method);
if (handlers.length != 1) {
throw new IllegalArgumentException("Cannot process method with " + handlers.length + " handler annotations: " + method);
}
Annotation handlerAnnotation = handlers[0];
String path = RequestHandlerHelper.readHandlerPath(handlerAnnotation);
HandlerType type = RequestHandlerHelper.readHandlerType(handlerAnnotation);
String[] handlerPermittedRoles = RequestHandlerHelper.readPermittedRoles(handlerAnnotation);
Parameter[] parameters = method.getParameters();
int[] contextIndexes = RequestHandlerHelper.readContextIndexes(parameters);
Map<Integer, PathParamMeta> pathParams = PathParamMeta.of(parameters);
Controller controller = parentClass.getAnnotation(Controller.class);
String pathPrefix = controller == null ? "" : controller.path();
String[] defaultPermittedRoles = controller == null ? new String[] { "ANYONE" } : controller.defaultPermittedRoles();
String[] permittedRoleNames = handlerPermittedRoles.length > 0 ? handlerPermittedRoles : defaultPermittedRoles;
SimpleRouteRole[] permittedRoles = Arrays.stream(permittedRoleNames).map(SimpleRouteRole::new).toArray(SimpleRouteRole[]::new);
return new RequestHandlerMeta(method, pathPrefix + path, type, permittedRoles, contextIndexes, pathParams);
}
Aggregations