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

📄 ejbgetter.java

📁 j2ee源码
💻 JAVA
字号:
/*
 * Created on 2003/12/6
 */
package com.leeman.common.util;

import javax.ejb.*;
import java.util.*;
import javax.naming.*;

/**
 * @author dennis
 */
public class EjbGetter {
	
	/**
	 * Get the EJB Home Interface
	 * @param service_jndiname JNDI Services Name of EJB
	 * @param homeInterface Home Interface Class
	 * @return EJB Home Interface
	 * @throws NamingException
	 */
	public static EJBHome getEJBHome(String service_jndiname, Class homeInterface) throws NamingException
	{
		Properties env = System.getProperties();
		env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
	
		/* 
		 * Use com/ibm/ejs/ns/jndi/CNInitialContextFactory.properties property file instead of providing the PROVIDER_URL
		 * com.ibm.CORBA.BootstrapHost=your.server.name
		 * com.ibm.CORBA.BootstrapPort=900
		 */
		//env.put(Context.PROVIDER_URL , PROTOCOL + APPSERVER_URL + APPSERVER_PORT);
	
		Context ic = new InitialContext(env);
		EJBHome ejbHome = (EJBHome)javax.rmi.PortableRemoteObject.narrow(
					ic.lookup(service_jndiname), homeInterface);
		return ejbHome;
	}

	/**
	 * Get the EJB Local Home Interface
	 * @param ref_name
	 * @return
	 * @throws NamingException
	 */
	public static EJBLocalHome getEJBLocalHome(String ref_name) throws NamingException
	{
//		Context ic = new InitialContext();
//		EJBLocalHome ejbLocalHome = (EJBLocalHome)ic.lookup(service_jndiname);
//		return ejbLocalHome;

		java.util.Properties properties = new java.util.Properties();
		properties.put(javax.naming.Context.PROVIDER_URL, "iiop:///");
		properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
		javax.naming.InitialContext initialContext = new javax.naming.InitialContext(properties);
		
		Object objHome = initialContext.lookup("java:comp/env/"+ref_name);
		EJBLocalHome ejbLocalHome = (EJBLocalHome)objHome;
		
		return ejbLocalHome;
	}
}

⌨️ 快捷键说明

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