当前位置: 首页>>代码示例>>Java>>正文


Java TargetSource类代码示例

本文整理汇总了Java中org.springframework.aop.TargetSource的典型用法代码示例。如果您正苦于以下问题:Java TargetSource类的具体用法?Java TargetSource怎么用?Java TargetSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TargetSource类属于org.springframework.aop包,在下文中一共展示了TargetSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRefreshableProxy

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * 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, Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces == null) {
		interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
	}
	proxyFactory.setInterfaces(interfaces);
	if (proxyTargetClass) {
		classLoader = null;  // force use of Class.getClassLoader()
		proxyFactory.setProxyTargetClass(proxyTargetClass);
	}

	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
	introduction.suppressInterface(TargetSource.class);
	proxyFactory.addAdvice(introduction);

	return proxyFactory.getProxy(classLoader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:ScriptFactoryPostProcessor.java

示例2: getCustomTargetSource

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * Create a target source for bean instances. Uses any TargetSourceCreators if set.
 * Returns {@code null} if no custom TargetSource should be used.
 * <p>This implementation uses the "customTargetSourceCreators" property.
 * Subclasses can override this method to use a different mechanism.
 * @param beanClass the class of the bean to create a TargetSource for
 * @param beanName the name of the bean
 * @return a TargetSource for this bean
 * @see #setCustomTargetSourceCreators
 */
protected TargetSource getCustomTargetSource(Class<?> beanClass, String beanName) {
	// We can't create fancy target sources for directly registered singletons.
	if (this.customTargetSourceCreators != null &&
			this.beanFactory != null && this.beanFactory.containsBean(beanName)) {
		for (TargetSourceCreator tsc : this.customTargetSourceCreators) {
			TargetSource ts = tsc.getTargetSource(beanClass, beanName);
			if (ts != null) {
				// Found a matching TargetSource.
				if (logger.isDebugEnabled()) {
					logger.debug("TargetSourceCreator [" + tsc +
							" found custom TargetSource for bean with name '" + beanName + "'");
				}
				return ts;
			}
		}
	}

	// No custom TargetSource found.
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:AbstractAutoProxyCreator.java

示例3: getObjectType

import org.springframework.aop.TargetSource; //导入依赖的package包/类
@Override
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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AbstractSingletonProxyFactoryBean.java

示例4: newPrototypeInstance

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * 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.
		copy.setInterfaces(
				ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
	}
	copy.setFrozen(this.freezeProxy);

	if (logger.isTraceEnabled()) {
		logger.trace("Using ProxyCreatorSupport copy: " + copy);
	}
	return getProxy(copy.createAopProxy());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ProxyFactoryBean.java

示例5: freshTargetSource

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * Return a TargetSource to use when creating a proxy. If the target was not
 * specified at the end of the interceptorNames list, the TargetSource will be
 * this class's TargetSource member. Otherwise, we get the target bean and wrap
 * it in a TargetSource if necessary.
 */
private TargetSource freshTargetSource() {
	if (this.targetName == null) {
		if (logger.isTraceEnabled()) {
			logger.trace("Not refreshing target: Bean name not specified in 'interceptorNames'.");
		}
		return this.targetSource;
	}
	else {
		if (this.beanFactory == null) {
			throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " +
					"- cannot resolve target with name '" + this.targetName + "'");
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Refreshing target with name '" + this.targetName + "'");
		}
		Object target = this.beanFactory.getBean(this.targetName);
		return (target instanceof TargetSource ? (TargetSource) target : new SingletonTargetSource(target));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:ProxyFactoryBean.java

示例6: ultimateTargetClass

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * Determine the ultimate target class of the given bean instance, traversing
 * not only a top-level proxy but any number of nested proxies as well -
 * as long as possible without side effects, that is, just for singleton targets.
 * @param candidate the instance to check (might be an AOP proxy)
 * @return the target class (or the plain class of the given object as fallback;
 * never {@code null})
 * @see org.springframework.aop.TargetClassAware#getTargetClass()
 * @see Advised#getTargetSource()
 */
public static Class<?> ultimateTargetClass(Object candidate) {
	Assert.notNull(candidate, "Candidate object must not be null");
	Object current = candidate;
	Class<?> result = null;
	while (current instanceof TargetClassAware) {
		result = ((TargetClassAware) current).getTargetClass();
		Object nested = null;
		if (current instanceof Advised) {
			TargetSource targetSource = ((Advised) current).getTargetSource();
			if (targetSource instanceof SingletonTargetSource) {
				nested = ((SingletonTargetSource) targetSource).getTarget();
			}
		}
		current = nested;
	}
	if (result == null) {
		result = (AopUtils.isCglibProxy(candidate) ? candidate.getClass().getSuperclass() : candidate.getClass());
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:AopProxyUtils.java

示例7: copyConfigurationFrom

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * Copy the AOP configuration from the given AdvisedSupport object,
 * but allow substitution of a fresh TargetSource and a given interceptor chain.
 * @param other the AdvisedSupport object to take proxy configuration from
 * @param targetSource the new TargetSource
 * @param advisors the Advisors for the chain
 */
protected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, List<Advisor> advisors) {
	copyFrom(other);
	this.targetSource = targetSource;
	this.advisorChainFactory = other.advisorChainFactory;
	this.interfaces = new ArrayList<Class<?>>(other.interfaces);
	for (Advisor advisor : advisors) {
		if (advisor instanceof IntroductionAdvisor) {
			validateIntroductionAdvisor((IntroductionAdvisor) advisor);
		}
		Assert.notNull(advisor, "Advisor must not be null");
		this.advisors.add(advisor);
	}
	updateAdvisorArray();
	adviceChanged();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:AdvisedSupport.java

示例8: getCglibProxyTargetObject

import org.springframework.aop.TargetSource; //导入依赖的package包/类
private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
  String name = proxy.getClass().getName();
  if (name.toLowerCase().contains("cglib")) {
    Method[] methods = proxy.getClass().getDeclaredMethods();
    Method targetSourceMethod = null;
    for (Method method : methods) {
      if (method.getName().endsWith("getTargetSource")) {
        targetSourceMethod = method;
      }
    }
    if (targetSourceMethod != null) {
      targetSourceMethod.setAccessible(true);
      try {
        TargetSource targetSource = (TargetSource) targetSourceMethod.invoke(proxy);
        return targetSource.getTarget();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    } else {
      throw new IllegalStateException(
          "Could not find target source method on proxied object [" + proxy.getClass() + "]");
    }
  }
  return proxy;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:26,代码来源:GrpcAop.java

示例9: createRefreshableProxy

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
    * 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, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader;

if (interfaces == null) {
    interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
}
proxyFactory.setInterfaces(interfaces);
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);
   }
 
开发者ID:ilivoo,项目名称:game,代码行数:32,代码来源:MyScriptFactoryPostProcessor.java

示例10: ultimateTargetClass

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * Determine the ultimate target class of the given bean instance, traversing
 * not only a top-level proxy but any number of nested proxies as well &mdash;
 * as long as possible without side effects, that is, just for singleton targets.
 * @param candidate the instance to check (might be an AOP proxy)
 * @return the ultimate target class (or the plain class of the given
 * object as fallback; never {@code null})
 * @see org.springframework.aop.TargetClassAware#getTargetClass()
 * @see Advised#getTargetSource()
 */
public static Class<?> ultimateTargetClass(Object candidate) {
	Assert.notNull(candidate, "Candidate object must not be null");
	Object current = candidate;
	Class<?> result = null;
	while (current instanceof TargetClassAware) {
		result = ((TargetClassAware) current).getTargetClass();
		Object nested = null;
		if (current instanceof Advised) {
			TargetSource targetSource = ((Advised) current).getTargetSource();
			if (targetSource instanceof SingletonTargetSource) {
				nested = ((SingletonTargetSource) targetSource).getTarget();
			}
		}
		current = nested;
	}
	if (result == null) {
		result = (AopUtils.isCglibProxy(candidate) ? candidate.getClass().getSuperclass() : candidate.getClass());
	}
	return result;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:AopProxyUtils.java

示例11: createRefreshableProxy

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * 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, Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces == null) {
		interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
	}
	proxyFactory.setInterfaces(interfaces);
	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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:ScriptFactoryPostProcessor.java

示例12: getAdvicesAndAdvisorsForBean

import org.springframework.aop.TargetSource; //导入依赖的package包/类
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String name, TargetSource customTargetSource) {
	if (StaticMessageSource.class.equals(beanClass)) {
		return DO_NOT_PROXY;
	}
	else if (name.endsWith("ToBeProxied")) {
		boolean isFactoryBean = FactoryBean.class.isAssignableFrom(beanClass);
		if ((this.proxyFactoryBean && isFactoryBean) || (this.proxyObject && !isFactoryBean)) {
			return new Object[] {this.testInterceptor};
		}
		else {
			return DO_NOT_PROXY;
		}
	}
	else {
		return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AutoProxyCreatorTests.java

示例13: isMultipleProxy

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * 是否代理了多次
 * see http://jinnianshilongnian.iteye.com/blog/1894465
 * @param proxy
 * @return
 */
public static boolean isMultipleProxy(Object proxy) {
    try {
        ProxyFactory proxyFactory = null;
        if(AopUtils.isJdkDynamicProxy(proxy)) {
            proxyFactory = findJdkDynamicProxyFactory(proxy);
        }
        if(AopUtils.isCglibProxy(proxy)) {
            proxyFactory = findCglibProxyFactory(proxy);
        }
        TargetSource targetSource = (TargetSource) ReflectionUtils.getField(ProxyFactory_targetSource_FIELD, proxyFactory);
        return AopUtils.isAopProxy(targetSource.getTarget());
    } catch (Exception e) {
        throw new IllegalArgumentException("proxy args maybe not proxy with cglib or jdk dynamic proxy. this method not support", e);
    }
}
 
开发者ID:leiyong0326,项目名称:phone,代码行数:22,代码来源:AopProxyUtils.java

示例14: copyConfigurationFrom

import org.springframework.aop.TargetSource; //导入依赖的package包/类
/**
 * Copy the AOP configuration from the given AdvisedSupport object,
 * but allow substitution of a fresh TargetSource and a given interceptor chain.
 * @param other the AdvisedSupport object to take proxy configuration from
 * @param targetSource the new TargetSource
 * @param advisors the Advisors for the chain
 */
protected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSource, List<Advisor> advisors) {
	copyFrom(other);
	this.targetSource = targetSource;
	this.advisorChainFactory = other.advisorChainFactory;
	this.interfaces = new ArrayList<Class>(other.interfaces);
	for (Advisor advisor : advisors) {
		if (advisor instanceof IntroductionAdvisor) {
			validateIntroductionAdvisor((IntroductionAdvisor) advisor);
		}
		Assert.notNull(advisor, "Advisor must not be null");
		this.advisors.add(advisor);
	}
	updateAdvisorArray();
	adviceChanged();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:AdvisedSupport.java

示例15: getObject

import org.springframework.aop.TargetSource; //导入依赖的package包/类
public synchronized Object getObject() throws Exception {
		TargetSource targetSource = new TargetSource() {
			public void releaseTarget(Object arg0) throws Exception {
//				System.out.println("releasing "+ arg0);
			}
			public boolean isStatic() {
				return false;
			}
			public Class<Connection> getTargetClass() {
				return Connection.class;
			}
			public Object getTarget() throws Exception {
//				System.out.println("getTarget()");
				if (connection == null || !"ESTABLISHED".equals(connection.getConnectionString())) {
					connection = new Connection(lifeInMillis);			
				}
				return connection;
			}
		};
		return ProxyFactory.getProxy(targetSource);
	}
 
开发者ID:KalaiselvanS,项目名称:codejam,代码行数:22,代码来源:ConnectionFactory.java


注:本文中的org.springframework.aop.TargetSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。