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

InvariantCondition

public class InvariantCondition extends Condition
author
Kabir Khan
version
$Revision: 57186 $

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

      super(condExpr, clazz, isStatic);
   
Methods Summary
public booleanequals(java.lang.Object o)

      if (o instanceof InvariantCondition)
      {
         return super.equals(o);
      }
      return false;
   
public voidevaluateCondition(org.jboss.aop.joinpoint.Invocation inv, boolean staticCall, boolean constructor, java.lang.Object ret)

      try
      {
         if (DesignByContractAspect.verbose) System.out.println("[dbc] Evaluate condition : '" + originalExpr + "' for class: " + clazz);
         
         if (!isStatic && staticCall)
         {
            System.out.println("[dbc] Ignoring non-static invariant for static call");
            return;
         }
   
         Interpreter interpreter = new Interpreter();
         Object target = (constructor) ? ret : getTarget(inv, staticCall);
         
         for (Iterator it = parameterLookup.keySet().iterator() ; it.hasNext() ; )
         {
            String bsname = (String)it.next();
            String originalname = (String)parameterLookup.get(bsname); 
            if (originalname.equals(Condition.TARGET))
            {
               interpreter.set(bsname, target);
               if (DesignByContractAspect.verbose) System.out.println("[dbc] Setting $" + originalname + " to " + target +" (type: " + target.getClass().getName() + ")");
            }
            else
            {
               System.out.println("INVARIANT CONDITION BROKEN: "+ originalExpr + " - " + clazz);
               throw new RuntimeException("Invalid marker '" + originalname + "' in expression: " + originalExpr);
            }
         }
         
         Boolean eval = (Boolean)interpreter.eval(condExpr);
   
         if (!eval.booleanValue())
         {
            throw new RuntimeException("Invariant condition " + originalExpr + " was broken " + "for class: " + clazz);
         }
      }
      catch (EvalError e)
      {
         throw new RuntimeException("There was an error in the expression: " + originalExpr, e);
      }