Skip to main content

[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 could use declare parents to make your matching interfaces extend
another marker interface. E.g.,

public static interface Transactional {}

// you can have declarations like this in one place or in as many separate
places as you like
@DeclareParents(value="com.foo.interface.A || com.foo.interface.B || …")
        private Transactional implementedInterface;

then you can use
  @Pointcut("execution(* Transactional+.* (..))")
  public void transactionalOperation() {
  }

Hope that helps,
Ron

________________________________________
From: aspectj-dev-bounces@xxxxxxxxxxx
[mailto:aspectj-dev-bounces@xxxxxxxxxxx] On Behalf Of Jean Bovet
Sent: Thursday, October 26, 2006 10:15 AM
To: AspectJ developer discussions
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





Back to the top