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

import org.jboss.aop.joinpoint.FieldReadInvocation;
import org.jboss.aop.joinpoint.FieldWriteInvocation;

/**
 *
 *  @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 *  @version $Revision: 1.2.2.4 $
 */
public class StateChangeInterceptor implements org.jboss.aop.advice.Interceptor
{
   protected DistributedPOJOState manager;

   public StateChangeInterceptor(DistributedPOJOState manager)
   {
      this.manager = manager;
   }

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

   /**
    *
    */
   public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable
   {
      if (!(invocation instanceof FieldWriteInvocation) && !(invocation instanceof FieldReadInvocation)) return invocation.invokeNext();

      // Don't need to worry if we're static or not because this is an instance interceptor

      if (invocation instanceof FieldReadInvocation)
      {
         return manager.fieldRead(invocation);
      }
      else
      {
         return manager.fieldWrite(invocation);
      }
   }

}
