KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > injection > client > Client


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.injection.client;
8
9
10 import org.jboss.tutorial.injection.bean.ShoppingCart;
11
12 import javax.naming.InitialContext JavaDoc;
13
14 import java.util.HashMap JavaDoc;
15
16 /**
17  * Comment
18  *
19  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
20  * @version $Revision: 1.2.6.3 $
21  */

22 public class Client
23 {
24    public static void main(String JavaDoc[] args) throws Exception JavaDoc
25    {
26       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
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 JavaDoc<String JavaDoc, Integer JavaDoc> fullCart = cart.getCartContents();
39       for (String JavaDoc 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