You declare the introductions within a class that has been annotated with @Aspect or @InterceptorDef. MyAspect in this example serves no purpose beyond allowing you to define introductions (i.e. it contains no actual advices).
import org.jboss.aop.Introduction; @Aspect public class MyAspect { @Introduction (target=POJO.class, interfaces={java.io.Serializable.class}) public static Object noInterfacesPOJOIntro; ... }
Basically, you just annotate any field within the aspect with @Introduction. The target attribute takes the class you want to introduce interfaces into, and the interfaces attribute takes an array of the interfaces you want to add to the class.
import org.jboss.aop.Mixin; @Aspect public class MyAspect { ... @Mixin (target=POJO2.class, interfaces={java.io.Externalizable.class}) public static POJO2ExternalizableMixin createExternalizableMixin(POJO2 pojo) { return new POJO2ExternalizableMixin(pojo); } }You annotate a public static method within the aspect with @Mixin. The target attribute takes the class you want to introduce interfaces into, and the interfaces attribute takes an array of the interfaces you want to add to the class. The method must take a class of the same type as the target as its parameter, and it must contain the logic to create and return an instance of the mixin class.
import org.jboss.aop.Mixin; @Aspect public class MyAspect { ... @Introduction (typeExpression="class(POJO3) OR class(POJO4)", interfaces={java.io.Serializable.class}) public static Object withTypeExpression; }
$ ant
The output should be:
run: [java] --- POJO --- [java] deserialized pojo.stuff: hello world [java] --- POJO2 --- [java] deserialized pojo2.stuff2: hello world [java] --- POJO3 --- [java] pojo3 introduction expression worked [java] --- POJO4 --- [java] pojo4 introduction expression worked