荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: RichardQiu (Richard Qiu), 信区: Java
标  题: 用JB5实现j2ee tutorial中的converter范例(4)
发信站: 荔园晨风BBS站 (Wed Oct 10 17:51:58 2001), 转信

四、ConverterClient.java

package converterapp;

import javax.naming.*;
import javax.rmi.PortableRemoteObject;

/**
 * Title:        A EJB SAMPLE
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      VISTA.COM
 * @author George Hill
 * @version 1.0
 */

public class ConverterClient {
  private ConverterHome converterHome = null;

  /**Construct the EJB test client*/
  public ConverterClient() {
    try {
      //get naming context
      Context ctx = new InitialContext();

      //look up jndi name
      Object ref = ctx.lookup("Converter");

      //cast to Home interface
      converterHome = (ConverterHome) PortableRemoteObject.narrow(ref,
        ConverterHome.class);

      Converter currencyConverter = converterHome.create();
      double amount = currencyConverter.dollarToYen(100.00);
      System.out.println(String.valueOf(amount));
      amount = currencyConverter.yenToEuro(100.00);
      System.out.println(String.valueOf(amount));
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  //----------------------------------------------------------------------------
  // Utility Methods
  //----------------------------------------------------------------------------

  public ConverterHome getHome() {
    return converterHome;
  }
  /**Main method*/

  public static void main(String[] args) {
    ConverterClient client = new ConverterClient();
    // Use the getHome() method of the client object to call Home interface
    // methods that will return a Remote interface reference.  Then
    // use that Remote interface reference to access the EJB.
  }
}

--
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.32.16]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店