/***************************************
 *                                     *
 *  JBoss: The OpenSource J2EE WebOS   *
 *                                     *
 *  Distributable under LGPL license.  *
 *  See terms of license at gnu.org.   *
 *                                     *
 ***************************************/
package org.jboss.aspects.remoting;

import org.jboss.aop.Dispatcher;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.ServerInvocationHandler;
import org.jboss.remoting.ServerInvoker;

import javax.management.MBeanServer;

/**
 * AOPRemotingInvocationHandler is a ServerInvocationHandler that will forward requests to the
 * aop Dispatcher
 *
 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 * @version $Revision: 1.2.2.6 $
 */
public class AOPRemotingInvocationHandler implements ServerInvocationHandler
{
   public AOPRemotingInvocationHandler()
   {
      super();
   }

   /**
    * set the invoker that owns this handler
    *
    * @param invoker
    */
   public void setInvoker(ServerInvoker invoker)
   {
   }

   /**
    * set the mbean server that the handler can reference
    *
    * @param server
    */
   public void setMBeanServer( MBeanServer server )
   {
   }

   /**
    * method is called to destroy the handler and remove all pending notifications and listeners
    * from the notification cache
    */
   public synchronized void destroy()
   {
   }

   protected void finalize() throws Throwable
   {
      destroy();
      super.finalize();
   }

   public Object invoke(InvocationRequest invocation)
      throws Throwable
   {
      org.jboss.aop.joinpoint.Invocation inv =(org.jboss.aop.joinpoint.Invocation)invocation.getParameter();
      return Dispatcher.singleton.invoke(inv);
   }

    /**
     * Adds a callback handler that will listen for callbacks from
     * the server invoker handler.
     * @param callbackHandler
     */
    public void addListener(InvokerCallbackHandler callbackHandler)
    {
        //TODO: implement for callback api -TME
    }

    /**
     * Removes the callback handler that was listening for callbacks
     * from the server invoker handler.
     * @param callbackHandler
     */
    public void removeListener(InvokerCallbackHandler callbackHandler)
    {
        //TODO: implement for callback api -TME
    }
}
