Results 1 to 2 of 2

Thread: Matching against specific methods from classes from multiple packages

  1. #1
    Join Date
    Sep 2009
    Posts
    4

    Default Matching against specific methods from classes from multiple packages

    Hi,

    I am trying to write a pointcut expression that will allow a method in an aspect class to be invoked based upon matching a variable class structure & specific method names. An example of what I'm trying to achieve is as follows:

    Classes to be matched on by pointcut expression:

    com.travelagent.reservation.service.dao.BookingDao .add(...)
    com.travelagent.client.service.dao.ClientDao.add(. ..)

    I have tried the following pointcut expressions (which don't appear to work):

    @Before("execution(* *Dao.add(..))")
    @Before("execution(* com.travelagent.*.*.dao.Dao.add(..))")

    I have also thought about making all the DAOs extend an abstract class which in turn implements and interface and writing a rule based upon this, but I'd appreciate knowing if I can write a generic pointcut expression which can do regular expression matching on the beginning and ending of package structures, combined with a regular expression on the class name and a named method i.e. add?

    Appreciate your advise.

    Many Thanks,

    Mark

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Please use [ code[/code] tags when posting code that way it remains readable.

    Your second pointcut is wrong so that will never match (it will only match a class named Dao which has an add method). Also read my other reply as to when and where aspects apply...

    I strongly suggest a read of the reference guid eon how Spring AOP works. Also the pointcut isn't a regular expression it is writting in the pointcut language (so I suggest a readup on AspectJ as well)...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •