KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > injection > 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.injection.bean;
8
9 import java.util.HashMap JavaDoc;
10 import javax.annotation.EJB;
11 import javax.ejb.Remote JavaDoc;
12 import javax.ejb.Remove JavaDoc;
13 import javax.ejb.Stateful JavaDoc;
14
15
16 @Stateful JavaDoc
17 @Remote JavaDoc(ShoppingCart.class)
18 public class ShoppingCartBean implements ShoppingCart, java.io.Serializable JavaDoc
19 {
20    private HashMap JavaDoc<String JavaDoc, Integer JavaDoc> cart = new HashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
21
22    @EJB
23    private Calculator calculator;
24
25
26    private Calculator set;
27
28    @EJB(beanName="org.jboss.tutorial.injection.bean.CalculatorBean")
29    public void setCalculator(Calculator c)
30    {
31       set = c;
32    }
33
34
35    public void buy(String JavaDoc product, int quantity)
36    {
37       if (cart.containsKey(product))
38       {
39          int currq = cart.get(product);
40          currq = calculator.add(currq, quantity);
41          cart.put(product, currq);
42       }
43       else
44       {
45          cart.put(product, quantity);
46       }
47    }
48
49    public HashMap JavaDoc<String JavaDoc, Integer JavaDoc> getCartContents()
50    {
51       return cart;
52    }
53
54    @Remove JavaDoc
55    public void checkout()
56    {
57       System.out.println("To be implemented");
58    }
59 }
60
Popular Tags