Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] perthis and binding on super class.

Title: perthis and binding on super class.

Hi All,

I'm having some issues solving a problem and was hoping someone could give some assistence.

I'm want to bind on the execution of a method in a super class and the perthis on the subclass.  For example, say we have the following:


        ______________________
        |       <<abstract>>      |
        |                         |
        |       Vehicle           |
        |-------------------------------------|
        |-------------------------------------|
        | + <final> stop():void   |
        |_____________________|
                           /\
                      /_ \
                        |
                        |
                        |
                            |
        _____________________
        |                       |
        |         Car           |
        |-----------------------------------|
        |-----------------------------------|
        |____________________|

I want to bind on the execution (not call as this is a packaged library) of say, the stop method.  However I want one aspect instance for each car object.  I would have thought it was something like this:

public aspect CarStopping perthis( execution ( Car.new() ) ){

        private boolean shouldNotify = false;

        public boolean getShouldNotify(){
                return shouldNotify;
        }

        public void setShouldNotify(boolean flag) {
                this.shouldNotify = flag;
        }

        pointcut stopCalled() : execution( void Vehicle.stop() );

        after() : stopCalled(){
                if(shouldNotify) System.out.println("Car stopped");
        }
}

And I could do something like:

        Car c = new Car();
        CarStopping stopping = CarStopping.aspectOf(c);
        stopping.setShouldNotify(true);
        car.stop();

But this solution doesn't work for me, which leads me to believe I'm doing something wrong.

Now, of course this is not the exact code I'm trying to get working as I have no real need to know anything about cars...it just demonstrated (I hope) what I'm trying to accompish.  Does anybody know of a good solution?

Cheers
Adam

Important notice: This message is intended for the individual(s) and entity(s) addressed. The information contained in this transmission and any attached, may be confidential and may also be the subject of legal privilege, public interest immunity or legal professional privilege. Any review, retransmission, dissemination or other use of, taking of any action in reliance upon this information by person or entities other than the recipient is prohibited and requires authorization from the sender. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person) you may not copy or deliver this message to anyone. In such cases you should destroy this message and kindly notify the sender by reply email.

WARNING: Although Infocomp has taken reasonable precautions so that no viruses are present in this e-mail, the company cannot accept responsibility for any loss or damage arising from the use of e-mail attachments.


Back to the top