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

📄 test.java

📁 精通Jboss——Ejb和Web Services开发精解的随书源代码
💻 JAVA
字号:
/**
 * 
 * Test.java
 * 
 * Created on 2003-8-15 12:21:48
 * 
 */
package com.liuyang.jboss.sessionbean.calculator;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import com.liuyang.jboss.sessionbean.calculator.ejb.Calculator;
import com.liuyang.jboss.sessionbean.calculator.ejb.CalculatorHome;

/**
 * @author
 * <a href="mailto:jdcyang@yahoo.com.cn">刘洋</a>
 */
public class Test {
	public static void main(String[] args){
		Test test = new Test();
		try {
			test.test();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void test() throws Exception{
		Hashtable env = new Hashtable();
		env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
		env.put(Context.PROVIDER_URL,"localhost");
		Context initContext = new InitialContext(env);		
		try {
			Object ref  = initContext.lookup("CalculatorHomeRemote");
			CalculatorHome home = (CalculatorHome)
			PortableRemoteObject.narrow(ref, CalculatorHome.class);
			Calculator calculator = home.create();
			calculator.add(100);
			calculator.add(200);
			//calculator.divideBy(0);
			System.out.println(calculator.getValue());
		}
		finally {
		  if (initContext != null) {
			initContext.close();
		  }
		}	
		
	}
}

⌨️ 快捷键说明

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