EJBHomeFactory.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package com.borland.training.meetings.sessions;
- import javax.naming.*;
- import java.util.*;
- import javax.ejb.*;
- import com.borland.training.meetings.entities.*;
- import com.borland.training.meetings.sessions.*;
- public class EJBHomeFactory {
- private static EJBHomeFactory instance = null;
- private Context initialContext;
- private Map ejbHomes;
- private EJBHomeFactory() throws NamingException {
- initialContext = new InitialContext();
- ejbHomes = Collections.synchronizedMap(new HashMap());
- }
- public static EJBHomeFactory getInstance() throws NamingException {
- if(instance == null) {
- instance = new EJBHomeFactory();
- }
- return instance;
- }
- public EJBLocalHome lookupByLocalEJBReference(String ejbReferenceComponent)
- throws NamingException {
- java.lang.Object home = ejbHomes.get(ejbReferenceComponent);
- if(home == null) {
- home = initialContext.lookup("java:comp/env/ejb/" + ejbReferenceComponent);
- ejbHomes.put(ejbReferenceComponent, home);
- }
- return (EJBLocalHome) home;
- }
- public EJBHome lookupByRemoteEJBReference(String ejbReferenceComponent, Class homeClass)
- throws NamingException {
- java.lang.Object home = ejbHomes.get(ejbReferenceComponent);
- if(home == null) {
- java.lang.Object obj =
- initialContext.lookup("java:comp/env/ejb/" + ejbReferenceComponent);
- home = javax.rmi.PortableRemoteObject.narrow(obj, homeClass);
- ejbHomes.put(ejbReferenceComponent, home);
- }
- return (EJBHome) home;
- }
- }