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); ? ? } }
|