Results 1 to 7 of 7

Thread: Load-Time Weaving aspect complexities

  1. #1

    Default Load-Time Weaving aspect complexities

    Hi,

    I'm trying to write an aspect whose pointcut detects a method call m on class A (so A.m()), but I want to specify what class the caller is. Does aspectjweaver and the aop.xml file allow me to specify things such as this, target, and within for a particular pointcut? If so, can someone please show me how?

    Thank you,
    Jeff

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    The following link seem to have an answer
    http://www.eclipse.org/aspectj/doc/n...iguration.html
    Let us know if you still having an issue

  3. #3

    Default

    I had actually seen that link before, but that seems to show how to set includes and excludes for all aspects. I was just trying for a single aspect.

    I basically wanted to try to do something like this:

    Code:
              <aspectj>
                <aspects>
                  <!-- define a concrete aspect inline -->
                  <concrete-aspect name="com.xyz.tracing.MyTracing"
                                   extends="tracing.AbstractTracing">
                    <pointcut name="tracingScope" expression="call(* MyClass.myMethod(..))"/>
                  </concrete-aspect>
                </aspects>
    
                <weaver options="-verbose">
                  <include within="javax.*"/>
                </weaver>
    
              </aspectj>
    As it is, this would make sure com.xyz.tracing.MyTracing would be executed on any call to MyClass.myMethod(), but I would also like it to only be executed when the "this" object (i.e. the caller) is of type MyCaller. So it would be 2 expressions combined into 1. Is that possible?

    Thanks,
    Jeff

  4. #4
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Something like this should work
    Code:
     <aspectj>
                <aspects>
                  <!-- define a concrete aspect inline -->
                  <concrete-aspect name="com.xyz.tracing.MyTracing"
                                   extends="tracing.AbstractTracing">
                    <pointcut name="tracingScope(MyCaller mc)" expression="call(* MyClass.myMethod(..)) && this(mc)"/>
                  </concrete-aspect>
                </aspects>
    
                <weaver options="-verbose">
                  <include within="javax.*"/>
                </weaver>
    
    </aspectj>
    Let me know

  5. #5

    Default

    Oleg, thanks. That wasn't exactly the right syntax for the aop.xml file, but it got me close enough to find the right syntax. Appreciate it.

  6. #6
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Cool!

    Could you please post the right syntax so others can benefit?

  7. #7

    Default

    Sure, I'd be happy to.

    Code:
     <aspectj>
                <aspects>
                  <!-- define a concrete aspect inline -->
                  <concrete-aspect name="com.xyz.tracing.MyTracing"
                                   extends="tracing.AbstractTracing">
                    <pointcut name="tracingScope" expression="call(* MyClass.myMethod(..)) AND this(fully.qualifier.package.MyCaller)"/>
                  </concrete-aspect>
                </aspects>
    
                <weaver options="-verbose">
                  <include within="javax.*"/>
                </weaver>
    
    </aspectj>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •