/*
 * 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;
/**
 * Checks to see if this object is local in VM
 *
 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 * @version $Revision: 1.2.2.5 $
 */
public class IsLocalInterceptor implements org.jboss.aop.advice.Interceptor, java.io.Serializable
{
   private static final long serialVersionUID = 8067347185395345001L;
   
   public static final IsLocalInterceptor singleton = new IsLocalInterceptor();

   public String getName() { return "IsLocalInterceptor"; }

   public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable
   {
      Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
      if (Dispatcher.singleton.isRegistered(oid))
      {
         org.jboss.aop.joinpoint.InvocationResponse response = Dispatcher.singleton.invoke(invocation);
         invocation.setResponseContextInfo(response.getContextInfo());
         return response.getResponse();
      }
      return invocation.invokeNext();
   }
}
