Announcement Announcement Module
Collapse
No announcement yet.
Args pointcut with at least 1 matching param in undefined order wanted Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Args pointcut with at least 1 matching param in undefined order wanted

    Hi,

    i want to define a pointcut which matches all public methods of a certain packacke with at least one certain run-time parameter passed as argument to such a method. Example:

    execution (public * my.simple.packacke..*(..)) and (args(authorizable))

    This works for all methods that have exactly one parameter of type "my.simple.interfaces.Authorizable". But of course later on a developer could introduce a new method into the above package with a signature like this
    my.simple.packacke.MyClass#foo(int i, Authorizable authorizable). Now the aspect handling the authorization mechanism would not be called.

    So i need a way to define all methods in a desired package with at least one (or more) parameters passed which are of type X. Something like (args(*, authorizable, *)). But this and other combinations doesn't seem to work. I tried:
    - args(*, authorizable, *) - no error but also no match *grr*
    - args(authorizable, ..) - matches only if the first param is of type Authorizable
    - args(authorizable) or args(*, authorizable) or (authorizable, *) - matches only if the first or last param is of type Authorizable or there is only one param of type Authorizable.

    Of course i could implement the aspect in a way that it determines if a param is of type Authorizable via the JoinPoints#getArgs() method. This already works, but i would be a bit more satisfied if i could constrain the pointcut expression.

    TIA for any ideas,
    Dirk
    Last edited by unknown12; Jan 25th, 2008, 04:10 AM.

  • #2
    Try:

    Code:
    execution (public * my.simple.package..*(..,authorizable,..))

    Comment


    • #3
      Doesn't work

      The special wildcard '..' may be used only once in such an expression.

      Comment


      • #4
        Well - I'm pretty new to AOP (completely new to AspectJ style pointcut expressions), so I wrote some test cases before replying above. In my test case, I have:

        Code:
        <aop:config>
        	<aop:aspect ref="testAdvice">
        		<aop:before method="foo" pointcut="execution(* test..*(..,test.Foo,..))" />
        	</aop:aspect>
        </aop:config>
        This works perfectly in my tests.

        However, if you say it doesn't work for you, then it doesn't work - I'll leave it for someone more experienced with AOP. I'd be interested to see the suggested solution.

        Comment

        Working...
        X