package com.ld.igds.io;
|
|
import org.springframework.beans.BeansException;
|
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 接口Api所有协议的协议类,根据不同的协议配置调用不同的协议实现
|
*
|
* @author jiazx
|
*/
|
@Component(RemoteManager.BEAN_ID)
|
public class RemoteManager implements ApplicationContextAware {
|
|
public static final String BEAN_ID = "core.remoteManager";
|
|
/**
|
* 用于存放所有RemoteGrainService 接口的实现类
|
*/
|
public static Map<String, RemoteGrainService> remoteGrainMap = new HashMap<>();
|
|
public static Map<String, RemoteCommonService> remoteCommonMap = new HashMap<>();
|
|
public static Map<String, RemoteControlService> remoteControlMap = new HashMap<>();
|
|
public static Map<String, RemoteGasService> remoteGasMap = new HashMap<>();
|
|
public static Map<String, RemotePestService> remotePestMap = new HashMap<>();
|
|
@Override
|
public void setApplicationContext(ApplicationContext applicationContext)
|
throws BeansException {
|
Map<String, RemoteGrainService> grainMap = applicationContext
|
.getBeansOfType(RemoteGrainService.class);
|
|
for (String key : grainMap.keySet()) {
|
remoteGrainMap.put(grainMap.get(key).getProtocol(),
|
grainMap.get(key));
|
}
|
|
Map<String, RemoteCommonService> commonMap = applicationContext
|
.getBeansOfType(RemoteCommonService.class);
|
for (String key : commonMap.keySet()) {
|
remoteCommonMap.put(commonMap.get(key).getProtocol(),
|
commonMap.get(key));
|
}
|
|
Map<String, RemoteControlService> controlMap = applicationContext
|
.getBeansOfType(RemoteControlService.class);
|
|
for (String key : controlMap.keySet()) {
|
remoteControlMap.put(controlMap.get(key).getProtocol(),
|
controlMap.get(key));
|
}
|
|
Map<String, RemoteGasService> gasMap = applicationContext
|
.getBeansOfType(RemoteGasService.class);
|
for (String key : gasMap.keySet()) {
|
remoteGasMap.put(gasMap.get(key).getProtocol(), gasMap.get(key));
|
}
|
|
Map<String, RemotePestService> pestMap = applicationContext
|
.getBeansOfType(RemotePestService.class);
|
for (String key : pestMap.keySet()) {
|
remotePestMap.put(pestMap.get(key).getProtocol(), pestMap.get(key));
|
}
|
|
}
|
|
/**
|
* 根据协议获取协议实现接口
|
*
|
* @param protocol
|
* @return
|
*/
|
public RemoteGrainService getRemoteGrainService(String protocol) {
|
return remoteGrainMap.get(protocol);
|
}
|
|
/**
|
* 根据协议获取协议实现接口
|
*
|
* @param protocol
|
* @return
|
*/
|
public RemoteCommonService getRemoteCommonService(String protocol) {
|
return remoteCommonMap.get(protocol);
|
}
|
|
/**
|
* 根据协议获取协议实现接口
|
*
|
* @param protocol
|
* @return
|
*/
|
public RemoteGasService getRemoteGasService(String protocol) {
|
return remoteGasMap.get(protocol);
|
}
|
|
/**
|
* 根据协议获取协议实现接口
|
*
|
* @param protocol
|
* @return
|
*/
|
public RemoteControlService getRemoteControlService(String protocol) {
|
return remoteControlMap.get(protocol);
|
}
|
|
/**
|
* 根据协议获取协议实现接口
|
*
|
* @param protocol
|
* @return
|
*/
|
public RemotePestService getRemotePestService(String protocol) {
|
return remotePestMap.get(protocol);
|
}
|
|
}
|