[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Stop Excution of method.
|
Nuwan, you need to use an around-advice. Inside this advice you can
then put the following:
if(!account.isAccountClosed()){
proceed();
}
So you only proceed with the original call if the account is *not* closed.
Eric
On 20/11/2007, Nuwan Dias <ndias86@xxxxxxxxx> wrote:
>
>
>
> public class Account {
> private double balance;
> private boolean accountClosed = false;
>
> public double getBalance() {
> return balance;
> }
>
> public void setBalance(double balance) {
> this.balance = balance;
> }
>
> public boolean isAccountClosed() {
> return accountClosed;
> }
>
> public void deposit(double amount){
> this.balance +- amount;
> }
> }
>
> public aspect AccountAspect {
> pointcut demo(Account account, double credit) : execution(void
> Account.deposit(double)) &&
>
> target(account) &&
>
> args(credit);
>
> before(Account account, double credit) : demo(account, credit){
>
> if(account.isAccountClosed()){
> //i need something here to stop the deposit method from
> executing.
> }
> }
> }
>
>
> Hi friends,
>
> I have my class Account and Aspect AccountAspect as shown above. The
> account class has a method called deposit. It also has an attribute called
> isAccountClosed. what i need to do is, whenever the deposit method is
> called, i need to check whether the account is closed and if it is closed, i
> need to stop executing the code inside the depoist method. I do not know how
> i can get this done in AspectJ. My main program which calls these methods is
> a class called Bank.java, it just calls the methods in the Account class. I
> would really appreciate it if someone could help me out here.
>
> Thanks in advance,
> Nuwan
>
> ________________________________
> Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it
> now.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
--
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada