1 Reply Latest reply on Aug 18, 2009 8:05 AM by kabirkhan

    How do you get the superclass from the Invocation object?

    dermas

      I think I should show you a simple example code:

      
      public class A{
       @InterceptMe
       public void sayHello(){
       System.out.println("hello");
       }
      }
      
      public class B extends A{
       @InterceptMe
       public void sayHello(){
       super.sayHello();
       System.out.println("foo");
       }
      }
      
      jboss-aop.xml
      
      <aop>
       <bind pointcut="execution(* *->@aop.InterceptMe(..))">
       <interceptor class="aop.TheInterceptor" scope="PER_VM"/>
       </bind>
      </aop>
      
      


      Ok, so basically every method with the InterceptMe Annotation ist intercepted by TheInterceptor (great name isnt it? ^^).

      In this Interceptor every method ist called again with reflection (doesnt make much sense in this example, but for my project). Now the problem is, that if super.sayHello() is called, the Invocation class does still give me class B if I call myInvocation.getTargetObject(). This is a problem when invoking the method with reflection (method is invoked on the wrong class B instead of class A).

      Any idea how I can get the superclass?

        • 1. Re: How do you get the superclass from the Invocation object
          kabirkhan

          If the target is an instance of B, there is nothing you can do to call A's method instead if it is overridden by B.

          The super.sayHello() becomes an invokespecial bytecode instruction rather than the normal invokevirtual/invokeinterface, which I guess the jvm takes to mean calling the actual method specified rather than the "lowest" which is the normal behaviour.

          So, from your point of view I don't think there is much that can be done.