Announcement Announcement Module
Collapse
No announcement yet.
Accessing Target Object From Proxy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing Target Object From Proxy

    hi ng,

    could someone give me some hints on how to configure a proxy so that i can access the target object? eg:

    Code:
    Cast cast = (Cast) proxy;
    Target = (Target) cast.getTargetObject();
    thanks,
    cam

  • #2
    Code:
    org.springframework.aop.framework.Advised

    Comment


    • #3
      ok, but how can i access this from the proxy?

      here was what i was thinking. I was going to add an introduction advice to the proxy:

      Code:
      public interface IProxy {
      
          public Object getProxiedObject();
      
      }
      but how can i gain access to the proxied object from the mixin?

      Code:
      public class ProxyInterceptor extends DelegatingIntroductionInterceptor implements IProxy {
      
          public ProxyInterceptor() {
              super();
          }
      
          public Object getProxiedObject() {
             // how can i return the proxied object here?
          }
      
      }
      Code:
      public class ProxyAdvisor extends DefaultIntroductionAdvisor {
      
          public ProxyAdvisor() {
              super(new ProxyInterceptor(), IProxy.class);
          }
          
      }
      thanks,
      cam

      Comment


      • #4
        If you want to get the target from the proxy, you do:
        Code:
        Advised advised = (Advised) proxy;
        Target target = proxy.getTargetSource().getTarget();
        If you want to get the proxy from the target or advice, you set exposeProxy to true in the ProxyFactoryBean, and from your target or advice, you call
        Code:
        AopContext.currentProxy();
        Guillaume

        Comment


        • #5
          thanks that was exactly what i need to know!!
          cam

          Comment

          Working...
          X