package com.cim.idm.wmsextend.generic;


import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.esb.GenericSender;
import com.cim.idm.framework.transaction.TxDataSourceManager;
import com.cim.idm.wmsextend.generic.master.ConstantMap;
import com.cim.idm.wmsextend.generic.master.ErrorDefMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class GenericServiceProxy implements ApplicationContextAware {
	private static Log log = LogFactory.getLog(GenericServiceProxy.class);
	private static ApplicationContext ac;
	
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		// TODO Auto-generated method stub
		log.debug("Success Get AC");
		ac = arg0;
	}

	public static ApplicationContext getApplicationContext()
	{
		return ac;
	}
	
	public static TxDataSourceManager getTxDataSourceManager()
	{
		return (TxDataSourceManager)IDMFrameServiceProxy.getApplicationContext().getBean(TxDataSourceManager.class);
	}

	public static ConstantMap getConstantMap()
	{
		try
		{ return (ConstantMap) ac.getBean("ntConstantMap");
		
		}catch(Exception e)
		{
			return (ConstantMap)IDMFrameServiceProxy.getApplicationContext().getBean(ConstantMap.class);
		}
	}
	
	public static ErrorDefMap getErrorDefMap()
	{
		
		return (ErrorDefMap)IDMFrameServiceProxy.getApplicationContext().getBean(ErrorDefMap.class);	
	}
	
	public static GenericSender getGenericSender(String senderName)
	{
		
		if(log.isInfoEnabled()){
			log.info("senderName = " + senderName);
		}
		
		return (GenericSender) IDMFrameServiceProxy.getApplicationContext().getBean(senderName);
	}
	
//	public static JobTimer getJobTimer()
//	{
//		return (JobTimer)BundleUtil.getBundleServiceClass(JobTimer.class);	
//	}
}
