[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] how to capture method joinpoints in EJB3 session bean interface?

Here is my suggestion, which I posted to the newsgroup.  Reposting it
here in order to reach the larger audience of the mailing list.

------------
One thing that you can do is create an abstract aspect that defines the
advice and an abstract pointcut.  People who want to use your aspect need to
create a concrete aspect and instantiate the pointcut.

Eg-

abstract aspect AbstractSessionBeanAspect {
  protected abstract pointcut sessionBeanMethods();

  before() : sessionBeanMethods() {
   // do something

  }
}


aspect MySessionBeanAspect extends AbstractSessionBeanAspect {
  protected pointcut sessionBeanMethods() : execution(
SessionBeanInterface.*(..));
}

On Wed, Jul 29, 2009 at 12:31 PM, Andy Clement<andrew.clement@xxxxxxxxx> wrote:
> Well if you can't hardcode the interface name then the you can intercept all
> method executions and then the JoinPoint.StaticPart state to determine at
> runtime if you are interested in it.
> before(): execution(* *(..)) {
>   System.out.println(thisJoinPointStaticPart);
> }
> that may match a lot of places though.  If you can exploit the existence of
> annotations, that may help, something like this to indicate the declaring
> type must have the @Remote annotation.
> before(): execution(* (@Remote *).*(..)) {
>   System.out.println(thisJoinPointStaticPart);
> }
>
> Andy
>
> 2009/7/28 ppkluk <imperfectluk-ppk@xxxxxxxxxxxx>
>>
>> Hi all,
>>
>>  i am new to aspectj and i am trying to write aspect to capture the method
>> of all a session bean (EJB 3.0 syntax).
>>
>>  the methods i want to captures are the 'business method' in the session
>> bean.
>> As EJB 3.0 session bean can be created in the following form:
>>
>> --------------------------------------------------------------
>> //interface defining the session bean method
>> public interface SessionBeanInterface {
>>   public void advicedMethod();
>> }
>> --------------------------------------------------------------
>>
>> @Stateless(name="MySessionBean")
>> @Remote(SessionBeanInterface.class) //indicate SesionBeanInterface is the
>> remote bussinesss interface
>> public class SessionBean implements SessionBeanInterface {
>>
>>   public void advicedMethod(){
>>        //this method to be captured by before execution(...) pointcut
>>
>>   }
>>
>>   public void nonAdvicedMethod() {
>>    //this method is NOT to be captured
>>   }
>> }
>> -------------------------------------------------------------------
>>
>> in this situation, is this possible to write pointcut to capture only the
>> methods declared
>> in the SessionBeanInterface interface??
>>
>> *** i CANNOT HARDCODE the interface type in the aspect as i am now writing
>> a
>> *** generic tool aims to capture all the method execution.
>>
>> thank you.
>>
>> ppkluk
>> --
>> View this message in context:
>> http://www.nabble.com/how-to-capture-method-joinpoints-in-EJB3-session-bean-interface--tp24703854p24703854.html
>> Sent from the AspectJ - users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>