Results 1 to 5 of 5

Thread: Accessing Target Object From Proxy

  1. #1
    Join Date
    Oct 2004
    Posts
    15

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    Code:
    org.springframework.aop.framework.Advised

  3. #3
    Join Date
    Oct 2004
    Posts
    15

    Default

    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

  4. #4

    Default

    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

  5. #5
    Join Date
    Oct 2004
    Posts
    15

    Default

    thanks that was exactly what i need to know!!
    cam

Similar Threads

  1. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. Other Hibernate DAO LazyInitializationExceptions
    By bernardsirius in forum Data
    Replies: 5
    Last Post: Feb 18th, 2005, 04:09 PM
  5. Replies: 9
    Last Post: Feb 8th, 2005, 09:25 PM

Posting Permissions

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