Bo requested mixin support for Yet-Another-Intercept-Library (YAIL) so I just checked in support.
The mixin support is completely orthogonal to the interceptor support, and works like:
public void testMixer()
{
Mixer mixer = new Mixer();
mixer.addMixin(Map.class, new HashMap());
Object base = new Object();
Object mixed = mixer.mix(base);
assertTrue(mixed instanceof Map);
}
It works fine with the interception library as well:
public void testInterceptMixins()
{
InterceptionBroker broker = new InterceptionBroker();
MockInterceptor mock = new MockInterceptor();
broker.addInterceptor(mock, new ClassSignature(Map.class));
Mixer mixer = new Mixer();
mixer.addMixin(Map.class, new HashMap());
Object base = new Object();
Object mixed = mixer.mix(base);
Map wrapped = (Map) broker.wrap(mixed);
wrapped.put("1", "2");
assertTrue(mock.value);
}
The mixin support is little more than a thin veneer around cglib's mixins. Adding additional utility to the Mixer
class will probably happen once I actually use mixins. I can see places where it will be awfully convenient for passing information down interceptor stacks though.
Finally, unrelated, YAIL and Nanning are getting pretty similar, which bugs me. Jon mentioned that he is considering adding cglib support back into Nanning for people who don't mind aspected classes being non-serializable. This seems like silly duplication, but ah well, is all fun. On a side note I implemeneted a quick-and-dirty Nanning backend to the InterceptionBroker
and it worked pretty transparently. None of the unit tests passed though as I tend to use HashMap
for the base object, and nanning cannot intercept classes, just interfaces.
Pushed another development snbapshot with this.