@Test public void getInstance() throws Exception { A proxyA = new CGLibProxy().proxy(A.class, new B()); Assert.assertTrue(proxyA instanceof A); }
public <T> T proxy(Class<T> clazz, Object shadowObject) { if (!ArgumentsUtils.hasNoArgumentsConstructor(clazz)) { Class[] argTypes = ArgumentsUtils.getConstructorsArgumensTypes(clazz); Object[] args = ArgumentsUtils.getArgumens(argTypes); return proxy(clazz, shadowObject, argTypes, args); } this.shadowObject = shadowObject; Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(clazz); enhancer.setCallback(this); T proxy = (T) enhancer.create(); if (shadowObject instanceof Shadow) { ((Shadow) shadowObject).setProxyObject(proxy); } return proxy; }
CGLibProxy implements MethodInterceptor { public <T> T proxy(Class<T> clazz, Object shadowObject) { if (!ArgumentsUtils.hasNoArgumentsConstructor(clazz)) { Class[] argTypes = ArgumentsUtils.getConstructorsArgumensTypes(clazz); Object[] args = ArgumentsUtils.getArgumens(argTypes); return proxy(clazz, shadowObject, argTypes, args); } this.shadowObject = shadowObject; Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(clazz); enhancer.setCallback(this); T proxy = (T) enhancer.create(); if (shadowObject instanceof Shadow) { ((Shadow) shadowObject).setProxyObject(proxy); } return proxy; } }
CGLibProxy implements MethodInterceptor { public <T> T proxy(Class<T> clazz, Object shadowObject) { if (!ArgumentsUtils.hasNoArgumentsConstructor(clazz)) { Class[] argTypes = ArgumentsUtils.getConstructorsArgumensTypes(clazz); Object[] args = ArgumentsUtils.getArgumens(argTypes); return proxy(clazz, shadowObject, argTypes, args); } this.shadowObject = shadowObject; Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(clazz); enhancer.setCallback(this); T proxy = (T) enhancer.create(); if (shadowObject instanceof Shadow) { ((Shadow) shadowObject).setProxyObject(proxy); } return proxy; }  }
CGLibProxy implements MethodInterceptor { public <T> T proxy(Class<T> clazz, Object shadowObject) { if (!ArgumentsUtils.hasNoArgumentsConstructor(clazz)) { Class[] argTypes = ArgumentsUtils.getConstructorsArgumensTypes(clazz); Object[] args = ArgumentsUtils.getArgumens(argTypes); return proxy(clazz, shadowObject, argTypes, args); } this.shadowObject = shadowObject; Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(clazz); enhancer.setCallback(this); T proxy = (T) enhancer.create(); if (shadowObject instanceof Shadow) { ((Shadow) shadowObject).setProxyObject(proxy); } return proxy; }  T proxy(Class<T> clazz, Object shadowObject); T proxy(Class<T> clazz, Object shadowObject, Class[] argTypes, Object[] args); @Override Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy); }
CGLibProxy implements MethodInterceptor { public <T> T proxy(Class<T> clazz, Object shadowObject) { if (!ArgumentsUtils.hasNoArgumentsConstructor(clazz)) { Class[] argTypes = ArgumentsUtils.getConstructorsArgumensTypes(clazz); Object[] args = ArgumentsUtils.getArgumens(argTypes); return proxy(clazz, shadowObject, argTypes, args); } this.shadowObject = shadowObject; Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(clazz); enhancer.setCallback(this); T proxy = (T) enhancer.create(); if (shadowObject instanceof Shadow) { ((Shadow) shadowObject).setProxyObject(proxy); } return proxy; }  T proxy(Class<T> clazz, Object shadowObject); T proxy(Class<T> clazz, Object shadowObject, Class[] argTypes, Object[] args); @Override Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy);  }