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

ConditionManager

public class ConditionManager extends Object
author
Kabir Khan
version
$Revision: 57186 $

Fields Summary
public static HashMap
preConditions
public static HashMap
postConditions
public static HashMap
invariants
Constructors Summary
Methods Summary
private static voidaddInvariantConditions(java.util.ArrayList conditions, java.lang.Class clazz)

      Invariant inv = (Invariant)AnnotationElement.getAnyAnnotation(clazz, Invariant.class);
      if (inv != null)
      {
         if (DesignByContractAspect.verbose) System.out.println("[dbc] Found non-static invariants in class: " + clazz);
         String[] exprs = inv.value();
         if (exprs != null)
         {
            for (int i = 0 ; i < exprs.length ; i++)
            {
               conditions.add(new InvariantCondition(clazz, exprs[i], false));
            }
         }
      }

      StaticInvariant statinv = (StaticInvariant)AnnotationElement.getAnyAnnotation(clazz, StaticInvariant.class);
      if (statinv != null)
      {
         if (DesignByContractAspect.verbose) System.out.println("[dbc] Found static invariants in class: " + clazz);
         String[] exprs = statinv.value();
         if (exprs != null)
         {
            for (int i = 0 ; i < exprs.length ; i++)
            {
               conditions.add(new InvariantCondition(clazz, exprs[i], true));
            }
         }
      }
   
public static synchronized InvariantCondition[]getInvariants(java.lang.Class clazz)

   
        
   
      InvariantCondition[] inv = (InvariantCondition[])invariants.get(clazz); 
      if (inv != null)
      {
         return inv;
      }
      
      initialise(clazz);
      return (InvariantCondition[])invariants.get(clazz); 
   
protected static voidinitialise(java.lang.Class clazz)

      ArrayList invConds = new ArrayList();
      
      if (invariants.get(clazz) != null)
      {
         if (DesignByContractAspect.verbose)System.out.println("[dbc] Already have invariants for class: " + clazz);
      }
      
      if (DesignByContractAspect.verbose)System.out.println("[dbc] ===== Initialising invariants for class: " + clazz);

      //We need the @Invariant for this class and the super classes
      Class curClazz = clazz;

      while (curClazz != null)
      {
         addInvariantConditions(invConds, curClazz);
			
			Class[] interfaces = curClazz.getInterfaces();
			for (int i = 0; i < interfaces.length ; i++)
			{
			   addInvariantConditions(invConds, interfaces[i]);
			}

         curClazz = curClazz.getSuperclass();
      }
      
      InvariantCondition[] inv = (InvariantCondition[])invConds.toArray(new InvariantCondition[invConds.size()]);
      invariants.put(clazz, inv);