/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.tutorial.injection.bean;

import java.util.HashMap;
import javax.annotation.EJB;
import javax.ejb.Remote;
import javax.ejb.Remove;
import javax.ejb.Stateful;


@Stateful
@Remote(ShoppingCart.class)
public class ShoppingCartBean implements ShoppingCart, java.io.Serializable
{
   private HashMap<String, Integer> cart = new HashMap<String, Integer>();

   @EJB
   private Calculator calculator;


   private Calculator set;

   @EJB(beanName="org.jboss.tutorial.injection.bean.CalculatorBean")
   public void setCalculator(Calculator c)
   {
      set = c;
   }


   public void buy(String product, int quantity)
   {
      if (cart.containsKey(product))
      {
         int currq = cart.get(product);
         currq = calculator.add(currq, quantity);
         cart.put(product, currq);
      }
      else
      {
         cart.put(product, quantity);
      }
   }

   public HashMap<String, Integer> getCartContents()
   {
      return cart;
   }

   @Remove
   public void checkout()
   {
      System.out.println("To be implemented");
   }
}
