FileDocCategorySizeDatePackage
DesignByContractAspect.javaAPI DocJBoss 4.2.18771Fri Jul 13 21:02:28 BST 2007org.jboss.aspects.dbc

DesignByContractAspect

public class DesignByContractAspect extends Object
TODO: -Once version of beanshell in cvs allows importObject() (2.0, currently in beta), make invariants use that, so don't have to use $tgt for class invariants -Add $old funtionality
author
Kabir Khan
version
$Revision: 57186 $

Fields Summary
public static boolean
verbose
org.jboss.aspects.dbc.condition.ExecutableCondition[]
preconditions
org.jboss.aspects.dbc.condition.ExecutableCondition[]
postconditions
org.jboss.aspects.dbc.condition.InvariantCondition[]
invariants
Method
method
Constructor
constructor
boolean
isPublic
boolean
isStatic
boolean
isSynchronized
boolean
initialised
ThreadLocal
done
Constructors Summary
public DesignByContractAspect()

   
    
   
      done.set(Boolean.FALSE);
   
Methods Summary
private voidcheckInvariants(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object ret)

      if (verbose) System.out.println("[dbc] === checkInvariants() for " + ((method != null) ? method.toString() : constructor.toString()));
      boolean isConstructor = (constructor != null);
      for (int i = 0 ; i < invariants.length ; i++)
      {
         invariants[i].evaluateCondition(invocation, isStatic, isConstructor, ret);
      }
   
private voidcheckPostConditions(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object[] args, java.lang.Object ret)

      if (verbose) System.out.println("[dbc] === checkPostconditions() for " + ((method != null) ? method.toString() : constructor.toString()));
      for (int i = 0 ; i < postconditions.length ; i++)
      {
         postconditions[i].evaluateCondition(this, invocation, args, ret);
      }
   
private voidcheckPreConditions(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object[] args)

      if (verbose) System.out.println("[dbc] === checkPreconditions() for " + ((method != null) ? method.toString() : constructor.toString()));
      for (int i = 0 ; i < preconditions.length ; i++)
      {
         preconditions[i].evaluateCondition(this, invocation, args, null);
     }
   
private java.lang.ObjectdoInvoke(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object[] args)

      logStart();
      Object ret = null;
      boolean wasDone = ((Boolean)done.get()).booleanValue();

      try
      {
         done.set(Boolean.TRUE);
         if (!wasDone && isPublic && (constructor == null))
         {
            checkInvariants(invocation, null);
         }
         if (!wasDone)
         {
            checkPreConditions(invocation, args);
         }
            
         ret = invocation.invokeNext();

         if (!wasDone && isPublic)
         {
            checkInvariants(invocation, ret);
            checkPostConditions(invocation, args, ret);
         }
      }
      finally
      {
         if (!wasDone)
         {
            done.set(Boolean.FALSE);
         }
      }
      
      logEnd();
      return ret;
   
public booleangetVerbose()

      return verbose;
   
private voidinitialise(java.lang.reflect.Method m)

      method = m;
      int modifiers = m.getModifiers();
      initialise(modifiers);
      
      preconditions = MethodConditionManager.getPreConditions(m);
      postconditions = MethodConditionManager.getPostConditions(m);
      
      if (isPublic)
      {
         invariants = MethodConditionManager.getInvariants(m);
      }
   
private voidinitialise(java.lang.reflect.Constructor c)

      constructor = c;
      int modifiers = c.getModifiers();
      initialise(modifiers);

      preconditions = ConstructorConditionManager.getPreConditions(c);
      postconditions = ConstructorConditionManager.getPostConditions(c);
      
      if (isPublic)
      {
         invariants = ConstructorConditionManager.getInvariants(c);
      }
   
private voidinitialise(int modifiers)

      isSynchronized = Modifier.isSynchronized(modifiers);
      isStatic = Modifier.isStatic(modifiers);
      isPublic = Modifier.isPublic(modifiers);
      
      initialised = true;      
   
private java.lang.Objectinvoke(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object[] args)

      if (isSynchronized)
      {
         if (isStatic)
         {
            synchronized (method.getDeclaringClass())
            {
               return doInvoke(invocation, args);
            }
         }
         else
         {
            synchronized (invocation.getTargetObject())
            {
               return doInvoke(invocation, args);
            }
         }
      }
      return doInvoke(invocation, args);
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.MethodInvocation invocation)

      if (!initialised)
      {
         initialise(invocation.getMethod());
      }
      Object[] args = invocation.getArguments();
      return invoke(invocation, args);
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.MethodCalledByMethodInvocation invocation)

      if (!initialised)
      {
         initialise(invocation.getCalledMethod());
      }
      Object[] args = invocation.getArguments();
      return invoke(invocation, args);
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.MethodCalledByConstructorInvocation invocation)

      if (!initialised)
      {
         initialise(invocation.getCalledMethod());
      }
      Object[] args = invocation.getArguments();
      return invoke(invocation, args);
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.ConstructorInvocation invocation)

      if (!initialised)
      {
         initialise(invocation.getConstructor());
      }
      Object[] args = invocation.getArguments();
      return invoke(invocation, args);
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.ConstructorCalledByMethodInvocation invocation)

      if (!initialised)
      {
         initialise(invocation.getCalledConstructor());
      }
      Object[] args = invocation.getArguments();
      return invoke(invocation, args);
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.ConstructorCalledByConstructorInvocation invocation)

      if (!initialised)
      {
         initialise(invocation.getCalledConstructor());
      }
      Object[] args = invocation.getArguments();
      return invoke(invocation, args);
   
private voidlogEnd()

      if (verbose)
      {
         if (method != null)
         {
            System.out.println("[dbc] ======= Invoked method: " + method);
         }
         else
         {
            System.out.println("[dbc] ======= Invoked constructor: " + constructor);
         }
      }
   
private voidlogStart()

      if (verbose)
      {
         if (method != null)
         {
            System.out.println("[dbc] ======= Invoking method: " + method);
         }
         else
         {
            System.out.println("[dbc] ======= Invoking constructor: " + constructor);
         }
      }
   
public voidsetVerbose(boolean vbs)

      verbose = vbs;