?? sb_hotelmanagertestclient2.java
字號(hào):
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 java.util.*;
import com.xc.hotelmanager.hotel.model.*;
import com.xc.hotelmanager.hotel.control.*;
public class SB_hotelmanagerTestClient2 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_hotelmanagerTestClient2() {
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://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_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 int FindEmptyRoom(String type) {
int returnValue = 0;
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 String getRoomtype(String id) {
String returnValue = null;
if (sB_hotelmanager == null) {
System.out.println("Error in getAllRoomMsg(): " + ERROR_NULL_REMOTE);
return returnValue;
}
long startTime = 0;
if (logging) {
log("Calling getAllRoomMsg()");
startTime = System.currentTimeMillis();
}
try {
returnValue = sB_hotelmanager.getRoomtype(id);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: getAllRoomMsg()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: getAllRoomMsg()");
}
e.printStackTrace();
}
if (logging) {
log("Return value from getAllRoomPrice(): " + returnValue + ".");
}
return returnValue;
}
public void CancleRes(String id) {
if (sB_hotelmanager == null) {
System.out.println("Error in CancleRes(): " + ERROR_NULL_REMOTE);
return ;
}
long startTime = 0;
if (logging) {
log("Calling CancleRes( " + id + ")");
startTime = System.currentTimeMillis();
}
try {
sB_hotelmanager.CancleRes( id);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: CancleRes( " + id + ")");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: CancleRes( " + id + ")");
}
e.printStackTrace();
}
}
public Collection getRoomByType(String type) {
Collection returnValue =null;
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_hotelmanagerTestClient2 client = new SB_hotelmanagerTestClient2();
SB_hotelmanager m = client.create();
//SB_AccommodationManager a=client.create();
Reservation res = new Reservation();
res.setArrivetime("060918");
res.setCid("23");
res.setCname("alix");
res.setDays(2);
res.setMembers(1);
res.setPrepay(100);
Collection record = null;
Collection re = null;
String msg = null;
String str3 = "0";
int str1 = 0;
String s = "001";
/* try{
m.CancleResByDate("060827163614");
}
catch(Exception e){
e.printStackTrace();
}
try{
re=m.SearchRes("b");
if(re==null){System.out.println("record is null");}
if(re.equals("")){System.out.println("record is kong");}
else System.out.println("is not null");
Iterator h=re.iterator();
while(h.hasNext()){str1=str1+1;}
System.out.println(str1);
}
catch(Exception e){
e.printStackTrace();
}*/
try{
String s1="005";
String s2="3421";
String s3="kong";
Room room=new Room();
room.setRoomid(s2);
room.setRtypeid(s1);
room.setRstuts(s3);
Room t=m.addRoom(room);
System.out.println(t.getRoomid());
System.out.println(t.getRtypeid());
}
catch(Exception e){
e.printStackTrace();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -