Results 1 to 4 of 4

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

  1. #1
    Join Date
    Jan 2008
    Posts
    2

    Default 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 at 04:10 AM.

  2. #2
    Join Date
    Jan 2008
    Location
    Southampton, UK
    Posts
    14

    Default

    Try:

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

  3. #3
    Join Date
    Jan 2008
    Posts
    2

    Default Doesn't work

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

  4. #4
    Join Date
    Jan 2008
    Location
    Southampton, UK
    Posts
    14

    Default

    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.
    Chris Davies

Posting Permissions

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