ExecutableConditionpublic abstract class ExecutableCondition extends Condition
Constructors Summary |
---|
public ExecutableCondition(String condExpr, Class clazz, boolean isStatic)
super(condExpr, clazz, isStatic);
|
Methods Summary |
---|
public void | evaluateCondition(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.Object | executableObject()
| protected abstract java.lang.Object | getValueForPredefinedToken(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Object rtn, java.lang.String token)
| protected java.lang.Object | getValueForToken(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 boolean | isPredefinedToken(java.lang.String token)
| protected abstract java.lang.Class[] | parameterTypes()
| public java.lang.String | toString()
return executableObject() + ":" + super.toString();
|
|