Announcement Announcement Module
Collapse
No announcement yet.
How to distingish pointcut parameters in case of || expresion? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to distingish pointcut parameters in case of || expresion?

    Hello

    I want my advise to be executed when target Class or method annotated with MyAnnotation. Also I want to access MyAnnotation attributes.

    Question:
    How to distingish pointcut parameters in case of || expresion?

    I tried two variants

    @AfterThrowing(pointcut = "@annotation(m)||@target(m)")
    public void annotatedWith(MyAnnotation m) {
    //...
    }


    and

    @AfterThrowing(pointcut = "@annotation(m)||@target(s)")
    public void annotatedWith(MyAnnotation m,MyAnnotation s) {
    //...
    }


    both do not work.

    Thanks in advance.

  • #2
    The first expression doesn't work as the binding could be ambiguous: Which annotation should AspectJ bind if an annotation of MyAnnotation type is present for both the target object's type and the selected join point?

    The second expression doesn't work as the binding is potentially inconsistent: One of the collected annotation will have to be null if an annotation of MyAnnotation type is present for either the target object's type and the selected method but not both.

    Solution: Use two advice and call a method from them to do carry the advice logic.

    -Ramnivas

    Comment


    • #3
      First of all, thank you very much, your solution works! ;-)

      Originally posted by ramnivas View Post
      The first expression doesn't work as the binding could be ambiguous: Which annotation should AspectJ bind if an annotation of MyAnnotation type is present for both the target object's type and the selected join point?
      I think in this case should exist a rule of choosing. In this case I'd choose target method over target class. By doing so we could have the ability to annotate a class and override annotation in methods.

      Originally posted by ramnivas View Post
      The second expression doesn't work as the binding is potentially inconsistent: One of the collected annotation will have to be null if an annotation of MyAnnotation type is present for either the target object's type and the selected method but not both.
      I see nothing bad if one of paremeters that came to method will be null.
      If that solution worked a developer could override one annotation by another and complement as well.

      Originally posted by ramnivas View Post
      Solution: Use two advice and call a method from them to do carry the advice logic.
      Once again thank you Mr. Ramnivas ;-) I'm noob in AOP and your help came right at time.
      Last edited by Plastics; Aug 2nd, 2007, 01:39 PM.

      Comment

      Working...
      X