《AspectJ Cookbook》讀書筆記六: 捕獲通知上的連接點(diǎn)
一. 捕獲何時(shí)執(zhí)行通知
使用adviceexecution()切入點(diǎn)。adviceexecution()切入點(diǎn)的語法如下:
pointcut <pointcut name>() : adviceexecution();
package com.aspectj;

public aspect AdviceExecutionRecipe
{
/*
Specifies calling advice whenever advice is executed
*/
pointcut adviceExecutionPointcut() : adviceexecution();

// Advice declaration
before() : adviceExecutionPointcut()
{
System.out.println(
"------------------- Aspect Advice Logic --------------------");
System.out.println("In the advice picked by ExecutionRecipe");
System.out.println(
"Signature: "
+ thisJoinPoint.getStaticPart().getSignature());
System.out.println(
"Source Line: "
+ thisJoinPoint.getStaticPart().getSourceLocation());
System.out.println(
"------------------------------------------------------------");
}
}
二. 排出作為通知執(zhí)行結(jié)果的連接點(diǎn)
三. 在發(fā)出通知時(shí)展示原始連接點(diǎn)
添加JoinPoint標(biāo)識(shí)符到切入點(diǎn)定義中。
package com.aspectj;

import org.aspectj.lang.JoinPoint;

public aspect AdviceExecutionRecipe
{
/*
Specifies calling advice whenever advice is executed
*/
pointcut adviceExecutionPointcut(JoinPoint originalJoinPoint) : adviceexecution() && args(originalJoinPoint) && !within(AdviceExecutionRecipe);

// Advice declaration
before(JoinPoint originalJoinPoint) : adviceExecutionPointcut(originalJoinPoint)
{
System.out.println(
"------------------- Aspect Advice Logic --------------------");
System.out.println("In the advice picked by AdviceExecutionRecipe");
System.out.println(
"Signature: "
+ thisJoinPoint.getStaticPart().getSignature());
System.out.println(
"Source Line: "
+ thisJoinPoint.getStaticPart().getSourceLocation());
System.out.println(
"Advised Advice's Join Point Signature: "
+ originalJoinPoint.getSignature());
System.out.println(
"------------------------------------------------------------");
}
}
使用adviceexecution()切入點(diǎn)。adviceexecution()切入點(diǎn)的語法如下:
pointcut <pointcut name>() : adviceexecution();


























二. 排出作為通知執(zhí)行結(jié)果的連接點(diǎn)
三. 在發(fā)出通知時(shí)展示原始連接點(diǎn)
添加JoinPoint標(biāo)識(shí)符到切入點(diǎn)定義中。

































posted on 2008-08-29 16:09 Brian 閱讀(375) 評(píng)論(0) 編輯 收藏 所屬分類: 《AspectJ Cookbook》讀書筆記