3 Replies Latest reply on Mar 12, 2004 4:37 PM by bill.burke

    Interception of Superclass and Interfaces

    alex_brasil

      Hi,

      Is there any way of intercepting the methods of an interface implementation or to intercept a subclass of some declared superclass?

      For example: I have two classes, A and B, and B extends A. Is there any way of intercepting calls to an instance of B by declaring an interceptor to class A (superclass).

      Likewise, if A was an interface, is there anyway of intercepting its methods implementations on B?

      If these features are not implemented yet, is there any predictions on when (or if) they will get done?

      Thanks,
      Alex

        • 1. Re: Interception of Superclass and Interfaces
          bill.burke

          In DR2 you can do the following

          class A
          {
          public void method1() {..}
          }

          class B extends A {}

          method1 will be intercepted if you declare a methoind-pointcut on A.method1.

          DR3 has been improved tremoundously. You can do instanceof in the pointcut expression. DR3 will be out next Wednesday.

          DR3 example:

          interface A
          {
          void method1();
          }

          public class B implements A {...}

          [bind pointcut="execution(void $instanceof{A}->method1())"]
          [interceptor class="SOmeInterceptor"/]
          [/bind]

          Bill

          • 2. Re: Interception of Superclass and Interfaces
            alex_brasil

            First of all, thanks for the fast answer.

            "Bill Burke" wrote:

            In DR2 you can do the following

            class A
            {
            public void method1() {..}
            }

            class B extends A {}

            method1 will be intercepted if you declare a methoind-pointcut on A.method1.


            That I already knew, but what if B overide method1()? Will DR3 provide a way to catch the overiden method as well?

            "Bill Burke" wrote:

            DR3 has been improved tremoundously. You can do instanceof in the pointcut expression. DR3 will be out next Wednesday.

            DR3 example:

            interface A
            {
            void method1();
            }

            public class B implements A {...}

            [bind pointcut="execution(void $instanceof{A}->method1())"]
            [interceptor class="SOmeInterceptor"/]
            [/bind]

            Bill


            That's cool. Will it work for subclasses as well? Is there any document where I can learn more about the "bind" pointcut and "$instanceof" operator in JBossAOP?

            Thanks,
            Alex

            • 3. Re: Interception of Superclass and Interfaces
              bill.burke

              Doco for DR3? Working on it right now. If you checkout CVS head

              cvs checkout jboss-head

              $ cd jboss-head/aop
              $ build dist

              You will get a zip dist. In the dist docs/examples directory there are a bunch of examples. I'll be adding to this and documenting each example as well as updating all the doco on our website.

              Next week these examples will be on our wiki as well as other doco on JBoss AOP DR3.

              Bill