KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > stateful > 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.stateful.client;
8
9
10 import java.util.HashMap JavaDoc;
11 import javax.naming.InitialContext JavaDoc;
12 import org.jboss.tutorial.stateful.bean.ShoppingCart;
13
14 /**
15  * Comment
16  *
17  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
18  * @version $Revision: 1.1.6.3 $
19  */

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