[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Specifying pointcuts in an external file


Jean,

You need a pointcut library. You _will_ have to update the library each time you add an interface to you application but you won't have to change the aspect. Also the library can be shared between aspects.

public class HelloWorld {

        public static void main(String[] args) {
                System.out.println("Hello World!");
        }

}


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class AtAspect {
//        @Pointcut("execution(public void main(String[]))")
//        public void mainMethod () {
//        }

        @Before("(PointcutLibrary.mainMethod())")
        public void beforeMainMethod (JoinPoint.StaticPart thisJoinPointStaticPart, JoinPoint thisJoinPoint) {
                System.out.println("AtAspect.beforeMainMethod() " + thisJoinPoint);
        }

}


import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

//@Aspect
public class PointcutLibrary {
        @Pointcut("execution(public void main(String[]))")
        public void mainMethod () {
        }

}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



"Jean Bovet" <jbovet@xxxxxxxxx>
Sent by: aspectj-dev-bounces@xxxxxxxxxxx

26/10/2006 18:15

Please respond to
AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>

To
"AspectJ developer discussions" <aspectj-dev@xxxxxxxxxxx>
cc
Subject
Re: [aspectj-dev] Specifying pointcuts in an external file





Yes, my question was probably not so clear. Let me take an example.

Let's say that I want to weave all methods declared by an interface, I will have to write the following pointcut:

 @Pointcut("execution(* com.foo.interface.a..*(..))")
 public void anyFooInterfaceA() {
 }

And then I write the advice:

 @Before("(anyFooInterfaceA())")
 public void beforeAnyInterface(JoinPoint.StaticPart thisJoinPointStaticPart, JoinPoint thisJoinPoint) {
 ...


Now let say I need to apply the same advice for more interfaces, the pointcut will become:

 @Pointcut("(execution(* com.foo.interface.a..* (..)) && execution(* com.foo.interface.b..*(..)) && execution(* com.bar.interface.c..*(..)))")
 public void anyFooOrBarInterfaces() {
 }
 
The project I am working on requires a lot of interfaces to be weaved and more interfaces will be added in the future. I am trying to find an easy way to add all the existing interfaces (and the future ones) into my aspect class without having (1) huge pointcut definition or (2) to modify the aspect code each time a new interface that need to be weaved is added. Is there an elegant way to achieve that? Or is there a way to specify an external file that will contain the list of pointcut to take into consideration for a specific advice. For example:

@Before(file="pointcut.txt")

Thanks a lot

Regards,

Jean
 

On 10/25/06, Matthew Webster < matthew_webster@xxxxxxxxxx> wrote:

Jean,


I am not sure I fully understand your question. Are you writing pointcuts that match annotations declared in the classes you wish to advise? I this statement puzzles me: "
each time a pointcut changes, I will have to change the annotation". Can you post an example of what you are trying to do?

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB,
matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/

"Jean Bovet" <jbovet@xxxxxxxxx>
Sent by:
aspectj-dev-bounces@xxxxxxxxxxx

23/10/2006 21:01

Please respond to
AspectJ developer discussions <
aspectj-dev@xxxxxxxxxxx>


To
aspectj-dev@xxxxxxxxxxx
cc
Subject
[aspectj-dev] Specifying pointcuts in an external file







Hi,

Is it possible to specify pointcuts in an external file when using the annotation AspectJ? I am asking this question because our project will contain a lot of different pointcuts: what is the easiest way to define them? Using annotation is a bit a pain because each time a pointcut changes, I will have to change the annotation. Any method to load these pointcuts from an external source?

Thanks for any help,

Jean

_______________________________________________
aspectj-dev mailing list

aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list

aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev