Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Stop Excution of method.



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.

Back to the top