📄 ejbhomefactory.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 + -