商务预订系统的程序代码示例
整个商务预订系统的开发是在IBM VisualAge for Java下面开发完成的,在该IDE开发环境中,实体Bean绝对会话Bean要轻易开发得多,以下就以TravelAgentBean为例,介绍EJB组件的开发过程:
1.TravelAgent远程接口
它提供了设置客户希望预订的航线和客舱ID的方法。此外,还设置boolPassage()方法来对客户的预订进行计费,并为客户产生一张票据。具体代码如下:
package com.titan.travelagent;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import com.titan.cruise.Cruise;
import com.titan.customer.Customer;
import com.titan.processpayment.CreditCard;
public interface TravelAgent extends javax.ejb.EJBObject
{
public void setCruiseID(int cruise) throws RemoteException, FinderException;
public int getCruiseID( ) throws RemoteException, IncompleteConversationalState;
public void setCabinID(int cabin) throws RemoteException, FinderException;
public int getCabinID()throws RemoteException, IncompleteConversationalState;
public int getCustomerID()throws RemoteException, IncompleteConversationalState;
public Ticket boolPassage(CreditCard card,double price) throws RemoteException。IncompleteConversationalState;
}
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import com.titan.cruise.Cruise;
import com.titan.customer.Customer;
import com.titan.processpayment.CreditCard;
public interface TravelAgent extends javax.ejb.EJBObject
{
public void setCruiseID(int cruise) throws RemoteException, FinderException;
public int getCruiseID( ) throws RemoteException, IncompleteConversationalState;
public void setCabinID(int cabin) throws RemoteException, FinderException;
public int getCabinID()throws RemoteException, IncompleteConversationalState;
public int getCustomerID()throws RemoteException, IncompleteConversationalState;
public Ticket boolPassage(CreditCard card,double price) throws RemoteException。IncompleteConversationalState;
}
2.TravelAgent Home接口
puckage com.titan.tracelagent;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import com.titan.customer.Customer;
public interface TravelAgentHome extends javax.ejb.EJBHome {
public TravelAgent create(Customer cust) throws RemoteException,CreateException;}
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import com.titan.customer.Customer;
public interface TravelAgentHome extends javax.ejb.EJBHome {
public TravelAgent create(Customer cust) throws RemoteException,CreateException;}
3.TravelAgent Bean类
它需要实现TravelAgent的远程接口和Home接口中的所有行为,限于篇幅,本文将不再介绍其实现代码,感爱好的读者可自己加以完成。以上就是基于EJB技术的商务预订系统的开发。