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

import java.lang.reflect.Method;

import org.jboss.aop.joinpoint.Invocation;

/**
 *
 * @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
 * @version $Revision: 1.1.8.4 $
 */
public class MethodCondition extends ExecutableCondition
{
   Method method;
   
   public MethodCondition(Method method, String condExpr, boolean staticCall)
   {
      super(condExpr, method.getClass(), staticCall);
      this.method = method;
   }

   public boolean equals(Object o)
   {
      if (o instanceof MethodCondition)
      {
         MethodCondition mc = (MethodCondition)o;
         if (mc.method.equals(method))
         {
            return super.equals(o);
         }
      }
      return false;
   }

   // ExecutableCondition implementation -------------------------------------
   protected Object executableObject()
   {
      return method;
   }

   protected Class[] parameterTypes()
   {
      return method.getParameterTypes();
   }

   protected boolean isPredefinedToken(String token)
   {
      return token.equals(Condition.TARGET) || token.equals(Condition.RETURN);
   }
   
   protected Object getValueForPredefinedToken(Invocation invocation, Object rtn, String token)
   {
      if (token.equals(Condition.TARGET))
      {
         return getTarget(invocation, isStatic);
      }
      else if (token.equals(Condition.RETURN))
      {
         return rtn;
      }
      
      return null;
   }
}
