⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ejbhomefactory.java

📁 这是一个工作流管理的后端EJB实现
💻 JAVA
字号:
package com.coshare.joyteam.projectMgr.businessDelegate;

import java.util.HashMap;
import java.util.Map;
import java.util.Collections;

import javax.ejb.EJBHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class EJBHomeFactory
{
	private Map ejbHomes;
	
	private static EJBHomeFactory ejbHomeFactoryInstance;
	
	private Context context;
	
	private EJBHomeFactory() throws NamingException
	{
		context = new InitialContext();
		
		this.ejbHomes = Collections.synchronizedMap(new HashMap());
	}
	
	public static EJBHomeFactory getFactory() throws HomeFactoryException
	{
		try
		{
			if(EJBHomeFactory.ejbHomeFactoryInstance == null)
			{
				EJBHomeFactory.ejbHomeFactoryInstance = new EJBHomeFactory();
			}	
		}catch(NamingException e)
		{
			throw new HomeFactoryException(e);
		}
		
		return EJBHomeFactory.ejbHomeFactoryInstance;
	}
	
	public EJBHome lookUpEJBHome(Class homeClass) throws HomeFactoryException
	{
		EJBHome ejbHome;
		
		ejbHome = (EJBHome)this.ejbHomes.get(homeClass);
		
		try
		{
			if(ejbHome == null)
			{
				ejbHome = (EJBHome)PortableRemoteObject.narrow(context.lookup(homeClass.getName()), homeClass);
				this.ejbHomes.put(homeClass, ejbHome);
			}
		}catch(NamingException e)
		{
			throw new HomeFactoryException(e);
		}
		
		return ejbHome;
	}
	
	public EJBHome lookUpEJBHome(Class homeClass, String jndiName) throws HomeFactoryException
	{
		EJBHome ejbHome;
		
		ejbHome = (EJBHome)this.ejbHomes.get(homeClass);
		
		try
		{
			if(ejbHome == null)
			{
				ejbHome = (EJBHome)PortableRemoteObject.narrow(context.lookup(jndiName), homeClass);
				this.ejbHomes.put(homeClass, ejbHome);
			}
		}catch(NamingException e)
		{
			throw new HomeFactoryException(e);
		}
		
		return ejbHome;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -