Search in sources :

Example 1 with OkaeriInjector

use of eu.okaeri.injector.OkaeriInjector in project okaeri-platform by OkaeriPoland.

the class RequestHandlerComponentResolver method getCall.

private Object[] getCall(@NonNull Map<Integer, Object[]> prefilledCallCache, @NonNull RequestHandlerMeta handlerMeta, @NonNull Context context, @NonNull Injector injector) {
    Object[] prefilledCall = prefilledCallCache.computeIfAbsent(Thread.currentThread().hashCode(), (hash) -> {
        OkaeriInjector okaeriInjector = (OkaeriInjector) injector;
        Parameter[] parameters = handlerMeta.getMethod().getParameters();
        return okaeriInjector.fillParameters(parameters, false);
    });
    int[] contextIndexes = handlerMeta.getContextIndexes();
    for (int contextIndex : contextIndexes) {
        prefilledCall[contextIndex] = context;
    }
    Map<Integer, PathParamMeta> pathParams = handlerMeta.getPathParams();
    for (PathParamMeta pathParam : pathParams.values()) {
        Object paramValue;
        String paramName = pathParam.getName();
        Class<?> paramType = pathParam.getType();
        try {
            paramValue = context.pathParamAsClass(paramName, paramType).get();
        } catch (Exception exception) {
            throw new RuntimeException("Failed resolving path parameter (" + paramName + ") of type " + paramType, exception);
        }
        prefilledCall[pathParam.getIndex()] = paramValue;
    }
    return prefilledCall;
}
Also used : OkaeriInjector(eu.okaeri.injector.OkaeriInjector) InvocationTargetException(java.lang.reflect.InvocationTargetException) PathParamMeta(eu.okaeri.platform.web.meta.PathParamMeta) Parameter(java.lang.reflect.Parameter)

Example 2 with OkaeriInjector

use of eu.okaeri.injector.OkaeriInjector in project okaeri-platform by OkaeriPoland.

the class InjectorSetupTask method execute.

@Override
public void execute(OkaeriPlatform platform) {
    OkaeriInjector injector = OkaeriInjector.create(true);
    platform.setInjector(injector);
    platform.registerInjectable("injector", injector);
}
Also used : OkaeriInjector(eu.okaeri.injector.OkaeriInjector)

Aggregations

OkaeriInjector (eu.okaeri.injector.OkaeriInjector)2 PathParamMeta (eu.okaeri.platform.web.meta.PathParamMeta)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Parameter (java.lang.reflect.Parameter)1