org.springframework.util.ClassUtils#createCompositeInterface ( )源码实例Demo

下面列出了org.springframework.util.ClassUtils#createCompositeInterface ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) {
	Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
	if (targetMethod.getDeclaringClass().isInterface()) {
		// Try to build the most specific interface possible for inherited methods to be
		// considered for sub-interface matches as well, in particular for proxy classes.
		// Note: AspectJ is only going to take Method.getDeclaringClass() into account.
		Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass);
		if (ifcs.size() > 1) {
			try {
				Class<?> compositeInterface = ClassUtils.createCompositeInterface(
						ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
				targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
			}
			catch (IllegalArgumentException ex) {
				// Implemented interfaces probably expose conflicting method signatures...
				// Proceed with original target method.
			}
		}
	}
	return getShadowMatch(targetMethod, method);
}
 
private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) {
	Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
	if (targetMethod.getDeclaringClass().isInterface()) {
		// Try to build the most specific interface possible for inherited methods to be
		// considered for sub-interface matches as well, in particular for proxy classes.
		// Note: AspectJ is only going to take Method.getDeclaringClass() into account.
		Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass);
		if (ifcs.size() > 1) {
			try {
				Class<?> compositeInterface = ClassUtils.createCompositeInterface(
						ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
				targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
			}
			catch (IllegalArgumentException ex) {
				// Implemented interfaces probably expose conflicting method signatures...
				// Proceed with original target method.
			}
		}
	}
	return getShadowMatch(targetMethod, method);
}
 
@Nullable
protected Object adaptToInterfaces(
		@Nullable Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) {

	Class<?> adaptedIfc;
	if (actualInterfaces.length == 1) {
		adaptedIfc = actualInterfaces[0];
	}
	else {
		adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader);
	}

	if (adaptedIfc != null) {
		ScriptEngine scriptEngine = this.scriptEngine;
		if (!(scriptEngine instanceof Invocable)) {
			throw new ScriptCompilationException(scriptSource,
					"ScriptEngine must implement Invocable in order to adapt it to an interface: " + scriptEngine);
		}
		Invocable invocable = (Invocable) scriptEngine;
		if (script != null) {
			script = invocable.getInterface(script, adaptedIfc);
		}
		if (script == null) {
			script = invocable.getInterface(adaptedIfc);
			if (script == null) {
				throw new ScriptCompilationException(scriptSource,
						"Could not adapt script to interface [" + adaptedIfc.getName() + "]");
			}
		}
	}

	return script;
}
 
@Nullable
protected Object adaptToInterfaces(
		@Nullable Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) {

	Class<?> adaptedIfc;
	if (actualInterfaces.length == 1) {
		adaptedIfc = actualInterfaces[0];
	}
	else {
		adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader);
	}

	if (adaptedIfc != null) {
		ScriptEngine scriptEngine = this.scriptEngine;
		if (!(scriptEngine instanceof Invocable)) {
			throw new ScriptCompilationException(scriptSource,
					"ScriptEngine must implement Invocable in order to adapt it to an interface: " + scriptEngine);
		}
		Invocable invocable = (Invocable) scriptEngine;
		if (script != null) {
			script = invocable.getInterface(script, adaptedIfc);
		}
		if (script == null) {
			script = invocable.getInterface(adaptedIfc);
			if (script == null) {
				throw new ScriptCompilationException(scriptSource,
						"Could not adapt script to interface [" + adaptedIfc.getName() + "]");
			}
		}
	}

	return script;
}
 
源代码5 项目: lams   文件: StandardScriptFactory.java
protected Object adaptToInterfaces(Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) {
	Class<?> adaptedIfc;
	if (actualInterfaces.length == 1) {
		adaptedIfc = actualInterfaces[0];
	}
	else {
		adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader);
	}

	if (adaptedIfc != null) {
		if (!(this.scriptEngine instanceof Invocable)) {
			throw new ScriptCompilationException(scriptSource,
					"ScriptEngine must implement Invocable in order to adapt it to an interface: " +
							this.scriptEngine);
		}
		Invocable invocable = (Invocable) this.scriptEngine;
		if (script != null) {
			script = invocable.getInterface(script, adaptedIfc);
		}
		if (script == null) {
			script = invocable.getInterface(adaptedIfc);
			if (script == null) {
				throw new ScriptCompilationException(scriptSource,
						"Could not adapt script to interface [" + adaptedIfc.getName() + "]");
			}
		}
	}

	return script;
}
 
protected Object adaptToInterfaces(Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) {
	Class<?> adaptedIfc;
	if (actualInterfaces.length == 1) {
		adaptedIfc = actualInterfaces[0];
	}
	else {
		adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader);
	}

	if (adaptedIfc != null) {
		if (!(this.scriptEngine instanceof Invocable)) {
			throw new ScriptCompilationException(scriptSource,
					"ScriptEngine must implement Invocable in order to adapt it to an interface: " +
							this.scriptEngine);
		}
		Invocable invocable = (Invocable) this.scriptEngine;
		if (script != null) {
			script = invocable.getInterface(script, adaptedIfc);
		}
		if (script == null) {
			script = invocable.getInterface(adaptedIfc);
			if (script == null) {
				throw new ScriptCompilationException(scriptSource,
						"Could not adapt script to interface [" + adaptedIfc.getName() + "]");
			}
		}
	}

	return script;
}
 
源代码7 项目: spring-analysis-note   文件: ProxyFactoryBean.java
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.proxyClassLoader);
}
 
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
 
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class
 * for the given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
 
源代码10 项目: java-technology-stack   文件: ProxyFactoryBean.java
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.proxyClassLoader);
}
 
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
 
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class
 * for the given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
 
源代码13 项目: lams   文件: JndiObjectFactoryBean.java
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
 
源代码14 项目: lams   文件: ScriptFactoryPostProcessor.java
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class
 * for the given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
 
源代码15 项目: lams   文件: ProxyFactoryBean.java
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.proxyClassLoader);
}
 
源代码16 项目: spring4-understanding   文件: ProxyFactoryBean.java
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.proxyClassLoader);
}
 
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class for the
 * given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
 
/**
 * Create a composite interface Class for the given interfaces,
 * implementing the given interfaces in one single Class.
 * <p>The default implementation builds a JDK proxy class
 * for the given interfaces.
 * @param interfaces the interfaces to merge
 * @return the merged interface as Class
 * @see java.lang.reflect.Proxy#getProxyClass
 */
protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
	return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}