1 7 package jfox.test.ejb3.injection; 8 9 import java.util.HashMap ; 10 import java.util.Map ; 11 import javax.ejb.EJB ; 12 import javax.ejb.Remote ; 13 import javax.ejb.Stateful ; 14 15 16 @Stateful (name="injection.ShoppingCartBean") 17 @Remote (ShoppingCart.class) 18 public class ShoppingCartBean implements ShoppingCart, java.io.Serializable { 19 private final HashMap <String , Integer > cart = new HashMap <String , Integer >(); 20 21 @EJB (beanName = "injection.CalculatorBean") 22 private Calculator calculator; 23 24 public void buy(String 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 <String , Integer > getCartContents() { 36 return cart; 37 } 38 39 } 40 | Popular Tags |