KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > stateful > bean > ShoppingCartBean


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.bean;
8
9 import java.io.Serializable JavaDoc;
10 import java.util.HashMap JavaDoc;
11 import javax.ejb.Remove JavaDoc;
12 import javax.ejb.Stateful JavaDoc;
13 import javax.ejb.Remote JavaDoc;
14
15
16 @Stateful JavaDoc
17 @Remote JavaDoc(ShoppingCart.class)
18 public class ShoppingCartBean implements ShoppingCart, Serializable JavaDoc
19 {
20    private HashMap JavaDoc<String JavaDoc, Integer JavaDoc> cart = new HashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
21
22    public void buy(String JavaDoc product, int quantity)
23    {
24       if (cart.containsKey(product))
25       {
26          int currq = cart.get(product);
27          currq += quantity;
28          cart.put(product, currq);
29       }
30       else
31       {
32          cart.put(product, quantity);
33       }
34    }
35
36    public HashMap JavaDoc<String JavaDoc, Integer JavaDoc> getCartContents()
37    {
38       return cart;
39    }
40
41    @Remove JavaDoc
42    public void checkout()
43    {
44       System.out.println("To be implemented");
45    }
46 }
47
Popular Tags