1 Reply Latest reply on Jun 13, 2007 6:09 AM by Kabir Khan

    Annotations for Typed Advices

    Flavia Rainone Master

      Hello everyone!

      One of the great features we are adding to JBoss AOP 2.0 are the typed advices (before/after/after-throwing/finally). Currently, only the configuration of those by xml is implemented:

      <bind pointcut="pointcut expression">
       <before name="advice name" aspect="aspect class name"/>
      </bind>
      
      <bind pointcut="pointcut expression">
       <after name="advice name" aspect="aspect class name"/>
      </bind>
      
      <bind pointcut="pointcut expression">
       <throwing name="advice name" aspect="aspect class name"/>
      </bind>
      
      <bind pointcut="pointcut expression">
       <finally name="advice name" aspect="aspect class name"/>
      </bind>


      For consistency on nomenclature, we added the tag around to represent around advices:
      <bind pointcut="pointcut expression">
       <around name="advice name" aspect="aspect class name"/>
      </bind>


      The old tag advice will continue to be supported of course and, since we have more than one type of advice now, we say that using this tag is equivalent to using the default type of advice: around.

      Now we are defining the annotation API for typed advice bindings. Currently, this API consists solely of @Bind annotation and supports only around interception:
      public @interface Bind
      {
       String pointcut();
       String cflow() default "";
      }


      The question here is how to extend this API to support typed advices. I am not sure of which approach would be better:

      1- We can define annotations @Before, @After, @Throwing and @Finally whose signature/implementation would be equal to the @Bind annotation above. Eventually we could think of writing @Around for uniformity.

      2-We can add a parameter to @Bind:
      AdviceType type() default AdviceType.AROUND;

      The first solution mix bindings (@Bind) with advice types (@Before, @After, etc). but looks shorter.
      The second solution specify advice types as a parameter of Bind, that probably makes more sense, but will demand more typing from users.

      Any thoughts on which solution would be better?