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

📄 sb_customermanagertestclient1.java

📁 用j2ee开发的一个旅店管理系统
💻 JAVA
字号:
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.Customer;import java.util.Collection;public class SB_CustomerManagerTestClient1 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_CustomerManagerHome sB_CustomerManagerHome = null;  private SB_CustomerManager sB_CustomerManager = null;  //Construct the EJB test client  public SB_CustomerManagerTestClient1() {    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_CustomerManager");      //look up jndi name and cast to Home interface      sB_CustomerManagerHome = (SB_CustomerManagerHome) PortableRemoteObject.narrow(ref, SB_CustomerManagerHome.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://DGYNMR1X: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_CustomerManager create() {    long startTime = 0;    if (logging) {      log("Calling create()");      startTime = System.currentTimeMillis();    }    try {      sB_CustomerManager = sB_CustomerManagerHome.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_CustomerManager + ".");    }    return sB_CustomerManager;  }  //----------------------------------------------------------------------------  // Methods that use Remote interface methods to access data through the bean  //----------------------------------------------------------------------------  public Customer loadCustomer(String cid) {    Customer returnValue = null;    if (sB_CustomerManager == null) {      System.out.println("Error in loadCustomer(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling loadCustomer(" + cid + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_CustomerManager.loadCustomer(cid);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: loadCustomer(" + cid + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: loadCustomer(" + cid + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from loadCustomer(" + cid + "): " + returnValue + ".");    }    return returnValue;  }  public Customer exitCustomer(String cid) {    Customer returnValue = null;    if (sB_CustomerManager == null) {      System.out.println("Error in exitCustomer(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling exitCustomer(" + cid + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_CustomerManager.exitCustomer(cid);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: exitCustomer(" + cid + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: exitCustomer(" + cid + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from exitCustomer(" + cid + "): " + returnValue + ".");    }    return returnValue;  }  public void removeCustomer(String cid) {    if (sB_CustomerManager == null) {      System.out.println("Error in removeCustomer(): " + ERROR_NULL_REMOTE);      return ;    }    long startTime = 0;    if (logging) {      log("Calling removeCustomer(" + cid + ")");      startTime = System.currentTimeMillis();    }    try {      sB_CustomerManager.removeCustomer(cid);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: removeCustomer(" + cid + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: removeCustomer(" + cid + ")");      }      e.printStackTrace();    }  }  public Customer saveCustomer(Customer cus) {    Customer returnValue = null;    if (sB_CustomerManager == null) {      System.out.println("Error in saveCustomer(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling saveCustomer(" + cus + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_CustomerManager.saveCustomer(cus);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: saveCustomer(" + cus + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: saveCustomer(" + cus + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from saveCustomer(" + cus + "): " + returnValue + ".");    }    return returnValue;  }  public Customer addCustomer(Customer cus) {    Customer returnValue = null;    if (sB_CustomerManager == null) {      System.out.println("Error in addCustomer(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling addCustomer(" + cus + ")");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_CustomerManager.addCustomer(cus);      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: addCustomer(" + cus + ")");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: addCustomer(" + cus + ")");      }      e.printStackTrace();    }    if (logging) {      log("Return value from addCustomer(" + cus + "): " + returnValue + ".");    }    return returnValue;  }  public Collection getAllCustomer() {    Collection returnValue = null;    if (sB_CustomerManager == null) {      System.out.println("Error in getAllCustomer(): " + ERROR_NULL_REMOTE);      return returnValue;    }    long startTime = 0;    if (logging) {      log("Calling getAllCustomer()");      startTime = System.currentTimeMillis();    }    try {      returnValue = sB_CustomerManager.getAllCustomer();      if (logging) {        long endTime = System.currentTimeMillis();        log("Succeeded: getAllCustomer()");        log("Execution time: " + (endTime - startTime) + " ms.");      }    }    catch(Exception e) {      if (logging) {        log("Failed: getAllCustomer()");      }      e.printStackTrace();    }    if (logging) {      log("Return value from getAllCustomer(): " + 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_CustomerManagerTestClient1 client = new SB_CustomerManagerTestClient1();    SB_CustomerManager m=client.create();    try{     String cid="0987";     String cname="hu";     String cstuts="in";     String cnote="";     Customer cus=new Customer();     cus.setCid(cid);     cus.setCname(cname);     cus.setCstuts(cstuts);     Customer c=m.addCustomer(cus);     System.out.println(c.getCid());     System.out.println(c.getCname());    }    catch(Exception e){      e.printStackTrace();    }  }}

⌨️ 快捷键说明

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