Wednesday, October 5, 2011

Quick introduction to AspectJ ITD

In this post, I'll show a few examples of AspectJ ITDs that are generated by Spring Roo and the declarations contained in those ITDs. You'll find a more detailed discussion in Chapter 1 (which is available for download) of Spring Roo 1.1 Cookbook.

Example 1: FlightService_Roo_ToString.aj
package sample.roo.flightapp.service;

privileged aspect FlightService_Roo_ToString {
   
    public String FlightService.toString() {
        StringBuilder sb = new StringBuilder();
       sb.append("Origin: ")
         .append(getOrigin());
        return sb.toString();
    }
} 

The following figure shows what the above declaration implies:


Example 2FlightService_Roo_Serializable.aj

package sample.roo.flightapp.service;

import java.io.Serializable;

privileged aspect FlightService_Roo_Serializable {
   
  declare parents: FlightService implements Serializable;
   
  private static final long FlightService.serialVersionUID
      = 5059552858884348572L
}


The following figure shows what the above declaration implies:


No comments:

Post a Comment