FileDocCategorySizeDatePackage
Client_121b.javaAPI DocExample2794Mon Sep 30 09:42:58 BST 2002com.titan.clients

Client_121b

public class Client_121b extends Object
Example demonstrating use of ProcessPayment EJB directly

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

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

      try
      {
         Context jndiContext = getInitialContext ();
         
         System.out.println ("Looking up home interfaces..");
         Object ref = jndiContext.lookup ("ProcessPaymentHomeRemote");
         
         ProcessPaymentHomeRemote procpayhome = (ProcessPaymentHomeRemote)
         PortableRemoteObject.narrow (ref,ProcessPaymentHomeRemote.class);
         
         ProcessPaymentRemote procpay = procpayhome.create ();
            
         ref = jndiContext.lookup ("CustomerHomeRemote");
            
         CustomerHomeRemote custhome = (CustomerHomeRemote)
            PortableRemoteObject.narrow (ref,CustomerHomeRemote.class);
         
         CustomerRemote cust = custhome.findByPrimaryKey (new Integer (1));
         
         System.out.println ("Making a payment using byCash()..");
         procpay.byCash (cust,1000.0);
         
         System.out.println ("Making a payment using byCheck()..");
         CheckDO check = new CheckDO ("010010101101010100011", 3001);
         procpay.byCheck (cust,check,2000.0);
         
         System.out.println ("Making a payment using byCredit()..");
         Calendar expdate = Calendar.getInstance ();
         expdate.set (2005,1,28); // month=1 is February
         CreditCardDO credit = new CreditCardDO ("370000000000002",expdate.getTime (),"AMERICAN_EXPRESS");
         procpay.byCredit (cust,credit,3000.0);
         
         System.out.println ("Making a payment using byCheck() with a low check number..");
         CheckDO check2 = new CheckDO ("111000100111010110101", 1001);
         try
         {
            procpay.byCheck (cust,check2,9000.0);
            System.out.println("Problem! The PaymentException has not been raised!");
         }
         catch (PaymentException pe)
         {
            System.out.println ("Caught PaymentException: "+pe.getMessage ());
         }
         
         procpay.remove ();
      }
      catch(java.rmi.RemoteException re)
      {
         re.printStackTrace ();
      }
      catch(Throwable t)
      {
         t.printStackTrace ();
      }