Out of dateThis documentation is a bit out of date. For better documentation please see the wiki . This documentation will be updated before the 1.0 release. UsageBuilding an aspected objectThis builds an aspected object consisting of two mixins one implementing the interface Intf and the other implementing SideAspect. Both mixins have the interceptors MockInterceptor and NullInterceptor applied to all methods.
AspectInstance aspectInstance = new AspectInstance();
MixinInstance mixinInstance = new MixinInstance();
mixinInstance.setInterfaceClass(Intf.class);
mixinInstance.addInterceptor(new MockInterceptor());
mixinInstance.addInterceptor(new NullInterceptor());
mixinInstance.setTarget(new Impl());
aspectInstance.addMixin(mixinInstance);
MixinInstance sideMixinInstance = new MixinInstance();
sideMixinInstance.setInterfaceClass(SideAspect.class);
sideMixinInstance.addInterceptor(new NullInterceptor());
sideMixinInstance.addInterceptor(new MockInterceptor());
sideMixinInstance.setTarget(new SideAspectImpl());
aspectInstance.addMixin(sideMixinInstance);
Object bigMomma = aspectInstance.getProxy();
Intf intf = (Intf) intf;
intf.call();
SideAspect sideAspect = (SideAspect) intf;
sideAspect.call();
Using runtime attributesThis is an example from the unit-tests: The class (with the attributes):
/**
* @classAttribute classValue
*/
public class AttributesTestClass
{
/**
* @fieldAttribute fieldValue
*/
public String field;
/**
* @methodAttribute methodValue
*/
public void method()
{
}
/**
* @methodAttribute argMethodValue
*/
public void method(String arg)
{
}
}
The code that compiles and accesses these attributes:
AttributesCompiler attributesCompiler = new AttributesCompiler();
attributesCompiler.setSrc(new File("src" + File.separator + "test"));
attributesCompiler.setDest(targetDir);
attributesCompiler.execute();
assertEquals("classValue", Attributes.getAttribute(AttributesTestClass.class, "classAttribute"));
Field field = AttributesTestClass.class.getDeclaredField("field");
assertEquals("fieldValue", Attributes.getAttribute(field, "fieldAttribute"));
Method method = AttributesTestClass.class.getMethod("method", null);
assertEquals("methodValue", Attributes.getAttribute(method, "methodAttribute"));
Method argMethod = AttributesTestClass.class.getMethod("method", new Class[]{String.class});
assertEquals("argMethodValue", Attributes.getAttribute(argMethod, "methodAttribute"));
The attributes-compiler can also be used as an ant-task (or better yet! inside maven ). This is left as an exercise for the interested reader (yeah, yeah, I'm lazy...). Configuration file formatThe XML based format is documented here . |