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

📄 helloclient.java

📁 《精通RMI:Java与EJB企业级应用开发》书籍的源代码. 本书是讲述RMI技术的经典著作
💻 JAVA
字号:
/*
 * Copyright 1999 by dreamBean Software,
 * All rights reserved.
 */
package masteringrmi.helloejb.client;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;

import masteringrmi.helloejb.interfaces.HelloHome;
import masteringrmi.helloejb.interfaces.HelloWorld;

/**
 *   This is an application that will talk to an EJB component.
 *
 *   It will use JNDI to find the component, then the home will be used instantiate it, and finally call it.
 *      
 *   @see HelloWorld
 *   @author Rickard 謆erg (rickard@dreambean.com)
 */
public class HelloClient
{
   // Static  -------------------------------------------------------
	public static void main(String[] args)
      throws Exception
   {
      new HelloClient();
   }
	
   // Constructors --------------------------------------------------
   public HelloClient()
      throws Exception
   {
      // Find home for HelloEJB
      HelloHome home;
      try
      {
         Context ctx = new InitialContext();
         home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("HelloEJB"), HelloHome.class);
         ctx.close();
      } catch (NamingException e)
      {
         System.out.println("Could not lookup HelloEJB home");
         throw e;
      }
      
      // Create HelloEJB
      HelloWorld helloEJB;
      try
      {
         helloEJB = home.create();
      } catch (CreateException e)
      {
         System.out.println("Could not create HelloEJB");
         throw e;
      }
      
      // Get greeting
      String greeting;
      try
      {
         greeting = helloEJB.helloWorld("World");
      } catch (RemoteException e)
      {
         System.out.println("Could not get greeting from HelloEJB");
         throw e;
      } finally
      {
         helloEJB.remove();
      }
      
      // Print greeting
      System.out.println(greeting);
   }
}

⌨️ 快捷键说明

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