Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] joinpoint in interface

In your pointcut expression: 

>   pointcut annotatedFacadeCall(TranslateExceptionToInternal
> translateExceptionToInternal) :
>     @annotation(translateExceptionToInternal)
>     && within(com.salestool.client..*)
>     && call(@TranslateExceptionToInternal StatusResult+
> com.salestool.facade.*.*(..));

Annotation matching in both @annotation and in call is based on the
static type of the receiver - the "subject" of the join point as the
aspectj docs call it. When you change to declare the variable to have
the interface type, the subject of the join point changes (it becomes
the interface operation). 

Changing to use the execution join point is probably what you want
here - this will match annotations based on the thing that actually
gets to execute (the implementation method). It would read something
like this:

pointcut inClientControlFlow() : 
  cflow(execution(* com.salestool.client..*(..));

pointcut annotatedFacadeCall(TranslateExceptionToInternal
translateExceptionToInternal) :
  @annotation(translateExceptionToInternal) &&
  execution(StatusResult+ com.salestool.facade.*.*(..)) &&
  inClientControlFlow();

Regards, Adrian.

On Mon, Feb 12, 2007 at 04:24:47AM -0800, aXXa wrote:
> 
> All!
> My question:
> In the following example, how do I write my pointcut to trigger on any
> implementing classes annotation, i.e. so BOTH A) and B) are adviced (without
> having to annotate the interface) 
> 
> I have the following pointcut defined:
> /** 
>   any method call to facade package returning a subclass of StatusResult and 
>   annotated with TranslateExceptionToInternal
>   from within the client package
> */
>   pointcut annotatedFacadeCall(TranslateExceptionToInternal
> translateExceptionToInternal) :
>     @annotation(translateExceptionToInternal)
>     && within(com.salestool.client..*)
>     && call(@TranslateExceptionToInternal StatusResult+
> com.salestool.facade.*.*(..));
> 
> 
> a method of a class in facade package is annotated...
> public class UserServiceFacadeImpl implements UserServiceFacade {
> 
>   @TranslateExceptionToInternal()
>   public StatusResult saveUpdateUser(user) {
>   }
> }
> 
> ...but NOT its corresponding method in the interface
> public interface UserServiceFacade {
>   public StatusResult saveUpdateUser(user);
> }
> 
> The following works fine, A):
> 
> package com.salestool.client;
> public class MyController {
>   public void myMethod() {
>     UserServiceFacadeImpl userFacadeImpl = new UserServiceFacadeImpl();
>     userFacadeImpl.saveUpdateUser(user); //is adviced
>   }
> 
> BUT since programming against interfaces is good manners I changed the code
> to, B)
> 
>   public void myMethod2() {
>     UserServiceFacade userFacade = new UserServiceFacadeImpl();
>     userFacade.saveUpdateUser(user); //is NOT adviced
>   }  
> }
> 
> 

-- 
Adrian Colyer
CTO
Interface21 Limited
http://www.interface21.com

Registered in England and Wales: No. 5187766 Registered Office: Summit
House, 2-2A Highfield Road, Dartford, Kent, DA1 2JY, UK

E-mails should be checked by the recipient to ensure that there are no
viruses and Interface21 does not accept any responsibility if this is
not done. Any views or opinions presented are solely those of the
author and do not necessarily represent those of Interface21.


Attachment: signature.asc
Description: Digital signature


Back to the top