Results 1 to 3 of 3

Thread: Wrapping a wrapper

Threaded View

  1. #1
    Join Date
    Nov 2008
    Posts
    6

    Wink Wrapping a wrapper

    OK, so now things are going really well, I have another (silly) question!

    Can I *wrap* a wrapper?

    Here's the class I want to wrap (simplified down):
    Code:
    class CommentatorCharacterObserver(MethodInterceptor):
        def __init__(self):
            pass
            
        def invoke(self, invocation):        
            tags = self.whoTaggedWho(invocation)
            
        def whoTaggedWho(self, invocation):
            character = invocation.instance
            return [character, character]
    and I'm wrapping with:

    Code:
    pointcutAdvisor = RegexpMethodPointcutAdvisor(advice = [WrappingInterceptor()], patterns = [".*"])
    self.characterAdvisor = ProxyFactoryObject(target = CommentatorCharacterObserver(), interceptors = pointcutAdvisor)
    Now, here's my output (with the debug logger on)
    Code:
    > : grep "CommentatorCharacterObserver" output
    2008-11-10 18:27:08,262 - springpython.aop.RegexpMethodPointcut - DEBUG - Candidate is [CommentatorCharacterObserver.invoke]; pattern is [.*]; matched=True
    2008-11-10 18:27:13,169 - springpython.aop.RegexpMethodPointcut - DEBUG - Candidate is [CommentatorCharacterObserver.invoke]; pattern is [.*]; matched=True
    2008-11-10 18:27:13,171 - springpython.aop.RegexpMethodPointcut - DEBUG - Candidate is [CommentatorCharacterObserver.invoke]; pattern is [.*]; matched=True
    2008-11-10 18:27:16,450 - springpython.aop.RegexpMethodPointcut - DEBUG - Candidate is [CommentatorCharacterObserver.invoke]; pattern is [.*]; matched=True
    2008-11-10 18:27:16,452 - springpython.aop.RegexpMethodPointcut - DEBUG - Candidate is [CommentatorCharacterObserver.invoke]; pattern is [.*]; matched=True
    It never even looks into CommentatorCharacterObserver.whoTaggedWho, but does happily watch invoke. Am I formulating something wrong?

    I know that wrapping a wrapper is a bizarre thing to do. My intention is that the Commentator will be output agnostic, and then a database aspect will wrap round it and store things in a database. So here, whoTaggedWho would be wrapped by the database, so the event will be saved across sessions. Is there a more intelligent way to do this with AOP?

    This is an experiment into whether the final project looks nicer than an OOP implementation, which it might well not!

    I'm sorry to have been such a bother all the time
    Last edited by Lewisham; Nov 10th, 2008 at 08:47 PM.

Tags for this Thread

Posting Permissions

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