package com.ld.igds.quantity.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(QuantityRemoteManager.BEAN_ID)
|
public class QuantityRemoteManager implements ApplicationContextAware {
|
|
public static final String BEAN_ID = "quantity.remoteManager";
|
|
public static Map<String, RemoteQuantityService> remoteQuantityMap = new HashMap<>();
|
|
@Override
|
public void setApplicationContext(ApplicationContext applicationContext)
|
throws BeansException {
|
|
Map<String, RemoteQuantityService> quantityMap = applicationContext
|
.getBeansOfType(RemoteQuantityService.class);
|
for (String key : quantityMap.keySet()) {
|
remoteQuantityMap.put(quantityMap.get(key).getProtocol(),
|
quantityMap.get(key));
|
}
|
|
}
|
|
/**
|
* 根据协议获取实现
|
*
|
* @param protocol
|
* @return
|
*/
|
public RemoteQuantityService getRemoteQuantityService(String protocol) {
|
return remoteQuantityMap.get(protocol);
|
}
|
|
}
|