?? sb_accommodationmanagertestclient1.java~12~
字號:
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 java.util.Collection;import com.xc.hotelmanager.hotel.model.Accommodation;import java.util.*;import com.xc.hotelmanager.hotel.model.*;import com.xc.hotelmanager.hotel.control.*;public class SB_AccommodationManagerTestClient1 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_AccommodationManagerHome sB_AccommodationManagerHome = null; private SB_AccommodationManager sB_AccommodationManager = null; //Construct the EJB test client public SB_AccommodationManagerTestClient1() { 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_AccommodationManager"); //look up jndi name and cast to Home interface sB_AccommodationManagerHome = (SB_AccommodationManagerHome) PortableRemoteObject.narrow(ref, SB_AccommodationManagerHome.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_AccommodationManager create() { long startTime = 0; if (logging) { log("Calling create()"); startTime = System.currentTimeMillis(); } try { sB_AccommodationManager = sB_AccommodationManagerHome.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_AccommodationManager + "."); } return sB_AccommodationManager; } //---------------------------------------------------------------------------- // Methods that use Remote interface methods to access data through the bean //---------------------------------------------------------------------------- public Collection getAccInfo(String cname, String roomid) { Collection returnValue = null; if (sB_AccommodationManager == null) { System.out.println("Error in getAccInfo(): " + ERROR_NULL_REMOTE); return returnValue; } long startTime = 0; if (logging) { log("Calling getAccInfo(" + cname + ", " + roomid + ")"); startTime = System.currentTimeMillis(); } try { returnValue = sB_AccommodationManager.getAccInfo(cname, roomid); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: getAccInfo(" + cname + ", " + roomid + ")"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: getAccInfo(" + cname + ", " + roomid + ")"); } e.printStackTrace(); } if (logging) { log("Return value from getAccInfo(" + cname + ", " + roomid + "): " + returnValue + "."); } return returnValue; } public String getleavedate() { String returnValue = ""; if (sB_AccommodationManager == null) { System.out.println("Error in getleavedate(): " + ERROR_NULL_REMOTE); return returnValue; } long startTime = 0; if (logging) { log("Calling getleavedate()"); startTime = System.currentTimeMillis(); } try { returnValue = sB_AccommodationManager.getleavedate(); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: getleavedate()"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: getleavedate()"); } e.printStackTrace(); } if (logging) { log("Return value from getleavedate(): " + returnValue + "."); } return returnValue; } public int getlivedays(String id) { int returnValue = 0; if (sB_AccommodationManager == null) { System.out.println("Error in getlivedays(): " + ERROR_NULL_REMOTE); return returnValue; } long startTime = 0; if (logging) { log("Calling getlivedays(" + id + ")"); startTime = System.currentTimeMillis(); } try { returnValue = sB_AccommodationManager.getlivedays(id); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: getlivedays(" + id + ")"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: getlivedays(" + id + ")"); } e.printStackTrace(); } if (logging) { log("Return value from getlivedays(" + id + "): " + returnValue + "."); } return returnValue; } public float getTotelCost(String id) { float returnValue = 0f; if (sB_AccommodationManager == null) { System.out.println("Error in getTotelCost(): " + ERROR_NULL_REMOTE); return returnValue; } long startTime = 0; if (logging) { log("Calling getTotelCost(" + id + ")"); startTime = System.currentTimeMillis(); } try { returnValue = sB_AccommodationManager.getTotelCost(id); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: getTotelCost(" + id + ")"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: getTotelCost(" + id + ")"); } e.printStackTrace(); } if (logging) { log("Return value from getTotelCost(" + id + "): " + returnValue + "."); } return returnValue; } public String saveToAcc(String id, String leavetime, float charge) { String returnValue = ""; if (sB_AccommodationManager == null) { System.out.println("Error in saveToAcc(): " + ERROR_NULL_REMOTE); return returnValue; } long startTime = 0; if (logging) { log("Calling saveToAcc(" + id + ", " + leavetime + ", " + charge + ")"); startTime = System.currentTimeMillis(); } try { returnValue = sB_AccommodationManager.saveToAcc(id, leavetime, charge); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: saveToAcc(" + id + ", " + leavetime + ", " + charge + ")"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: saveToAcc(" + id + ", " + leavetime + ", " + charge + ")");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -