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

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

package com.github.yoojia.next.actions;

import com.github.yoojia.next.lang.Sorts;
import com.github.yoojia.next.supports.CachedManager;
import com.github.yoojia.next.utils.ClassFinder;
import com.github.yoojia.next.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 ClassFinder.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
    @SuppressWarnings("unchecked")
    protected void ordering(List from, List to) {
        to.addAll(new Sorts(mWeightOrdering).sortedCopy(from));
        if (mLogger.isTraceEnabled()){
            for (ActionProcessor p : to) {
                mLogger.trace("{}", p);
            }
        }
        mLogger.trace("HTTP Action processors: {}", to.size());
    }

    @Override
    public void prepare(String root, Handle config, Class hostType, Method invoker) {
        final String method = config.method().toUpperCase(); // !! UpperCase
        final String uri = URIs.connect(root, config.path());
        final ActionProcessor processor = new ActionProcessor(uri, method, invoker, hostType, this);
        addProcessor(processor);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy