## Typedefs

If you have several classes that all are going to be intercepted in a similar way, you can declare a typedef to avoid declaring different pointcuts for each class. The typedef must resolve to a class expression.

      <typedef name="TD" expr="(class(POJO) AND has(* *->method(..))) OR class($instanceof{ExecutionTypedefInterface}) OR class(@executionTypedef)" />

The typedef can then be used in place of the class name in pointcuts

      <bind pointcut="execution($typedef{TD}->new())">
        <interceptor class="SimpleInterceptor" />
      </bind>
      <bind pointcut="execution(* $typedef{TD}->method())">
        <interceptor class="SimpleInterceptor" />
      </bind>
      <bind pointcut="field(* $typedef{TD}->field1)">
        <interceptor class="SimpleInterceptor" />
      </bind>
      <bind pointcut="all($typedef{TD})">
        <interceptor class="SimpleInterceptor2" />
      </bind>

In the supplied example POJO is not annotated and does not implement ExecutionTypedefInterface. POJO2 implements ExecutionTypedefInterface, and POJO3 is annotated with @executionTypedef.

#### Run the example

To compile and run:

      $ ant

It will javac the files and then run the AOPC precompiler to manipulate the bytecode, then finally run the example. The output should read as follows:

    run:
         [java] --- new POJO(); ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- pojo.field1 = 10; ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- get pojo.field1;---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- pojo.method(); ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor

         [java] =======================

         [java] --- new POJO2(); ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- pojo2.field1 = 10; ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- get pojo2.field1; ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- pojo2.method(); ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor

         [java] =======================

         [java] --- new POJO3(); ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- pojo3.field1 = 10; ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- get pojo3.field1; ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor
         [java] --- pojo3.method(); ---
         [java] <<< Entering SimpleInterceptor
         [java] <<< Entering SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor2
         [java] >>> Leaving SimpleInterceptor

POJO, POJO2 and POJO3 all get intercepted the same.