package CoreFS.SA01;

import java.util.HashMap;

import CoreFS.SA04.CoreDBManager;
import CoreFS.SA04.CoreDBProxy;
import CoreFS.SA06.CoreICommunicationService;

import CoreFS.SD03.CoreFileLog;
import CoreFS.SD03.CoreLogAdapter;
import CoreFS.SD03.CoreLogFactory;

public class CoreIComponent { 
	/**
	 * @desc :用于从Spring中获取dao对象 进行对DB的操作
	 * @create :091128
	 * @modify :091128
	 * @return
	 */

	public CoreIComponent() {
		// beanfactory = new CoreBeanFacotry();
		// logAdapter = new CoreLogAdapter();
		// logger = CoreLogFactory.getLogger(getClass());
		// CoreLogAdapter
	}

	public static CoreLogAdapter logAdapter;
	static {
		beanfactory = new CoreBeanFacotry();
		logAdapter = new CoreLogAdapter();
	}
	private static HashMap<String, CoreDBProxy> DBProxyMap;// 存放dao层的操作代理
	public CoreDBProxy dbproxy = null;// dao 的代理
	public static CoreBeanFacotry beanfactory;
	public static final int XFIRE_SERVICE = 2;
	public static final int HESSIAN_SERVICE = 1;

	// protected CoreFileLog logger = logAdapter.filelogger;

	private CoreDBManager dao = null;	
	/**
	 * @desc
	 * @param daoname
	 * @return
	 */
	public CoreDBManager getDao(String daoname) {
		if (DBProxyMap == null) {
			DBProxyMap = new HashMap();
		}
		dbproxy = DBProxyMap.get(daoname);
		if (dbproxy == null) {
			dbproxy = (CoreDBProxy) beanfactory.getDaoBean(
					"classpath:springjndiConfig.xml", daoname);
			DBProxyMap.put(daoname, dbproxy);
		}
		dao = new CoreDBManager(dbproxy);		
		return dao;
	}

	/**
	 * @desc :用于从Spring中获取Hession服务对象 以进行对客户端服务的发布
	 * @create :091128
	 * @modify :091128
	 * @return
	 */
	public static CoreICommunicationService communicationService = null;

//	public CoreICommunicationService getHessionService() {
//		// TODO Auto-generated method stub
//		if (communicationService == null) {
//			communicationService = (CoreICommunicationService) beanfactory
//					.getBean("remoting-client.xml", "HessionServiceClient");
//		}
//		return communicationService;
//	}


	public CoreICommunicationService getRPCService(int key,String ClientName) {
		if (communicationService == null) {
			switch (key) {
			case HESSIAN_SERVICE:
				communicationService = (CoreICommunicationService) beanfactory
				.getBean("remoting-client.xml", ClientName);
				break;
			case XFIRE_SERVICE:
				communicationService = (CoreICommunicationService) beanfactory
				.getBean("client.xml", "CoreXFireServiceProxyBean");
				break;
			default:
				break;
			}
		}
		return communicationService;

	}	
	
}
