package com.ruoyi.system.core;

import com.ruoyi.system.core.annotate.Execute;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class ClientExecuteFactory {

    public Map<String, ClientExecute> map = new HashMap<>();

    public ClientExecuteFactory(ApplicationContext applicationContext) {
        Map<String, ClientExecute> beans = applicationContext.getBeansOfType(ClientExecute.class);
        for (String key : beans.keySet()) {
            ClientExecute execute = beans.get(key);
            if (!execute.getClass().isAnnotationPresent(Execute.class)) {
                continue;
            } else {
                map.put(execute.getClass().getAnnotation(Execute.class).type(), execute);
            }
        }
    }

    public ClientExecute getClientExecute(String type) {
        return map.get(type);
    }
}
