5 Replies Latest reply on Jun 11, 2008 6:07 PM by Jose Pedro Pereira

    inheritance of aspects

    Fábio Costa Newbie

      I would like to know if some known strategy exists to simulate inheritance of aspects made in aspectj for jboss aop. I am working in a project based on aspectj with this characteristic. The project is very big then I is looking an alternative, instead of implementing the features in all "subclasses" of jboss aop implementation. I already know of two things:
      1 - The @Aspect annotation is not suitable for inheritance
      2 - jboss-aop.xml not accepted the construction <aspect class= " $instanceof {SomeClass} ?/>

        • 1. Re: inheritance of aspects
          Ståle Pedersen Newbie

          hi, i guess this question should be answered by kabir. atm he is on vacation, but he will answer you when he's back.
          in the meantime i guess you have to add @Aspect on all subclasses (i dont know how many classes you got, but hopefully its not too big of a job :)

          • 2. Re: inheritance of aspects
            Flavia Rainone Newbie

            Hi,
            It is not allowed to put an expression in the 'class' attribute of 'aspect' tag.
            Still, you can simulate the inheritance of aspect advices. As Stalep said, you need to declare the subclasses as aspects in the xml file, and declare the bindings like in the following example.

            >>>>> ASPECTS
            
            class MyAspect1 extends MySuperAspect
            {
             public Object advice(Invocation invocation) throws Throwable
             {
             // do something I want to and then invoke super aspect
             return super.advice(invocation);
             }
            }
            
            class MyAspect2 extends MySuperAspect
            {
             public Object advice(Invocation invocation) throws Throwable
             {
             // do only what I want to, don't call super aspect
             .....
             return invocation.invokeNext();
             }
            }
            
            public abstract class MySuperAspect
            {
             public Object advice(Invocation invocation) throw Throwable
             {
             ....
             }
            }
            
            >>>>> XML FILE
            
            <?xml ....?>
            <aop>
             <aspect class="MyAspect1" scope="PER_VM" />
             <aspect class="MyAspect2" scope="PER_VM" />
            
             <bind pointcut=">whatever you want here<" />
             <advice name="advice" aspect="MyAspect1"/>
             <advice name="advice" aspect="MyAspect2"/>
             </bind>
            </aop>
            


            Notice MySuperAspect can also be an interface or a concrete class.

            • 3. Re: inheritance of aspects
              Fábio Costa Newbie

              Good solution, thank you.

              • 5. Re: inheritance of aspects
                Jose Pedro Pereira Newbie

                But what if one is using the annotations based approach, do you inherit Pointcuts defined in the super abstract class?