Announcement Announcement Module
Collapse
No announcement yet.
introduce and intercept Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • introduce and intercept

    Is it possible to introduce an interface to an existing class and also intercept calls to the methods of the original class? I've tried to add two interceptors to a proxy, but because I had to set exposeProxy, singleton and proxyTargetClass to true for the introduction, subsequent method interceptors aren't called.

    I've tried (as a hack) to create the introduction proxy and then create another proxy on to that, but nothing seems to work. Am i missing something conceptually or is this a limit of the proxy-based approach? Would an alternative AOP framework like Aspectwerkz allow such functionality?

    TIA

  • #2
    I don't fully understand your problem but subsequent method calls from within the proxy context (i.e. from within an intercepted method to a method in the same class) are by nature (of a proxy based framework) never intercepted. This does not have anything to do with introductions or the proxyTargetClass features.

    You can get to the current Proxy by using AopContext.currentProxy() and cast is to the interface/class you need. This is not a really elegant solution I must admit.

    rgds,
    Alef Arendsen

    Comment


    • #3
      example

      Say I have a class called person with a method called "getName" and I want to introduce a new interface called "Coder" so I can ask a person that implements the interface for their favourite language. I can min-in the Coder interface and call the "getFavouriteLanguage" method and the code block in my mixin is called.

      Now I'd like to intercept the call to "getName" so I can change the call to return their nick if they are a coder. If I have already used a mixin, my method intercepter doesn't work. It seems that I can only get a mixin *or* a method-intercepter, but I can't use the same proxy factory for both types.

      Comment

      Working...
      X