package com.inspect.metadata.montdatamqhandle;

import com.inspect.metadata.montdatamqhandle.service.IBasedataMontDataHandleService;

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

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service("montBeanRegister")
public class RegisterMontDataHandelBean implements InitializingBean, ApplicationContextAware {
    private final Map<String, IBasedataMontDataHandleService> serviceImplMap = new HashMap<>();
    private ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void afterPropertiesSet() throws Exception {
        Map<String, IBasedataMontDataHandleService> beanMap = this.applicationContext.getBeansOfType(IBasedataMontDataHandleService.class);
        if (!beanMap.isEmpty()) {
            for (Entry<String, IBasedataMontDataHandleService> stringIBasedataMontDataHandleServiceEntry : beanMap.entrySet()) {
                Entry entry = stringIBasedataMontDataHandleServiceEntry;
                String beanName = (String) entry.getKey();
                IBasedataMontDataHandleService serviceImpl = (IBasedataMontDataHandleService) entry.getValue();
                this.serviceImplMap.put(beanName, serviceImpl);
            }
        }

    }

    public IBasedataMontDataHandleService getServiceImpl(String name) {
        return this.serviceImplMap.get(name);
    }
}
