1 7 package org.jboss.tutorial.stateful.client; 8 9 10 import java.util.HashMap ; 11 import javax.naming.InitialContext ; 12 import org.jboss.tutorial.stateful.bean.ShoppingCart; 13 14 20 public class Client 21 { 22 public static void main(String [] args) throws Exception 23 { 24 InitialContext ctx = new InitialContext (); 25 ShoppingCart cart = (ShoppingCart) ctx.lookup(ShoppingCart.class.getName()); 26 27 System.out.println("Buying 1 memory stick"); 28 cart.buy("Memory stick", 1); 29 System.out.println("Buying another memory stick"); 30 cart.buy("Memory stick", 1); 31 32 System.out.println("Buying a laptop"); 33 cart.buy("Laptop", 1); 34 35 System.out.println("Print cart:"); 36 HashMap <String , Integer > fullCart = cart.getCartContents(); 37 for (String product : fullCart.keySet()) 38 { 39 System.out.println(fullCart.get(product) + " " + product); 40 } 41 42 System.out.println("Checkout"); 43 cart.checkout(); 44 45 System.out.println("Should throw an object not found exception by invoking on cart after @Remove method"); 46 try 47 { 48 cart.getCartContents(); 49 } 50 catch (javax.ejb.EJBNoSuchObjectException e) 51 { 52 System.out.println("Successfully caught no such object exception."); 53 } 54 55 56 } 57 } 58 | Popular Tags |