1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
public aspect LogCreditCardProcessorOperations
{ Logger logger = new StdoutLogger();
pointcut publicOperation():
execution(public * CreditCardProcessor.*(..));
pointcut publicOperationCardAmountArgs(CreditCard card, Money amount):
publicOperation() && args(card, amount);
before(CreditCard card, Money amount):
publicOperationCardAmountArgs(card, amount)
{ logOperation("Starting", thisjoin point.getSignature().toString(), card, amount);
}
after(CreditCard card, Money amount) returning:
publicOperationCardAmountArgs(card, amount)
{ logOperation("Completing", thisjoin point.getSignature().toString(), card, amount);
}
after (CreditCard card, Money amount) throwing (Exception e):
publicOperationCardAmountArgs(card, amount)
{ logOperation("Exception " + e, thisjoin point.getSignature().toString(), card, amount);
}
private void logOperation(String status, String operation, CreditCard card, Money amount)
{ logger.log(status + " " + operation + " Card: " + card + " Amount: " + amount);
}
} |
Partager