View Full Version : Accessing Target Object From Proxy
cameronjones
Oct 18th, 2004, 07:48 AM
hi ng,
could someone give me some hints on how to configure a proxy so that i can access the target object? eg:
Cast cast = (Cast) proxy;
Target = (Target) cast.getTargetObject();
thanks,
cam
oliverhutchison
Oct 18th, 2004, 06:59 PM
org.springframework.aop.framework.Advised
cameronjones
Oct 19th, 2004, 11:45 PM
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:
public interface IProxy {
public Object getProxiedObject();
}
but how can i gain access to the proxied object from the mixin?
public class ProxyInterceptor extends DelegatingIntroductionInterceptor implements IProxy {
public ProxyInterceptor() {
super();
}
public Object getProxiedObject() {
// how can i return the proxied object here?
}
}
public class ProxyAdvisor extends DefaultIntroductionAdvisor {
public ProxyAdvisor() {
super(new ProxyInterceptor(), IProxy.class);
}
}
thanks,
cam
gpoirier
Oct 20th, 2004, 12:18 AM
If you want to get the target from the proxy, you do:
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 AopContext.currentProxy();
Guillaume
cameronjones
Oct 20th, 2004, 01:23 AM
thanks that was exactly what i need to know!! :D
cam
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.