PDA

View Full Version : access joinpoint object from before advice



hatsch1209
Jul 9th, 2007, 06:08 AM
Hi all,
I searched this forum but unfortunately I couldn't find an approritate answer for my simple problem.
I have an Account class and for each method of this class authentication is needed.

I want to use a before Advice with the schema definition. But I have no idea how I can pass the account object to the advice. In the documentation I read that "this" should work in this case, but it does not. 'account' is not found. If I change "..this(account)" to "this(banking.Account)" there is no error, but I cannot access the account-object from within the advice.



<bean class="banking.Account" id="account"></bean>
<bean id="authentication" class="authentication.Authentication"></bean>
<aop:config>
<aop:aspect ref="authentication">
<aop:before method="authenticate"
pointcut="execution(* banking.Account.*(..)) and this(account) "
arg-names="account" />
</aop:aspect>
</aop:config>

thx in advance, Hatsch

Andrei Stefan
Jul 10th, 2007, 09:34 AM
This thread (http://forum.springframework.org/showthread.php?t=39848) discusses a similar issue.

hatsch1209
Jul 11th, 2007, 04:39 AM
Thank you for your reply, although this thread does not solve this issue with a before advice (it uses around advice instead).
I solved it with changing the parameter from Authentication.autenticate(Account account) to authenticate(JoinPoint jp) and cast it to Account within the method.
I do explicitly need the before advice because I'm working on a AOP-tools comparison, and transfer the same example to different solutions.