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

📄 sb_hotelmanagertestclient1.java~1~

📁 用j2ee开发的一个旅店管理系统
💻 JAVA~1~
字号:
package com.xc.hotelmanager.hotel.control.session.test;import com.xc.hotelmanager.hotel.control.session.*;import javax.naming.*;import java.util.Properties;import javax.rmi.PortableRemoteObject;import com.xc.hotelmanager.hotel.model.Reservation;import java.util.Collection;import com.xc.hotelmanager.hotel.control.*;import com.xc.hotelmanager.hotel.control.EjbGetter;public class SB_hotelmanagerTestClient1 extends Object {  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 SB_hotelmanagerHome sB_hotelmanagerHome = null;  private SB_hotelmanager sB_hotelmanager = null;  //Construct the EJB test client  public SB_hotelmanagerTestClient1() {    initialize();  }  public void initialize() {    long startTime = 0;    if (logging) {      log("Initializing bean access.");      startTime = System.currentTimeMillis();    }    try {      //get naming context      Context context = getInitialContext();      //look up jndi name      Object ref = context.lookup("SB_hotelmanager");      //look up jndi name and cast to Home interface      sB_hotelmanagerHome = (SB_hotelmanagerHome) PortableRemoteObject.narrow(ref, SB_hotelmanagerHome.class);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded initializing bean access through Home interface.");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed initializing bean access.");      }      e.printStackTrace();    }  }  private Context getInitialContext() throws Exception {    String url = "t3://jsj207-75:7001";    String user = null;    String password = null;    Properties properties = null;    try {      properties = new Properties();      properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");      properties.put(Context.PROVIDER_URL, url);      if (user != null) {        properties.put(Context.SECURITY_PRINCIPAL, user);        properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);      }      return new InitialContext(properties);    }    catch(Exception e) {      log("Unable to connect to WebLogic server at " + url);      log("Please make sure that the server is running.");      throw e;    }  }  //----------------------------------------------------------------------------  // Methods that use Home interface methods to generate a Remote interface reference  //----------------------------------------------------------------------------  public SB_hotelmanager create() {    long startTime = 0;    if (logging) {      log("Calling create()");      startTime = System.currentTimeMillis();    }    try {      sB_hotelmanager = sB_hotelmanagerHome.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(): " + sB_hotelmanager + ".");    }    return sB_hotelmanager;  }  //----------------------------------------------------------------------------  // Methods that use Remote interface methods to access data through the bean  //----------------------------------------------------------------------------  public String FindEmptyRoom(String type) {    String returnValue = "";    if (sB_hotelmanager == null) {      System.out.println("Error in FindEmptyRoom(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling FindEmptyRoom(" + type + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_hotelmanager.FindEmptyRoom(type);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: FindEmptyRoom(" + type + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: FindEmptyRoom(" + type + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from FindEmptyRoom(" + type + "): " + returnValue + ".");    }    return returnValue;  }  public String ResRoom(Reservation res, int num, String type) {    String returnValue = "";    if (sB_hotelmanager == null) {      System.out.println("Error in ResRoom(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling ResRoom(" + res + ", " + num + ", " + type + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_hotelmanager.ResRoom(res, num, type);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: ResRoom(" + res + ", " + num + ", " + type + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: ResRoom(" + res + ", " + num + ", " + type + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from ResRoom(" + res + ", " + num + ", " + type + "): " + returnValue + ".");    }    return returnValue;  }  public Collection getAllRoom() {    Collection returnValue = null;    if (sB_hotelmanager == null) {      System.out.println("Error in getAllRoom(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getAllRoom()");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_hotelmanager.getAllRoom();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getAllRoom()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getAllRoom()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getAllRoom(): " + returnValue + ".");    }    return returnValue;  }  public Collection getAllRoomPrice() {    Collection returnValue = null;    if (sB_hotelmanager == null) {      System.out.println("Error in getAllRoomPrice(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getAllRoomPrice()");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_hotelmanager.getAllRoomPrice();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getAllRoomPrice()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getAllRoomPrice()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getAllRoomPrice(): " + returnValue + ".");    }    return returnValue;  }  public void CancleRes(int i, String id) {    if (sB_hotelmanager == null) {      System.out.println("Error in CancleRes(): " + ERROR_NULL_REMOTE);      return ;    }    long startTime = 0;    if (logging) {      log("Calling CancleRes(" + i + ", " + id + ")");      startTime = System.currentTimeMillis();    }    try {      sB_hotelmanager.CancleRes(i, id);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: CancleRes(" + i + ", " + id + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: CancleRes(" + i + ", " + id + ")");      }      e.printStackTrace();    }  }  public String getRoomByType(String type) {    String returnValue = "";    if (sB_hotelmanager == null) {      System.out.println("Error in getRoomByType(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getRoomByType(" + type + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_hotelmanager.getRoomByType(type);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getRoomByType(" + type + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getRoomByType(" + type + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getRoomByType(" + type + "): " + returnValue + ".");    }    return returnValue;  }  //----------------------------------------------------------------------------  // 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) {    SB_hotelmanagerTestClient1 client = new SB_hotelmanagerTestClient1();     HotelManager manager=HotelManager.getInstance();  }}

⌨️ 快捷键说明

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