use of org.forgerock.util.promise.Promise in project OpenAM by OpenRock.
the class AnnotatedMethod method checkMethod.
static AnnotatedMethod checkMethod(Class<?> annotation, Object requestHandler, Method method) {
List<ContextParameter> contextParams = new ArrayList<>();
int requestParam = -1;
for (int i = 0; i < method.getParameterTypes().length; i++) {
Class<?> type = method.getParameterTypes()[i];
for (Annotation paramAnnotation : method.getParameterAnnotations()[i]) {
if (paramAnnotation instanceof Contextual) {
if (Context.class.isAssignableFrom(type)) {
contextParams.add(new ContextParameter(i, (Class<? extends Context>) type));
} else if (Request.class.isAssignableFrom(type)) {
requestParam = i;
}
}
}
}
Function<Object, Promise<Response, NeverThrowsException>, NeverThrowsException> resourceCreator;
if (Promise.class.equals(method.getReturnType())) {
resourceCreator = new PromisedResponseCreator();
} else if (Response.class.equals(method.getReturnType())) {
resourceCreator = new Function<Object, Promise<Response, NeverThrowsException>, NeverThrowsException>() {
@Override
public Promise<Response, NeverThrowsException> apply(Object o) {
return newResultPromise((Response) o);
}
};
} else {
resourceCreator = ResponseCreator.forType(method.getReturnType());
}
return new AnnotatedMethod(annotation.getSimpleName(), requestHandler, method, contextParams, requestParam, method.getParameterTypes().length, resourceCreator);
}
Aggregations