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

Condition

public abstract class Condition extends Object
Stores a
author
Kabir Khan
version
$Revision: 57186 $

Fields Summary
public static final String
TARGET
public static final String
RETURN
protected HashMap
parameterLookup
protected String
originalExpr
protected String
condExpr
protected Class
clazz
protected boolean
isStatic
Constructors Summary
public Condition(String condExpr, Class clazz, boolean isStatic)

   
         
   
      this.isStatic = isStatic;
      
      if (DesignByContractAspect.verbose) System.out.println("[dbc] Initialising condition: " + condExpr);
      originalExpr = condExpr;
      condExpr += " ";

      StringBuffer newcond = new StringBuffer();
      StringBuffer param = null;

      for (int i  = 0 ; i < condExpr.length() ; i++)
      {
         char c = condExpr.charAt(i);
         if (c == '$")
         {
            param = new StringBuffer();
            continue;
         }
         else if (param != null && (c == '." || c == ' " || c == '=" || c == '>" || c == '<" 
            || c == ')" || c == '}" || c == ';" || c == '[" || c == ']"))
         {
            //Get param name as it was (without the leading '$')
            String prm = param.toString();
            
            if (prm.equals(TARGET) && isStatic)
            {
               //For a static method or static condition, use the class name instead of a parameter
               newcond.append(clazz.getName());
            }
            else
            {
               //Get param name for beanshell
               String bsparam = "p" + i;
               
               newcond.append(bsparam);
               parameterLookup.put(bsparam, prm);               
            }
               
            param = null;
         }

         if (param == null)
         {
            newcond.append(c);
         }
         else
         {
            param.append(c);
         }
      }

      Expression expr = ExpressionParser.parseExpression(newcond.toString());
      BeanshellGenerator gen = new BeanshellGenerator(expr);
      this.condExpr = gen.createBeanshellCode();
      
      if (DesignByContractAspect.verbose) System.out.println("[dbc] Expanded to Java code:\n" + this.condExpr);
      
      this.clazz = clazz;
   
Methods Summary
public booleanequals(java.lang.Object o)

      if (o instanceof Condition)
      {
         Condition c = (Condition)o;
         return c.clazz.equals(clazz) && originalExpr.equals(c.originalExpr);
      }
      
      return false;
   
protected java.lang.ObjectgetTarget(org.jboss.aop.joinpoint.Invocation invocation, boolean isStatic)

      if (!isStatic)
      {
         return invocation.getTargetObject();
      }
      else 
      {
         return clazz;
      }      
   
public inthashCode()

      // TODO Auto-generated method stub
      return originalExpr.hashCode();
   
public java.lang.StringtoString()

      return originalExpr;