-
1. Re: FYI on new features added tonight
hchirino Nov 3, 2002 11:00 AM (in response to hchirino)Ok.. this morning I've made some more improvments. Lets say you are developing a logging/audinting Interceptor that only works the "Teller" interface.
The easiest way to implement the interceptor would then be something like this:
class TellerAuditor implements Teller {
....
public transfer( Account from, Account to) {
audit.log("A transfer from "+from+" to "+to+" has occured.");
AspectInvocation ai = AspectInvocation.getContextAspectInvocation();
ai.invokeNextAndWrapException());
}
....
}
Then you just add a Delegating interceptor to your aspect like so:
<a:interceptor a:class="org.jboss.aspect.interceptors.DelegatingInterceptor" di:delegate="TellerAuditor" di:singleton="true"/>
Basicly, the Delegating interceptor will use your TellerAuditor to service all the Teller method calls. And the the TellerAuditor uses the AspectInvocation.getContextAspectInvocation() so that he can get the AspectInvocation that is being executed. He uses ai.invokeNextAndWrapException() to call the next interceptor since the "transfer(...)" method does not throw 'Throwable'. Any exceptions that are thrown in invokeNextAndWrapException() are wrapped in a RuntimeException. The wrapped exception will be unwrapped before that AspectInvocation finishes. -
2. Re: FYI on new features added tonight
hchirino Nov 3, 2002 11:32 AM (in response to hchirino)Ok.. just added a few more things:
- Aspect factory will now do parent delegation to find aspects. You can now do something like:
// AspectUnitTestCase.AddThree is defined in the parent.
AspectFactory parent = new AspectFactory();
parent.configure(getClass().getClassLoader().getResource("parent-aspect-config.xml"));
// Setup a child to the parent.
AspectFactory af = new AspectFactory(parent);
af.configure();
// create an aspect using the child.
Object o = af.createAspect("AspectUnitTestCase.AddThree", new TargetObjectA());
- You can set a ContectAspectFactory what will be associated with the current thread.
AspectFactory af = new AspectFactory().configure();
AspectFactory.setContextAspectFactory(af);
then you can later do a:
AspectFactory af = AspectFactory.getContextAspectFactory();