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