KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfox > test > ejb3 > injection > ShoppingCartBean


1 /*
2  * JFox - The most lightweight Java EE Application Server!
3  * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
4  *
5  * JFox is licenced and re-distributable under GNU LGPL.
6  */

7 package jfox.test.ejb3.injection;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11 import javax.ejb.EJB JavaDoc;
12 import javax.ejb.Remote JavaDoc;
13 import javax.ejb.Stateful JavaDoc;
14
15
16 @Stateful JavaDoc(name="injection.ShoppingCartBean")
17 @Remote JavaDoc(ShoppingCart.class)
18 public class ShoppingCartBean implements ShoppingCart, java.io.Serializable JavaDoc {
19     private final HashMap JavaDoc<String JavaDoc, Integer JavaDoc> cart = new HashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
20
21     @EJB JavaDoc(beanName = "injection.CalculatorBean")
22     private Calculator calculator;
23
24     public void buy(String JavaDoc product, int quantity) {
25         if (cart.containsKey(product)) {
26             int currq = cart.get(product);
27             currq = calculator.add(currq, quantity);
28             cart.put(product, currq);
29         }
30         else {
31             cart.put(product, quantity);
32         }
33     }
34
35     public Map JavaDoc<String JavaDoc, Integer JavaDoc> getCartContents() {
36         return cart;
37     }
38
39 }
40
Popular Tags