遵循特定的語法用于捕獲每一個(gè)種類的可使用連接點(diǎn)。
主要的種類:
- 方法執(zhí)行:execution(MethodSignature)
- 方法調(diào)用:call(MethodSignature)
- 構(gòu)造器執(zhí)行:execution(ConstructorSignature)
- 構(gòu)造器調(diào)用:call(ConstructorSignature)
- 類初始化:staticinitialization(TypeSignature)
- 屬性讀操作:get(FieldSignature)
- 屬性寫操作:set(FieldSignature)
- 例外處理執(zhí)行:handler(TypeSignature)
- 對(duì)象初始化:initialization(ConstructorSignature)
- 對(duì)象預(yù)先初始化:preinitialization(ConstructorSignature)
- Advice執(zhí)行:adviceexecution()
主要包括兩種類型的控制流:
cflow(Pointcut),捕獲所有的連接點(diǎn)在指定的方法執(zhí)行中,包括執(zhí)行方法本身。
cflowbelow(Pointcut),捕獲所有的連接點(diǎn)在指定的方法執(zhí)行中,除了執(zhí)行方法本身。
如以下的例子:
cflow(call(* Account.debit(..))
所有的debit方法中的連接點(diǎn),包括debit方法本身
cflowbelow(call(* Account.debit(..))
所有debit方法中的連接點(diǎn),除了debit方法本身
cflow(transactedOperations())
所有由transactedOperations捕獲的連接點(diǎn)
cflowbelow(execution(Account.new(..))
所有在Account 構(gòu)造器中執(zhí)行的連接點(diǎn)
基于詞匯結(jié)構(gòu)的連接點(diǎn)
源代碼片斷。,如within()和withincode()
within :捕獲在指定類或者方面中的程序體中的所有連接點(diǎn),包括內(nèi)部類。
Withincode:用于捕獲在構(gòu)造器或者方法中的所有連接點(diǎn),包括在其中的本地類
執(zhí)行對(duì)象連接點(diǎn)
匹配this,和target對(duì)象,作為方法被調(diào)用的對(duì)象。
this(Account),所有Account的實(shí)例的執(zhí)行點(diǎn),匹配所有的連接點(diǎn),如方法調(diào)用,屬性設(shè)置,當(dāng)前的執(zhí)行對(duì)象為Account,或者其子類。
target(Account):匹配所有的連接點(diǎn),目標(biāo)對(duì)象為Account或其子類。
必須執(zhí)行相應(yīng)的類型,不能使用*,或者..通配符。當(dāng)前靜態(tài)方法,不能被匹配。
在within()和this()中的區(qū)別:
一個(gè)是程序體,而另一個(gè)為對(duì)象執(zhí)行。
參數(shù)pointcuts
用于捕獲參數(shù)類型的連接點(diǎn)。
args(String,..,int)
args(RemoteException)
條件檢測(cè)pointcuts
if(System.currentTimeMillis()>triggerTime)