public class Transaction{
public Boolean doInsert(Integer accountNumber, Double amount){
//.
//.
//.
return boolVal;
}
}
To define a point cut for the same, the below aspect can be used.
public aspect TransactionAspect {
pointcut t1(Transaction t, Integer accountNumber) :
target(t) && args(accountNumber,..) &&
execution(* *(Integer,..));
before(Transaction t, Integer accountNumber) : t1(t, accountNumber){
if(!isDoAbleForAccount(t,accountNumber)){
throw new RuntimeException("Error : Detected error before transacting");
}
}
private boolean isDoAbleForAccount(Transaction t,Integer accountNumber){
//
//
}
}
The above aspect defines a pointcut named t1 with 2 parameters. The first parameter is the Transaction object itself which is the target object in execution, the second parameter is an Integer account number that is passed as an argument to the doInsert method. Note the syntax of the "args" in the pointcut. It has one to one mapping to the execution pattern "* *(Integer,..)" which defines any method, with any return value, but 1st argument as Integer and any number of remaining argument. The before advice uses this pointcut, and the remaing code is just not that important.
There is a one to one mapping for arguments between the "args" and the pattern used to select method's from a target object.