1 16 17 package org.springframework.aop.framework; 18 19 import org.aopalliance.intercept.Interceptor; 20 21 import org.springframework.aop.TargetSource; 22 import org.springframework.util.Assert; 23 import org.springframework.util.ClassUtils; 24 25 35 public class ProxyFactory extends ProxyCreatorSupport implements AopProxy { 36 37 40 public ProxyFactory() { 41 } 42 43 48 public ProxyFactory(Object target) { 49 Assert.notNull(target, "Target object must not be null"); 50 setInterfaces(ClassUtils.getAllInterfaces(target)); 51 setTarget(target); 52 } 53 54 59 public ProxyFactory(Class [] proxyInterfaces) { 60 setInterfaces(proxyInterfaces); 61 } 62 63 71 public ProxyFactory(Class proxyInterface, Interceptor interceptor) { 72 addInterface(proxyInterface); 73 addAdvice(interceptor); 74 } 75 76 82 public ProxyFactory(Class proxyInterface, TargetSource targetSource) { 83 addInterface(proxyInterface); 84 setTargetSource(targetSource); 85 } 86 87 88 96 public Object getProxy() { 97 return createAopProxy().getProxy(); 98 } 99 100 109 public Object getProxy(ClassLoader classLoader) { 110 return createAopProxy().getProxy(classLoader); 111 } 112 113 114 124 public static Object getProxy(Class proxyInterface, Interceptor interceptor) { 125 return new ProxyFactory(proxyInterface, interceptor).getProxy(); 126 } 127 128 136 public static Object getProxy(Class proxyInterface, TargetSource targetSource) { 137 return new ProxyFactory(proxyInterface, targetSource).getProxy(); 138 } 139 140 146 public static Object getProxy(TargetSource targetSource) { 147 if (targetSource.getTargetClass() == null) { 148 throw new IllegalArgumentException ("Cannot create class proxy for TargetSource with null target class"); 149 } 150 ProxyFactory proxyFactory = new ProxyFactory(); 151 proxyFactory.setTargetSource(targetSource); 152 proxyFactory.setProxyTargetClass(true); 153 return proxyFactory.getProxy(); 154 } 155 156 } 157 | Popular Tags |