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

📄 firsttestclient1.java

📁 用java编写的绘制手机图片的程序
💻 JAVA
字号:
package paint;import javax.naming.*;import javax.rmi.PortableRemoteObject;/** * Title:        ejbserver * Description:  this is first ejb server written by zhengjunfeng * Copyright:    Copyright (c) 2002 * Company:      buaa * @author zhengjunfeng * @version 1.0 */public class firstTestClient1 {  private static final String ERROR_NULL_REMOTE = "Remote interface reference is null.  It must be created by calling one of the Home interface methods first.";  private static final int MAX_OUTPUT_LINE_LENGTH = 100;  private boolean logging = true;  private firstHome firstHomeObject = null;  private first firstObject = null;  /**Construct the EJB test client*/  public firstTestClient1() {    long startTime = 0;    if (logging) {      log("Initializing bean access.");      startTime = System.currentTimeMillis();    }    try {      //get naming context      Context ctx = new InitialContext();      //look up jndi name      Object ref = ctx.lookup("first");      //cast to Home interface      firstHomeObject = (firstHome) PortableRemoteObject.narrow(ref, firstHome.class);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded initializing bean access.");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed initializing bean access.");      }      e.printStackTrace();    }  }  //----------------------------------------------------------------------------  // Methods that use Home interface methods to generate a Remote interface reference  //----------------------------------------------------------------------------  public first create() {    long startTime = 0;    if (logging) {      log("Calling create()");      startTime = System.currentTimeMillis();    }    try {      firstObject = firstHomeObject.create();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: create()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: create()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from create(): " + firstObject + ".");    }    return firstObject;  }  //----------------------------------------------------------------------------  // Methods that use Remote interface methods to access data through the bean  //----------------------------------------------------------------------------  public String getfirststring() {    String returnValue = "";    if (firstObject == null) {      System.out.println("Error in getfirststring(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getfirststring()");      startTime = System.currentTimeMillis();    }    try {      returnValue = firstObject.getfirststring();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getfirststring()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getfirststring()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getfirststring(): " + returnValue + ".");    }    return returnValue;  }  public void testRemoteCallsWithDefaultArguments() {    if (firstObject == null) {      System.out.println("Error in testRemoteCallsWithDefaultArguments(): " + ERROR_NULL_REMOTE);      return ;    }    getfirststring();  }  //----------------------------------------------------------------------------  // Utility Methods  //----------------------------------------------------------------------------  private void log(String message) {    if (message == null) {      System.out.println("-- null");      return ;    }    if (message.length() > MAX_OUTPUT_LINE_LENGTH) {      System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");    }    else {      System.out.println("-- " + message);    }  }  /**Main method*/  public static void main(String[] args) {    firstTestClient1 client = new firstTestClient1();    // Use the client object to call one of the Home interface wrappers    // above, to create a Remote interface reference to the bean.    // If the return value is of the Remote interface type, you can use it    // to access the remote interface methods.  You can also just use the    // client object to call the Remote interface wrappers.    client.create();    System.out.println(client.getfirststring());  }}

⌨️ 快捷键说明

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