use of cn.taketoday.aop.TargetSource in project today-framework by TAKETODAY.
the class AbstractSingletonProxyFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() {
if (this.target == null) {
throw new IllegalArgumentException("Property 'target' is required");
}
if (this.target instanceof String) {
throw new IllegalArgumentException("'target' needs to be a bean reference, not a bean name as value");
}
if (this.proxyClassLoader == null) {
this.proxyClassLoader = ClassUtils.getDefaultClassLoader();
}
ProxyFactory proxyFactory = new ProxyFactory();
if (this.preInterceptors != null) {
for (Object interceptor : this.preInterceptors) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));
}
}
// Add the main interceptor (typically an Advisor).
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(createMainInterceptor()));
if (this.postInterceptors != null) {
for (Object interceptor : this.postInterceptors) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));
}
}
proxyFactory.copyFrom(this);
TargetSource targetSource = createTargetSource(this.target);
proxyFactory.setTargetSource(targetSource);
if (this.proxyInterfaces != null) {
proxyFactory.setInterfaces(this.proxyInterfaces);
} else if (!isProxyTargetClass()) {
// Rely on AOP infrastructure to tell us what interfaces to proxy.
Class<?> targetClass = targetSource.getTargetClass();
if (targetClass != null) {
proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
}
}
postProcessProxyFactory(proxyFactory);
this.proxy = proxyFactory.getProxy(this.proxyClassLoader);
}
use of cn.taketoday.aop.TargetSource in project today-framework by TAKETODAY.
the class StandardProxyInvoker method dynamicAdvisedProceed.
public static Object dynamicAdvisedProceed(Object proxy, AdvisedSupport advised, TargetInvocation targetInv, Object[] args) throws Throwable {
Object target = null;
Object oldProxy = null;
boolean restore = false;
final TargetSource targetSource = advised.getTargetSource();
try {
if (advised.isExposeProxy()) {
// Make invocation available if necessary.
oldProxy = AopContext.setCurrentProxy(proxy);
restore = true;
}
target = targetSource.getTarget();
final MethodInterceptor[] interceptors = targetInv.getDynamicInterceptors(advised);
// but just use MethodInvoker invocation of the target.
if (ObjectUtils.isEmpty(interceptors)) {
return targetInv.proceed(target, args);
}
// We need to create a DynamicStandardMethodInvocation...
final Object retVal = new DynamicStandardMethodInvocation(proxy, target, targetInv, args, interceptors).proceed();
assertReturnValue(retVal, targetInv.getMethod());
return retVal;
} finally {
if (target != null && !targetSource.isStatic()) {
targetSource.releaseTarget(target);
}
if (restore) {
// Restore old proxy.
AopContext.setCurrentProxy(oldProxy);
}
}
}
Aggregations