1 Reply Latest reply on Oct 31, 2007 10:51 AM by jacob.orshalick

    AspectJ/Jboss Seam integration ?

    jayzaw

      Hi,

      I am using AspectJ for verifying preconditions within a call to a service's business operation method. So, to do this I use around(), which means:

      - when entering, the preconditions applying have to be verified by calling the methods. The method names of the preconditions are in a database (cached). They should be called by reflection.

      - the problems I have are:
      a) for using reflection, I have to be able to reference the class' name. Unfortunately, "this" - within an aspect's advice means a reference to the aspect or the advice. But not the class in which the operation currently executes.

      b) the project is a JBoss Seam project. The Jboss Seam component incorporating the service is annotated to be a stateless session bean. So I wonder whether:
      b1) AspectJ and Jboss Seam components will have conflicts (Seam uses annotations and maybe other technologies which might conflict with AspectJ)
      b2) how to integrate AspectJ in a Jboss Seam project - when trying to create an aspect in my Jboss Seam project, it complains that this is not an AspectJ project
      b3) what I should look out for when deploying the project (the aspects should be "weaved" into the code at precompile- or compile-time.

      Kind regards,

      Jay

        • 1. Re: AspectJ/Jboss Seam integration ?

           

          "jayzaw" wrote:
          a) for using reflection, I have to be able to reference the class' name. Unfortunately, "this" - within an aspect's advice means a reference to the aspect or the advice. But not the class in which the operation currently executes.


          This is more of an AspectJ question, but yes, you will have to use the reflection utilities provided by AspectJ to retrieve the class name. Something like:

          thisJoinPointStaticPart.getSignature().getDeclaringType().getName();
          


          "jayzaw" wrote:

          b1) AspectJ and Jboss Seam components will have conflicts (Seam uses annotations and maybe other technologies which might conflict with AspectJ)


          There should not be any conflicts as far as I know. I used annotations with an AspectJ implementation in a previous project and there where not any issues (of course I was using Spring/Hibernate so I could not speak to Seam specifically). The only time annotations should come into the picture is if you want to act on the annotation within your aspect.

          "jayzaw" wrote:
          b2) how to integrate AspectJ in a Jboss Seam project - when trying to create an aspect in my Jboss Seam project, it complains that this is not an AspectJ project


          Hmm... sounds like this is your IDE complaining? You should be able to add an aspect without any issues, simply use ajc for compilation.

          "jayzaw" wrote:
          b3) what I should look out for when deploying the project (the aspects should be "weaved" into the code at precompile- or compile-time.


          Yes, simply make sure to use ajc for compilation and the classes become plain-old Java byte code. Of course make sure you have the appropriate AspectJ libraries available at run-time for calls to the AspectJ APIs (reflection calls, etc).

          Hope that helps.