Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] RE: Regarding weaving Java Programs

HI all,

 

I got the answer myself when I tried out the same example by removing statics. Hence whether static or not, we need to write in the same way!! AspectJ does not show a distinction on whether static or not. It just looks for that method. Hats off to aspectj!!

 

Regards,

Ravi

 

-----Original Message-----
From: ravishankar, narayanan nair
Sent: Monday, March 01, 2004 9:27 PM
To: 'aspectj-users@xxxxxxxxxxx'
Subject: Regarding weaving Java Programs

 

Hi all,

 

I have just started using AspectJ and was going through the initial newbie examples:

 

I have a class called MessageCommunicator as follows:

public class MessageCommunicator

{

            public static void deliver(String message)

            {

                        System.out.println(message);

            }

            public static void deliver(String person, String message)

            {

                        System.out.println(person+"!, "+ message);

            }

}

 

Now I have a test program:

 

public class Test

{

            public static void main(String[] args)

            {

                        MessageCommunicator.deliver("WELCOME TO AOP");

                        MessageCommunicator.deliver("Ravi" , "Wonderful Technology");

            }

 

}

Now I am weaving MessageCommunicator with my MannersAspect as:

 

public aspect MannersAspect

{

            pointcut deliverMessage()

                                    : call(* MessageCommunicator.deliver(..));

 

            before() : deliverMessage()

            {

                        System.out.print("Inserting with AOP ---->  ");

            }

}

 

Everything is working fine when I compile with ajc and output is as expected.

 

My question is, had the method “deliver” in MessageCommunicator been NOT STATIC, how could I achieve the same result, please help. Thanks

 

Best regards,

Ravi

 


Back to the top