KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > stateful_deployment_descriptor > 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_deployment_descriptor.client;
8
9
10 import org.jboss.tutorial.stateful_deployment_descriptor.bean.ShoppingCart;
11
12 import javax.ejb.EJBException JavaDoc;
13 import javax.ejb.EJBNoSuchObjectException;
14 import javax.naming.InitialContext JavaDoc;
15
16 import java.rmi.NoSuchObjectException JavaDoc;
17 import java.util.HashMap JavaDoc;
18
19 /**
20  * Comment
21  *
22  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
23  * @version $Revision: 1.1.2.4 $
24  */

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