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

com.zyy.common.factory.HandleFactory Maven / Gradle / Ivy

package com.zyy.common.factory;

import com.zyy.common.model.TemplateModel;
import com.zyy.common.service.HandleService;
import com.zyy.common.util.TokenModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;

import javax.annotation.PostConstruct;
import java.util.Map;

@Slf4j
@Data
@AllArgsConstructor
public class HandleFactory {

    private final ApplicationContext applicationContext;
    private static ApplicationContext context;

    @PostConstruct
    public void init() {
        context = applicationContext;
    }

    public static HandleService getHandle(String type) {
        Map beansOfType = context.getBeansOfType(HandleService.class);
        for (String key : beansOfType.keySet()) {
            if (key.equals(type)) return beansOfType.get(key);
        }
        return null;
    }

    public static void execute(String type, TemplateModel model, Object object, TokenModel tokenModel) {
        HandleService service = getHandle(type);
        if (service != null) {
            service.handleRun(model, object, tokenModel);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy