FileDocCategorySizeDatePackage
ExecutableCondition.javaAPI DocJBoss 4.2.14084Fri Jul 13 21:02:28 BST 2007org.jboss.aspects.dbc.condition

ExecutableCondition

public abstract class ExecutableCondition extends Condition
A pre or post consition
author
Kabir Khan
version
$Revision: 57186 $

Fields Summary
Constructors Summary
public ExecutableCondition(String condExpr, Class clazz, boolean isStatic)

      super(condExpr, clazz, isStatic);
   
Methods Summary
public voidevaluateCondition(org.jboss.aspects.dbc.DesignByContractAspect aspect, org.jboss.aop.joinpoint.Invocation inv, java.lang.Object[] args, java.lang.Object ret)

      try
      {
         if (DesignByContractAspect.verbose) System.out.println("[dbc] Evaluate condition : '" + originalExpr + "' for: " + executableObject());
   
         Interpreter interpreter = new Interpreter();
         for (Iterator it = parameterLookup.keySet().iterator() ; it.hasNext() ; )
         {
            String beanshellname = (String)it.next();
            String originalname = (String)parameterLookup.get(beanshellname);
            Object value = getValueForToken(inv, args, ret, originalname);
            interpreter.set(beanshellname, value);
            if (DesignByContractAspect.verbose) System.out.println("[dbc] Setting $" + originalname + " to " + value + 
                  ((value != null) ? " (type: " + value.getClass().getName() + ")" : "")) ;
         }
   
         Boolean eval = (Boolean)interpreter.eval(condExpr);
   
         if (!eval.booleanValue())
         {
            System.out.println("CONDITION BROKEN: "+ originalExpr + " - " + executableObject());
            throw new RuntimeException("Condition " + originalExpr + " was broken " + "for: " + executableObject());
         }
      }
      catch (EvalError e)
      {
         throw new RuntimeException("There was an error in the expression: " + originalExpr, e);
      }
   
protected abstract java.lang.ObjectexecutableObject()

protected abstract java.lang.ObjectgetValueForPredefinedToken(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object rtn, java.lang.String token)

protected java.lang.ObjectgetValueForToken(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object[] args, java.lang.Object rtn, java.lang.String token)

      if (isPredefinedToken(token))
      {
      	return getValueForPredefinedToken(invocation, rtn, token);
      }
     
      try
      {
         int i = Integer.parseInt(token);
         return args[i];
      }
      catch(NumberFormatException e)
      {
         throw new RuntimeException("Invalid token '$" + token + "' in condition: " + originalExpr);
      }
      catch(ArrayIndexOutOfBoundsException e)
      {
         throw new RuntimeException("invalid parameter number '$" + token + "' in condition: "
               + originalExpr + ". " + executableObject() + " takes " + parameterTypes().length);
      }
   
protected abstract booleanisPredefinedToken(java.lang.String token)

protected abstract java.lang.Class[]parameterTypes()

public java.lang.StringtoString()

      return executableObject() + ":" + super.toString();