Annotation Introductions

Overview

This is an extension of the annotation example. In this example, instead of declaring an annotation within the Java source file, we introduce an annotation through an XML descriptor. This XML descriptor has the same effect as declaring an annotation.

Example code

The example code declares annotations via doclets within POJO.java. Single.java, Trace.java, and Complex.java all represent our annotation interfaces. The TraceInterceptor traces method, field, and constructor calls on POJO and outputs the annotations tagged on those members;

Applying an Annotation Introduction

jboss-aop.xml

   <annotation-introduction expr="constructor(POJO->new())">
      @Complex (ch='a', string="hello world", flt=5.5, dbl=6.6, shrt=5, lng=6, integer=7, bool=true, annotation=@Single("hello"), array={"hello", "world"}, clazz=java.lang.String)
   </annotation-introduction>

It is pretty simple, define an expression within the expr attribute. constructor(), method(), class(), and field() all take a corresponding expression of that type. You can also use the has() and hasfield() operators as well if you wish and any boolean expression with those 6 operators.

Running

To compile and run (for further detail, refer to our Compiling and Running Examples Guide):

  $ ant run.aopc

It will javac the files and then run the AOPC precompiler to manipulate the bytecode, then finally run the example. The output should be similar to this:

_run.aopc:
     [java] --- new POJO(); ---
     [java] @Single ("hello world")
     [java] @Complex (ch='a', "hello world", flt=5.5, dbl=6.6, ...blah blah blah YOU GET THE IDEA...
     [java] <<< Trace : executing constructor public POJO()
     [java] empty constructor
     [java] >>> Leaving Trace
     [java] --- pojo.someMethod(); ---
     [java] @Single ("hello world")
     [java] @Complex (ch='a', "hello world", flt=5.5, dbl=6.6, ...blah blah blah YOU GET THE IDEA...
     [java] <<< Trace : executing method public void POJO.someMethod()
     [java] someMethod
     [java] >>> Leaving Trace
     [java] --- pojo.field = 55;  ---
     [java] @Single ("hello world")
     [java] @Complex (ch='a', "hello world", flt=5.5, dbl=6.6, ...blah blah blah YOU GET THE IDEA...
     [java] <<< Trace : write field name: public int POJO.field
     [java] >>> Leaving Trace