Version 2

    Annotation Introductions

     

    Overview

    This is an extension of the annotation14 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 the JDK 1.5 way, or the JDK 1.4 way. 

     

    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

      $ ant
    

    This should be the output:

    run:
         [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