• beanFactory


    package com.byd.mes.util;
    
    
    import java.io.Serializable;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.beans.BeanUtils;
    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    
    import com.byd.mes.bussiness.bo.main.ShopOrderBO;
    import com.byd.mes.bussiness.service.activity.Activity;
    import com.byd.mes.util.cache.CacheManager;
    
    public class BeanFactory implements ApplicationContextAware {
    	private static final Log log = LogFactory.getLog(BeanFactory.class);
    	private static ApplicationContext applicationContext;
    	private static Map<String, String> systemParamters;
    	private static PropertyConfigurer propertyConfigurer;
    	public static final String INSTANCE_SINGLETON = "singleton";
    	public static final String INSTANCE_PROTOTYPE = "prototype";
    	private static Map clazzInstanceContext= new HashMap();
    	
    	public static final Map<String,ShopOrderBO> map=new HashMap<String,ShopOrderBO>();
    	
    	public static Object getBean(String beanName) {
    		return applicationContext.getBean(beanName);
    	}
    	
    	public static Activity getFunction(String className) {
    		return getFunction(className,BeanFactory.INSTANCE_SINGLETON);
    	}
    	public static Activity getFunction(String className,String instanceType) {
    		Object obj = getClazzIns(className,instanceType);
    		if(!(obj instanceof Activity)) throw new RuntimeException("必须实现com.byd.mes.bussiness.service.siteoperation.sfc.Function接口");
    		return (Activity) obj;
    	}
    	public static Object getClazzIns(String className,String instanceType) {
    		try{
    			if(StringUtils.equalsIgnoreCase(INSTANCE_SINGLETON,instanceType)){
    				Object fn = clazzInstanceContext.get(className);
    				if(fn == null){
    					fn = BeanUtils.instantiateClass(Class.forName(className));
    					clazzInstanceContext.put(className, fn);
    				}
    				return fn;
    			}
    			else if(StringUtils.equalsIgnoreCase(INSTANCE_PROTOTYPE,instanceType)){
    				return BeanUtils.instantiateClass(Class.forName(className)) ;
    			}			
    		}catch(Exception ex){
    			throw new RuntimeException("实例化类'"+className+"'失败 ->"+ex.getMessage(),ex);
    		}
    		throw new RuntimeException("实例化类'"+className+"'失败 ");
    	}
    	
    	@Override
    	public void setApplicationContext(ApplicationContext applicationContext)throws BeansException {
    		log.info("set applicationContext to static>>>"+applicationContext);
    		BeanFactory.applicationContext = applicationContext;
    	}
    
    	public static ApplicationContext getApplicationContext() {
    		return applicationContext;
    	}
    
    	public static Map<String, String> getSystemParamters() {
    		return (Map)propertyConfigurer.getProperties();
    	}
    
    	public void setPropertyConfigurer(PropertyConfigurer propertyConfigurer) {
    		BeanFactory.propertyConfigurer = propertyConfigurer;
    	}
    
    }
    
  • 相关阅读:
    软件测试拓展及视频教程
    LR性能测试课程及视频教程
    WEB自动化测试(UFT与Selenium)课程及视频教程
    WEB测试重点及视频教程
    web软件测试基础系统测试简化理论
    Python学习之路——day03
    Python文件常用的三个变量
    python的文件打开
    Python遍历字典
    Python学习之路——day02
  • 原文地址:https://www.cnblogs.com/qq1988627/p/6606894.html
Copyright © 2020-2023  润新知