1 7 package org.jboss.tutorial.injection.client; 8 9 10 import org.jboss.tutorial.injection.bean.ShoppingCart; 11 12 import javax.naming.InitialContext ; 13 14 import java.util.HashMap ; 15 16 22 public class Client 23 { 24 public static void main(String [] args) throws Exception 25 { 26 InitialContext ctx = new InitialContext (); 27 ShoppingCart cart = (ShoppingCart) ctx.lookup(ShoppingCart.class.getName()); 28 29 System.out.println("Buying 1 memory stick"); 30 cart.buy("Memory stick", 1); 31 System.out.println("Buying another memory stick"); 32 cart.buy("Memory stick", 1); 33 34 System.out.println("Buying a laptop"); 35 cart.buy("Laptop", 1); 36 37 System.out.println("Print cart:"); 38 HashMap <String , Integer > fullCart = cart.getCartContents(); 39 for (String product : fullCart.keySet()) 40 { 41 System.out.println(fullCart.get(product) + " " + product); 42 } 43 44 System.out.println("Checkout"); 45 cart.checkout(); 46 47 } 48 } 49 | Popular Tags |