@Override @Nullable public Class<?> getTargetClass() { return this.targetSource.getTargetClass(); }
@Override @Nullable public Class<?> getObjectType() { if (this.proxy != null) { return this.proxy.getClass(); } if (this.proxyInterfaces != null && this.proxyInterfaces.length == 1) { return this.proxyInterfaces[0]; } if (this.target instanceof TargetSource) { return ((TargetSource) this.target).getTargetClass(); } if (this.target != null) { return this.target.getClass(); } return null; }
/** * Create a proxy for the specified {@code TargetSource} that extends * the target class of the {@code TargetSource}. * @param targetSource the TargetSource that the proxy should invoke * @return the proxy object */ public static Object getProxy(TargetSource targetSource) { if (targetSource.getTargetClass() == null) { throw new IllegalArgumentException("Cannot create class proxy for TargetSource with null target class"); } ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(targetSource); proxyFactory.setProxyTargetClass(true); return proxyFactory.getProxy(); }
if (targetSource != null && targetSource.getTargetClass() != null && listenerType.isAssignableFrom(targetSource.getTargetClass())) { return true; if(targetSource != null && targetSource.getTargetClass() != null && targetSource.getTargetClass().isInterface()) { logger.warn(String.format("%s is an interface. The implementing class will not be queried for annotation based listener configurations. If using @StepScope on a @Bean method, be sure to return the implementing class so listener annotations can be used.", targetSource.getTargetClass().getName()));
thisObject = target; } else { clazz = targetSource.getTargetClass(); break;
MethodInvoker mi = MethodInvokerUtils.getMethodInvokerByAnnotation(annotationType, target); final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource() .getTargetClass() : target.getClass(); if (mi != null) { ReflectionUtils.doWithMethods(targetClass, method -> {
ElementType.METHOD), "Annotation [" + annotationType + "] is not a Method-level annotation."); final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource() .getTargetClass() : target.getClass(); if (targetClass == null) {
"Annotation [" + annotationType + "] is not a Method-level annotation."); final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource().getTargetClass() : target.getClass(); if (targetClass == null) {
/** * Create a new prototype instance of this class's created proxy object, * backed by an independent AdvisedSupport configuration. * @return a totally independent proxy, whose advice we may manipulate in isolation */ private synchronized Object newPrototypeInstance() { // In the case of a prototype, we need to give the proxy // an independent instance of the configuration. // In this case, no proxy will have an instance of this object's configuration, // but will have an independent copy. if (logger.isTraceEnabled()) { logger.trace("Creating copy of prototype ProxyFactoryBean config: " + this); } ProxyCreatorSupport copy = new ProxyCreatorSupport(getAopProxyFactory()); // The copy needs a fresh advisor chain, and a fresh TargetSource. TargetSource targetSource = freshTargetSource(); copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain()); if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) { // Rely on AOP infrastructure to tell us what interfaces to proxy. Class<?> targetClass = targetSource.getTargetClass(); if (targetClass != null) { copy.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader)); } } copy.setFrozen(this.freezeProxy); if (logger.isTraceEnabled()) { logger.trace("Using ProxyCreatorSupport copy: " + copy); } return getProxy(copy.createAopProxy()); }
/** * Create a refreshable proxy for the given AOP TargetSource. * @param ts the refreshable TargetSource * @param interfaces the proxy interfaces (may be {@code null} to * indicate proxying of all interfaces implemented by the target class) * @return the generated proxy * @see RefreshableScriptTargetSource */ protected Object createRefreshableProxy(TargetSource ts, @Nullable Class<?>[] interfaces, boolean proxyTargetClass) { ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(ts); ClassLoader classLoader = this.beanClassLoader; if (interfaces != null) { proxyFactory.setInterfaces(interfaces); } else { Class<?> targetClass = ts.getTargetClass(); if (targetClass != null) { proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.beanClassLoader)); } } if (proxyTargetClass) { classLoader = null; // force use of Class.getClassLoader() proxyFactory.setProxyTargetClass(true); } DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts); introduction.suppressInterface(TargetSource.class); proxyFactory.addAdvice(introduction); return proxyFactory.getProxy(classLoader); }
target); final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource().getTargetClass() : target.getClass(); if (mi != null) {
Class<?> targetClass = targetSource.getTargetClass(); if (targetClass != null) { proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
/** * Create a refreshable proxy for the given AOP TargetSource. * @param ts the refreshable TargetSource * @param interfaces the proxy interfaces (may be {@code null} to * indicate proxying of all interfaces implemented by the target class) * @return the generated proxy * @see RefreshableScriptTargetSource */ protected Object createRefreshableProxy(TargetSource ts, @Nullable Class<?>[] interfaces, boolean proxyTargetClass) { ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(ts); ClassLoader classLoader = this.beanClassLoader; if (interfaces != null) { proxyFactory.setInterfaces(interfaces); } else { Class<?> targetClass = ts.getTargetClass(); if (targetClass != null) { proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.beanClassLoader)); } } if (proxyTargetClass) { classLoader = null; // force use of Class.getClassLoader() proxyFactory.setProxyTargetClass(true); } DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts); introduction.suppressInterface(TargetSource.class); proxyFactory.addAdvice(introduction); return proxyFactory.getProxy(classLoader); }
@Test public void testCreateLazy() { TargetSource targetSource = new AbstractLazyCreationTargetSource() { @Override protected Object createObject() { return new InitCountingBean(); } @Override public Class<?> getTargetClass() { return InitCountingBean.class; } }; InitCountingBean proxy = (InitCountingBean) ProxyFactory.getProxy(targetSource); assertEquals("Init count should be 0", 0, InitCountingBean.initCount); assertEquals("Target class incorrect", InitCountingBean.class, targetSource.getTargetClass()); assertEquals("Init count should still be 0 after getTargetClass()", 0, InitCountingBean.initCount); proxy.doSomething(); assertEquals("Init count should now be 1", 1, InitCountingBean.initCount); proxy.doSomething(); assertEquals("Init count should still be 1", 1, InitCountingBean.initCount); }
thisObject = target; } else { clazz = targetSource.getTargetClass(); break;
@Override @Nullable public Class<?> getTargetClass() { return this.targetSource.getTargetClass(); }
public Class getObjectType() { if (proxy != null) return proxy.getClass(); if (target instanceof TargetSource) return ((TargetSource) target).getTargetClass(); if (target != null) return target.getClass(); else return null; }
/** * Return the type of the proxy. Will check the singleton instance if * already created, falling back to the TargetSource's target class. * @see org.springframework.aop.TargetSource#getTargetClass */ public Class getObjectType() { return (this.singletonInstance != null ? this.singletonInstance.getClass() : getTargetSource().getTargetClass()); }
public Object getProxy(ClassLoader classLoader) { if (logger.isDebugEnabled()) { Class targetClass = this.advised.getTargetSource().getTargetClass(); logger.debug("Creating JDK dynamic proxy" + (targetClass != null ? " for [" + targetClass.getName() + "]" : "")); } Class[] proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised); return Proxy.newProxyInstance(classLoader, proxiedInterfaces, this); }
/** * Create a proxy for the specified <code>TargetSource</code> that extends the * target class of the <code>TargetSource</code>. */ public static Object getProxy(TargetSource targetSource) { if (targetSource.getTargetClass() == null) { throw new IllegalArgumentException("Cannot create class proxy for TargetSource with null target class"); } ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(targetSource); proxyFactory.setProxyTargetClass(true); return proxyFactory.getProxy(); }