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

com.jquicker.context.bean.BeanManager Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.jquicker.context.bean;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author OL
 */
public abstract class BeanManager {

	protected static Map> beanContainer = new ConcurrentHashMap>();

	public static void putBean(String name, Object object) {
		Bean bean = new Bean();
		bean.setObject(object);
		bean.setBeanName(name);
		if(beanContainer.putIfAbsent(name, bean) != null) {
			throw new RuntimeException("ambiguous");
		}
	}
	
	public static void addProxy(String name, Object proxy) {
		Bean bean = beanContainer.get(name);
		if(bean != null){
			bean.setProxy(proxy);
		}
	}
	
	/**
	 * 获取对象实体
	 * 
	 * @param clz
	 * @return
	 * @author OL
	 */
	@SuppressWarnings("unchecked")
	public static  T getBean(String beanName) {
		Bean bean = beanContainer.get(beanName);
		return bean == null ? null : (T) bean.getBean();
	}
	
	public static Map> getBeans() {
		return beanContainer;
	}
}