/* 

	Purpose:
		
	Description:
		
	History:
		2014/4/21, Dennis

Copyright (C) 2010 Potix Corporation. All Rights Reserved.

*/
package org.zkoss.zss.jsf.ui.impl;

/**
 * context to hold object-holder 
 * @author Dennis
 * @since 3.5.0
 */
public abstract class ObjectHolderContext {

	static private ThreadLocal<ObjectHolder> holder = new ThreadLocal<ObjectHolder>();
	
	public static ObjectHolderContext setHolder(ObjectHolder pool){
		ObjectHolderContext old = ObjectHolderContext.holder.get();
		ObjectHolderContext.holder.set(pool);
		return old;
	}
	public static boolean hasHolder(){
		return ObjectHolderContext.holder.get()!=null;
	}
	public static ObjectHolderContext removeHolder(){
		ObjectHolderContext old = ObjectHolderContext.holder.get();
		ObjectHolderContext.holder.remove();
		return old;
	}
	
	public static Object getObjectIfAny(String desktopId,String objId){
		ObjectHolder holder = ObjectHolderContext.holder.get();
		if(holder==null)
			return null;
		return holder.get(desktopId+"."+objId);
	}
	
	public static void putObject(String desktopId,String objId,Object object){
		ObjectHolder holder = ObjectHolderContext.holder.get();
		if(holder!=null){
			holder.put(desktopId+"."+objId,object);
		}
	}
}
