Results 1 to 7 of 7

Thread: Bug in SdkRegularExpressionMethodPointcut?

  1. #1
    Join Date
    Sep 2007
    Posts
    4

    Question Bug in SdkRegularExpressionMethodPointcut?

    Hi,

    My group is in the process of evaluating Spring.NET AOP to see if we can leverage it for our existing VB.NET application. To test if it works as expected, I wrote a small sample app (largely rewriting the C# example in the docs for VB.NET, since there aren't really any examples of Spring.NET AOP in a VB.NET app out there.)

    In that app, I've got an an aspectized class (ServiceCommand) with two methods: 'Execute' and 'doExecute'. What I am finding is that specifying a regular expression works for the pointcut in most cases, except when that regular expression is 'do'. In this case, the advice (all types including Before, After, and Around) gets applied to both methods, even though the method 'Execute' does not have the substring 'do' anywhere in its name. I'm thinking that this may have something to do with the fact that 'do' is a keyword in .NET.

    Here is a code snippet that shows how BeforeAdvice is being applied. When the regular expression is used and I put 'do' into txtRegex, I see that the advice gets applied to both method calls, even though I'd expect it to get applied to 'doExecute' only:

    Private Sub cmdBefore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBefore.Click
    Dim factory As New Spring.Aop.Framework.ProxyFactory(New ServiceCommand)
    If rbRegex.Checked Then
    Dim advisor As New Spring.Aop.Support.DefaultPointcutAdvisor(New Spring.Aop.Support.SdkRegularExpressionMethodPoint cut(txtRegex.Text), New BeforeAdvice)
    factory.AddAdvisor(advisor)

    ElseIf rbAllMethods.Checked Then
    factory.AddAdvice(New BeforeAdvice)
    End If
    Dim command As ICommand = factory.GetProxy()
    command.Execute("test advice before invocation")
    command.doExecute("test advice before invocation")

    End Sub

  2. #2
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    Does the namespace contains the text "do" in it ?
    Because the SdkRegularExpressionMethodPointcut takes into account the "full name" of the method : namespace.type.method.

    fyi, you can also use NameMatchMethodPointcut.

    HTH,
    Bruno
    My english is as poor as my taylor is rich

  3. #3
    Join Date
    Sep 2007
    Posts
    4

    Default

    Thanks for the reply Bruno. The namespace here is "WindowsApplication1.Form1", which does indeed contain the "do" text.

    Is there a way I could use a regular expression pointcut on just the method name and not the full namespace? NameMatchMethodPointcut is no good for that as it is used for exact matches as opposed to regexp.

  4. #4
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    Hi,

    I think the regex "\.\w[\w\d_]*" should do the job.

    -Erich

  5. #5
    Join Date
    Sep 2007
    Posts
    4

    Default

    Thanks for the reply Erich. The regexp \w\.do* does work for my particular case with the Spring.Aop.Support.SdkRegularExpressionMethodPoint implementation.

    However, this does imply that I need to know the exact namespace in every method invocation that I want to aspectize using a regular expression pointcut - without this knowledge I cannot be sure that the regular expression is correct. I suppose this makes sense since one would typically want to aspectize routines in their application namespace and not impact imported namespaces.

    So it sounds like there is no regexp pointcut implementation in Spring.NET that will go off just the method name. What should be used for regexp method pattern matching is the SdkRegularExpressionMethodPoint, and the regular expression should be written with the fully qualified namespace in mind. Is this correct?

    Thanks,
    -Phil

  6. #6
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    Hi Phil,

    at least for now and SdkRegularExpressionMethodPoint this is the case, yes. Of course we're always open ears for improvement suggestions.

    Btw: NameMatchMethodPointcut accepts wildcards as well. Thus "do*" should work as well for your problem.

    cheers,
    Erich

  7. #7
    Join Date
    Sep 2007
    Posts
    4

    Thumbs up

    Erich, thank you very much for the prompt replies! And yes, NameMatchMethodPointcut works as you mention. I think at this point we can consider my issue closed.

    Regards,
    -Phil

Posting Permissions

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