/*
 * JBoss, the OpenSource EJB server
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.ejb3.test.entitycallback;

import java.util.HashMap;
import javax.ejb.Stateful;
import javax.ejb.Remote;

/**
 * @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
 * @version $Revision: 1.3.2.4 $
 */
@Stateful
@Remote(CallbackCounter.class)
public class CallbackCounterBean implements CallbackCounter, java.io.Serializable
{
   public static HashMap<String, HashMap> callbacks = new HashMap<String, HashMap>();

   public static void addCallback(String className, Class callbackAnnotation)
   {
      System.out.println("***** Adding " + callbackAnnotation.getName() + " callback to " + className);

      HashMap<Class, Integer> classCallbacks = callbacks.get(className);
      if (classCallbacks == null)
      {
         classCallbacks = new HashMap<Class, Integer>();

         callbacks.put(className, classCallbacks);
      }
      Integer i = classCallbacks.get(callbackAnnotation);
      if (i == null)
      {
         i = 0;
      }
      i++;
      System.out.println("count: " + i);
      classCallbacks.put(callbackAnnotation, i);
   }

   public int getCallbacks(String beanClass, Class callbackAnnotation)
   {
      HashMap<Class, Integer> classCallbacks = callbacks.get(beanClass);
      if (classCallbacks == null)
      {
         return 0;
      }

      Integer i = classCallbacks.get(callbackAnnotation);
      if (i != null)
      {
         return i;
      }

      return 0;
   }

   public static void clear()
   {
      callbacks = new HashMap<String, HashMap>();
   }
}
