2 Replies Latest reply on Nov 3, 2002 11:32 AM by Hiram Chirino

    FYI on new features added tonight

    Hiram Chirino Expert

      Hi guys.. I added a few more things to the Aspect implementation in the CVS tonight.

      - Added interceptor method call filtering. A regular expression can be applied to limit the method calls a interceptor will be involved in.

      So now in the aspect xml file you can now:
      <a:aspect a:name="Person">
      <a:interceptor a:class="InterceptorX"
      a:filter="get.*"/>
      </a:aspect>

      InterceptorX will only receive method calls that start with 'get'

      - Added the ability to add extra interfaces to an aspect (in addtion to the interfaces add by interceptors)

      So now in the aspect xml you can now do:
      <a:aspect a:name="Address" a:interfaces="IAddress">
      <a:interceptor a:class="org.jboss.aspect.interceptors.GetSetInterceptor"/>
      </a:aspect>

      Objects created with the Address aspect will now have the IAddress interface (even if it is now exposed by any of the interceptors defined for the aspect).

      - Added a GetSetInterceptor which implements the getters and setters in the typical java bean fasion.

      So if you ahve the following xml:
      <a:aspect a:name="Address" a:interfaces="IAddress">
      <a:interceptor a:class="org.jboss.aspect.interceptors.GetSetInterceptor"/>
      </a:aspect>

      Then, all the get* and set* methods in IAddress will be implemented by the GetSetInterceptor. The GetSetInterceptor does not expose any Interfaces, it just implements any get set methods that are passed on to it.

      Regards,
      Hiram

        • 1. Re: FYI on new features added tonight
          Hiram Chirino Expert

          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
            Hiram Chirino Expert

            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();