Client_122b.javaAPI DocExample2803Wed May 29 18:53:50 BST 2002com.titan.clients


public class Client_122b extends Object
Books passage for a Customer on a particular Cruise in a specified Cabin Uses command-line parameters: java com.titan.clients.Client_122b

Fields Summary
Constructors Summary
Methods Summary
public static javax.naming.ContextgetInitialContext()

		return new InitialContext();
public static voidmain(java.lang.String[] args)

		if (args.length != 4) {
			System.out.println("Usage: java com.titan.clients.Client_122b <customerID> <cruiseID> <cabinID> <price>");

		Integer customerID = new Integer(args[0]);
		Integer cruiseID = new Integer(args[1]);
		Integer cabinID = new Integer(args[2]);
		double price = new Double(args[3]).doubleValue();

		Context jndiContext = getInitialContext();
		Object obj = jndiContext.lookup("TravelAgentHomeRemote");
		TravelAgentHomeRemote tahome = (TravelAgentHomeRemote) 
			javax.rmi.PortableRemoteObject.narrow(obj, TravelAgentHomeRemote.class);

		obj = jndiContext.lookup("CustomerHomeRemote");
		CustomerHomeRemote custhome = (CustomerHomeRemote) 
			javax.rmi.PortableRemoteObject.narrow(obj, CustomerHomeRemote.class);

		// Find a reference to the Customer for which to book a cruise
		System.out.println("Finding reference to Customer "+customerID);
		CustomerRemote cust = custhome.findByPrimaryKey(customerID);

		// Start the Stateful session bean
		System.out.println("Starting TravelAgent Session...");
		TravelAgentRemote tagent = tahome.create(cust);

		// Set the other bean parameters in agent bean
		System.out.println("Setting Cruise and Cabin information in TravelAgent..");

		// Create a dummy CreditCard for this.  Really should use Customer's card, but CreditCard bean is local
		// and there is no getCreditCard() function on Customer which returns a CreditCardDO object.
		Calendar expdate = Calendar.getInstance();
		CreditCardDO card = new CreditCardDO("370000000000002",expdate.getTime(),"AMERICAN EXPRESS");

		// Book the passage
		System.out.println("Booking the passage on the Cruise!");
		TicketDO ticket = tagent.bookPassage(card,price);

		System.out.println("Ending TravelAgent Session...");

		System.out.println("Result of bookPassage:");