ejbhomefactory.java

来自「这是一个工作流管理的后端EJB实现」· Java 代码 · 共 86 行

JAVA
86
字号
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 + =
减小字号Ctrl + -
显示快捷键?