if (this.target == null) {
throw new IllegalArgumentException("'target' is required");
}
ProxyFactory proxyFactory = new ProxyFactory();
if (this.preInterceptors != null) {
for (int i = 0; i < this.preInterceptors.length; i++) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(this.preInterceptors[i]));
}
}
if (this.pointcut != null) {
Advisor advice = new DefaultPointcutAdvisor(this.pointcut, this.resourceInterceptor);
proxyFactory.addAdvisor(advice);
}
else {
// rely on default pointcut
proxyFactory.addAdvisor(new ResourceAdvisor(this.resourceInterceptor));
// Could just do the following, but it's usually less efficient because of AOP advice chain caching.
// proxyFactory.addInterceptor(transactionInterceptor);
}
if (this.postInterceptors != null) {
for (int i = 0; i < this.postInterceptors.length; i++) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(this.postInterceptors[i]));
}
}
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.
proxyFactory.setInterfaces(AopUtils.getAllInterfacesForClass(targetSource.getTargetClass()));
}
this.proxy = proxyFactory.getProxy();
}