1 7 package org.jboss.tutorial.injection.bean; 8 9 import java.util.HashMap ; 10 import javax.annotation.EJB; 11 import javax.ejb.Remote ; 12 import javax.ejb.Remove ; 13 import javax.ejb.Stateful ; 14 15 16 @Stateful 17 @Remote (ShoppingCart.class) 18 public class ShoppingCartBean implements ShoppingCart, java.io.Serializable 19 { 20 private HashMap <String , Integer > cart = new HashMap <String , Integer >(); 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 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 <String , Integer > getCartContents() 50 { 51 return cart; 52 } 53 54 @Remove 55 public void checkout() 56 { 57 System.out.println("To be implemented"); 58 } 59 } 60 | Popular Tags |