ejbhomefactory.java

来自「一个netstore的完整代码,他使用了j2ee和webservice技术,并使」· Java 代码 · 共 50 行

JAVA
50
字号
package netstore.service.ejb;

import java.io.InputStream;
import java.io.IOException;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;

/**
 * This class implements the EJBHomeFactory pattern. It performs JNDI
 * lookups to locate EJB homes and caches the results for subsequent calls.
 */
public class EJBHomeFactory {
  private Map homes;
  private static EJBHomeFactory singleton;
  private InitialContext ctx;

   private EJBHomeFactory(  ) throws NamingException {
    homes = Collections.synchronizedMap(new HashMap(  ));
    ctx = new InitialContext();
  }


  /**
   * Get the Singleton instance of the class.
   */
  public static EJBHomeFactory getInstance(  ) throws NamingException {
    if (singleton == null) {
      singleton = new EJBHomeFactory(  );
    }
    return singleton;
  }

  /**
   * Specify the JNDI name and class for the desired home interface.
   */
  public EJBHome lookupHome(String jndiName, Class homeClass)
   throws NamingException {
    EJBHome home = (EJBHome)homes.get(homeClass);
    if (home == null) {
      home = (EJBHome)PortableRemoteObject.narrow(ctx.lookup(
        jndiName), homeClass);
      // Cache the home for repeated use
      homes.put(homeClass, home);
    }
    return home;
  }
}

⌨️ 快捷键说明

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