All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.yoojia.halo.actions.ActionManager Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.github.yoojia.halo.actions;

import com.github.yoojia.halo.supports.CachedManager;
import com.github.yoojia.halo.utils.Scanner;
import com.github.yoojia.halo.utils.URIs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.util.List;

/**
 * @author Yoojia.Chen ([email protected])
 */
final class ActionManager extends CachedManager implements Scanner.PrepareHandler {

    private final Logger mLogger = LoggerFactory.getLogger(ActionManager.class);

    ActionProcessor findMatched(String method, List urlResource){
        for (ActionProcessor p : getProcessors()){
            if(p.isMatchedMethod(method) && p.isMatchedResource(urlResource)){
                return p;
            }
        }
        return null;
    }

    @Override
    protected void ordering(List from, List to) {
        to.addAll(mWeightOrdering.sortedCopy(from));
        mLogger.trace("HTTP Action processors: {}", to.size());
    }

    @Override
    public void prepare(String root, Handle config, Class hostType, Method invoker) {
        final String methodName = config.method().toUpperCase(); // !! UpperCase
        final String uri = URIs.combined(root, config.path());
        final ActionProcessor processor = new ActionProcessor(uri, methodName, invoker, hostType, this);
        mLogger.trace("Config: Method={}, Uri={}", methodName, uri);
        addProcessor(processor);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy