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

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

/**
 * Create a new SimpleLoadTimeWeaver for the given class loader.
 * @param classLoader the {@code ClassLoader} to delegate to for
 * weaving (<i>must</i> support the required weaving methods).
 * @throws IllegalStateException if the supplied {@code ClassLoader}
 * does not support the required weaving methods
 */
public ReflectiveLoadTimeWeaver(@Nullable ClassLoader classLoader) {
	Assert.notNull(classLoader, "ClassLoader must not be null");
	this.classLoader = classLoader;

	Method addTransformerMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), ADD_TRANSFORMER_METHOD_NAME, ClassFileTransformer.class);
	if (addTransformerMethod == null) {
		throw new IllegalStateException(
				"ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide an " +
				"'addTransformer(ClassFileTransformer)' method.");
	}
	this.addTransformerMethod = addTransformerMethod;

	Method getThrowawayClassLoaderMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), GET_THROWAWAY_CLASS_LOADER_METHOD_NAME);
	// getThrowawayClassLoader method is optional
	if (getThrowawayClassLoaderMethod == null) {
		if (logger.isDebugEnabled()) {
			logger.debug("The ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide a " +
					"'getThrowawayClassLoader()' method; SimpleThrowawayClassLoader will be used instead.");
		}
	}
	this.getThrowawayClassLoaderMethod = getThrowawayClassLoaderMethod;
}
 
/**
 * Create a new SimpleLoadTimeWeaver for the given class loader.
 * @param classLoader the {@code ClassLoader} to delegate to for
 * weaving (<i>must</i> support the required weaving methods).
 * @throws IllegalStateException if the supplied {@code ClassLoader}
 * does not support the required weaving methods
 */
public ReflectiveLoadTimeWeaver(@Nullable ClassLoader classLoader) {
	Assert.notNull(classLoader, "ClassLoader must not be null");
	this.classLoader = classLoader;

	Method addTransformerMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), ADD_TRANSFORMER_METHOD_NAME, ClassFileTransformer.class);
	if (addTransformerMethod == null) {
		throw new IllegalStateException(
				"ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide an " +
				"'addTransformer(ClassFileTransformer)' method.");
	}
	this.addTransformerMethod = addTransformerMethod;

	Method getThrowawayClassLoaderMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), GET_THROWAWAY_CLASS_LOADER_METHOD_NAME);
	// getThrowawayClassLoader method is optional
	if (getThrowawayClassLoaderMethod == null) {
		if (logger.isDebugEnabled()) {
			logger.debug("The ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide a " +
					"'getThrowawayClassLoader()' method; SimpleThrowawayClassLoader will be used instead.");
		}
	}
	this.getThrowawayClassLoaderMethod = getThrowawayClassLoaderMethod;
}
 
源代码3 项目: lams   文件: ReflectiveLoadTimeWeaver.java
/**
 * Create a new SimpleLoadTimeWeaver for the given class loader.
 * @param classLoader the {@code ClassLoader} to delegate to for
 * weaving (<i>must</i> support the required weaving methods).
 * @throws IllegalStateException if the supplied {@code ClassLoader}
 * does not support the required weaving methods
 */
public ReflectiveLoadTimeWeaver(ClassLoader classLoader) {
	Assert.notNull(classLoader, "ClassLoader must not be null");
	this.classLoader = classLoader;
	this.addTransformerMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), ADD_TRANSFORMER_METHOD_NAME, ClassFileTransformer.class);
	if (this.addTransformerMethod == null) {
		throw new IllegalStateException(
				"ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide an " +
				"'addTransformer(ClassFileTransformer)' method.");
	}
	this.getThrowawayClassLoaderMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), GET_THROWAWAY_CLASS_LOADER_METHOD_NAME);
	// getThrowawayClassLoader method is optional
	if (this.getThrowawayClassLoaderMethod == null) {
		if (logger.isInfoEnabled()) {
			logger.info("The ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide a " +
					"'getThrowawayClassLoader()' method; SimpleThrowawayClassLoader will be used instead.");
		}
	}
}
 
源代码4 项目: lams   文件: SessionFactoryUtils.java
/**
 * Determine the DataSource of the given SessionFactory.
 * @param sessionFactory the SessionFactory to check
 * @return the DataSource, or {@code null} if none found
 * @see ConnectionProvider
 */
public static DataSource getDataSource(SessionFactory sessionFactory) {
	Method getProperties = ClassUtils.getMethodIfAvailable(sessionFactory.getClass(), "getProperties");
	if (getProperties != null) {
		Map<?, ?> props = (Map<?, ?>) ReflectionUtils.invokeMethod(getProperties, sessionFactory);
		Object dataSourceValue = props.get(Environment.DATASOURCE);
		if (dataSourceValue instanceof DataSource) {
			return (DataSource) dataSourceValue;
		}
	}
	if (sessionFactory instanceof SessionFactoryImplementor) {
		SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory;
		try {
			ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class);
			if (cp != null) {
				return cp.unwrap(DataSource.class);
			}
		}
		catch (UnknownServiceException ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("No ConnectionProvider found - cannot determine DataSource for SessionFactory: " + ex);
			}
		}
	}
	return null;
}
 
/**
 * Create a new SimpleLoadTimeWeaver for the given class loader.
 * @param classLoader the {@code ClassLoader} to delegate to for
 * weaving (<i>must</i> support the required weaving methods).
 * @throws IllegalStateException if the supplied {@code ClassLoader}
 * does not support the required weaving methods
 */
public ReflectiveLoadTimeWeaver(ClassLoader classLoader) {
	Assert.notNull(classLoader, "ClassLoader must not be null");
	this.classLoader = classLoader;
	this.addTransformerMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), ADD_TRANSFORMER_METHOD_NAME,
			new Class<?>[] {ClassFileTransformer.class});
	if (this.addTransformerMethod == null) {
		throw new IllegalStateException(
				"ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide an " +
				"'addTransformer(ClassFileTransformer)' method.");
	}
	this.getThrowawayClassLoaderMethod = ClassUtils.getMethodIfAvailable(
			this.classLoader.getClass(), GET_THROWAWAY_CLASS_LOADER_METHOD_NAME, new Class<?>[0]);
	// getThrowawayClassLoader method is optional
	if (this.getThrowawayClassLoaderMethod == null) {
		if (logger.isInfoEnabled()) {
			logger.info("The ClassLoader [" + classLoader.getClass().getName() + "] does NOT provide a " +
					"'getThrowawayClassLoader()' method; SimpleThrowawayClassLoader will be used instead.");
		}
	}
}
 
@Nullable
private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) {
	if (String.class == targetClass || String.class == sourceClass) {
		// Do not accept a toString() method or any to methods on String itself
		return null;
	}

	Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName());
	return (method != null && !Modifier.isStatic(method.getModifiers()) &&
			ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null);
}
 
/**
 * Determine the DataSource of the given SessionFactory.
 * @param sessionFactory the SessionFactory to check
 * @return the DataSource, or {@code null} if none found
 * @see ConnectionProvider
 */
@Nullable
public static DataSource getDataSource(SessionFactory sessionFactory) {
	Method getProperties = ClassUtils.getMethodIfAvailable(sessionFactory.getClass(), "getProperties");
	if (getProperties != null) {
		Map<?, ?> props = (Map<?, ?>) ReflectionUtils.invokeMethod(getProperties, sessionFactory);
		if (props != null) {
			Object dataSourceValue = props.get(Environment.DATASOURCE);
			if (dataSourceValue instanceof DataSource) {
				return (DataSource) dataSourceValue;
			}
		}
	}
	if (sessionFactory instanceof SessionFactoryImplementor) {
		SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory;
		try {
			ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class);
			if (cp != null) {
				return cp.unwrap(DataSource.class);
			}
		}
		catch (UnknownServiceException ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("No ConnectionProvider found - cannot determine DataSource for SessionFactory: " + ex);
			}
		}
	}
	return null;
}
 
@Nullable
private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) {
	if (String.class == targetClass || String.class == sourceClass) {
		// Do not accept a toString() method or any to methods on String itself
		return null;
	}

	Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName());
	return (method != null && !Modifier.isStatic(method.getModifiers()) &&
			ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null);
}
 
/**
 * Determine the DataSource of the given SessionFactory.
 * @param sessionFactory the SessionFactory to check
 * @return the DataSource, or {@code null} if none found
 * @see ConnectionProvider
 */
@Nullable
public static DataSource getDataSource(SessionFactory sessionFactory) {
	Method getProperties = ClassUtils.getMethodIfAvailable(sessionFactory.getClass(), "getProperties");
	if (getProperties != null) {
		Map<?, ?> props = (Map<?, ?>) ReflectionUtils.invokeMethod(getProperties, sessionFactory);
		if (props != null) {
			Object dataSourceValue = props.get(Environment.DATASOURCE);
			if (dataSourceValue instanceof DataSource) {
				return (DataSource) dataSourceValue;
			}
		}
	}
	if (sessionFactory instanceof SessionFactoryImplementor) {
		SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory;
		try {
			ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class);
			if (cp != null) {
				return cp.unwrap(DataSource.class);
			}
		}
		catch (UnknownServiceException ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("No ConnectionProvider found - cannot determine DataSource for SessionFactory: " + ex);
			}
		}
	}
	return null;
}
 
源代码10 项目: lams   文件: VelocityToolboxView.java
/**
 * Overridden to check for the ViewContext interface which is part of the
 * view package of Velocity Tools. This requires a special Velocity context,
 * like ChainedContext as set up by {@link #createVelocityContext} in this class.
 */
@Override
protected void initTool(Object tool, Context velocityContext) throws Exception {
	// Velocity Tools 1.3: a class-level "init(Object)" method.
	Method initMethod = ClassUtils.getMethodIfAvailable(tool.getClass(), "init", Object.class);
	if (initMethod != null) {
		ReflectionUtils.invokeMethod(initMethod, tool, velocityContext);
	}
}
 
源代码11 项目: lams   文件: ObjectToObjectConverter.java
private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) {
	if (String.class == targetClass || String.class == sourceClass) {
		// Do not accept a toString() method or any to methods on String itself
		return null;
	}

	Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName());
	return (method != null && !Modifier.isStatic(method.getModifiers()) &&
			ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null);
}
 
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);
	this.beanClass = beanClass;
	this.propertyEditorClass = propertyEditorClass;

	Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
	Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
	if (writeMethodToUse == null && readMethodToUse != null) {
		// Fallback: Original JavaBeans introspection might not have found matching setter
		// method due to lack of bridge method resolution, in case of the getter using a
		// covariant return type whereas the setter is defined for the concrete property type.
		Method candidate = ClassUtils.getMethodIfAvailable(
				this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
		if (candidate != null && candidate.getParameterTypes().length == 1) {
			writeMethodToUse = candidate;
		}
	}
	this.readMethod = readMethodToUse;
	this.writeMethod = writeMethodToUse;

	if (this.writeMethod != null && this.readMethod == null) {
		// Write method not matched against read method: potentially ambiguous through
		// several overloaded variants, in which case an arbitrary winner has been chosen
		// by the JDK's JavaBeans Introspector...
		Set<Method> ambiguousCandidates = new HashSet<Method>();
		for (Method method : beanClass.getMethods()) {
			if (method.getName().equals(writeMethodToUse.getName()) &&
					!method.equals(writeMethodToUse) && !method.isBridge()) {
				ambiguousCandidates.add(method);
			}
		}
		if (!ambiguousCandidates.isEmpty()) {
			this.ambiguousWriteMethods = ambiguousCandidates;
		}
	}
}
 
private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) {
	if (String.class == targetClass || String.class == sourceClass) {
		// Do not accept a toString() method or any to methods on String itself
		return null;
	}

	Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName());
	return (method != null && !Modifier.isStatic(method.getModifiers()) &&
			ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null);
}
 
/**
 * Overridden to check for the ViewContext interface which is part of the
 * view package of Velocity Tools. This requires a special Velocity context,
 * like ChainedContext as set up by {@link #createVelocityContext} in this class.
 */
@Override
protected void initTool(Object tool, Context velocityContext) throws Exception {
	// Velocity Tools 1.3: a class-level "init(Object)" method.
	Method initMethod = ClassUtils.getMethodIfAvailable(tool.getClass(), "init", Object.class);
	if (initMethod != null) {
		ReflectionUtils.invokeMethod(initMethod, tool, velocityContext);
	}
}
 
源代码15 项目: Zebra   文件: ZebraRoutingPointcut.java
boolean match(Method method, Class<?> targetClass) {
	// origin
	if (doMatch(method, targetClass)) {
		return true;
	}
	// cglib
	Class<?> userClass = ClassUtils.getUserClass(targetClass);
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass);
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	if (!specificMethod.equals(method)) {
		if (doMatch(specificMethod, userClass)) {
			return true;
		}
	}
	// jdk proxy
	if (Proxy.isProxyClass(targetClass)) {
		Class<?>[] interfaces = targetClass.getInterfaces();
		for (Class<?> interfaceClass : interfaces) {
			Method interfaceMethod = ClassUtils.getMethodIfAvailable(interfaceClass, method.getName(),
			      method.getParameterTypes());
			if (interfaceMethod != null && doMatch(interfaceMethod, interfaceClass)) {
				return true;
			}
		}
	}
	return false;
}
 
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);
	this.beanClass = beanClass;

	Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
	Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
	if (writeMethodToUse == null && readMethodToUse != null) {
		// Fallback: Original JavaBeans introspection might not have found matching setter
		// method due to lack of bridge method resolution, in case of the getter using a
		// covariant return type whereas the setter is defined for the concrete property type.
		Method candidate = ClassUtils.getMethodIfAvailable(
				this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
		if (candidate != null && candidate.getParameterCount() == 1) {
			writeMethodToUse = candidate;
		}
	}
	this.readMethod = readMethodToUse;
	this.writeMethod = writeMethodToUse;

	if (this.writeMethod != null) {
		if (this.readMethod == null) {
			// Write method not matched against read method: potentially ambiguous through
			// several overloaded variants, in which case an arbitrary winner has been chosen
			// by the JDK's JavaBeans Introspector...
			Set<Method> ambiguousCandidates = new HashSet<>();
			for (Method method : beanClass.getMethods()) {
				if (method.getName().equals(writeMethodToUse.getName()) &&
						!method.equals(writeMethodToUse) && !method.isBridge() &&
						method.getParameterCount() == writeMethodToUse.getParameterCount()) {
					ambiguousCandidates.add(method);
				}
			}
			if (!ambiguousCandidates.isEmpty()) {
				this.ambiguousWriteMethods = ambiguousCandidates;
			}
		}
		this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
		GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
	}

	if (this.readMethod != null) {
		this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
	}
	else if (this.writeMethodParameter != null) {
		this.propertyType = this.writeMethodParameter.getParameterType();
	}

	this.propertyEditorClass = propertyEditorClass;
}
 
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);
	this.beanClass = beanClass;

	Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
	Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
	if (writeMethodToUse == null && readMethodToUse != null) {
		// Fallback: Original JavaBeans introspection might not have found matching setter
		// method due to lack of bridge method resolution, in case of the getter using a
		// covariant return type whereas the setter is defined for the concrete property type.
		Method candidate = ClassUtils.getMethodIfAvailable(
				this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
		if (candidate != null && candidate.getParameterCount() == 1) {
			writeMethodToUse = candidate;
		}
	}
	this.readMethod = readMethodToUse;
	this.writeMethod = writeMethodToUse;

	if (this.writeMethod != null) {
		if (this.readMethod == null) {
			// Write method not matched against read method: potentially ambiguous through
			// several overloaded variants, in which case an arbitrary winner has been chosen
			// by the JDK's JavaBeans Introspector...
			Set<Method> ambiguousCandidates = new HashSet<>();
			for (Method method : beanClass.getMethods()) {
				if (method.getName().equals(writeMethodToUse.getName()) &&
						!method.equals(writeMethodToUse) && !method.isBridge() &&
						method.getParameterCount() == writeMethodToUse.getParameterCount()) {
					ambiguousCandidates.add(method);
				}
			}
			if (!ambiguousCandidates.isEmpty()) {
				this.ambiguousWriteMethods = ambiguousCandidates;
			}
		}
		this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
		GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
	}

	if (this.readMethod != null) {
		this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
	}
	else if (this.writeMethodParameter != null) {
		this.propertyType = this.writeMethodParameter.getParameterType();
	}

	this.propertyEditorClass = propertyEditorClass;
}
 
源代码18 项目: lams   文件: GenericTypeAwarePropertyDescriptor.java
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);

	if (beanClass == null)  {
		throw new IntrospectionException("Bean class must not be null");
	}
	this.beanClass = beanClass;

	Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
	Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
	if (writeMethodToUse == null && readMethodToUse != null) {
		// Fallback: Original JavaBeans introspection might not have found matching setter
		// method due to lack of bridge method resolution, in case of the getter using a
		// covariant return type whereas the setter is defined for the concrete property type.
		Method candidate = ClassUtils.getMethodIfAvailable(
				this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
		if (candidate != null && candidate.getParameterTypes().length == 1) {
			writeMethodToUse = candidate;
		}
	}
	this.readMethod = readMethodToUse;
	this.writeMethod = writeMethodToUse;

	if (this.writeMethod != null) {
		if (this.readMethod == null) {
			// Write method not matched against read method: potentially ambiguous through
			// several overloaded variants, in which case an arbitrary winner has been chosen
			// by the JDK's JavaBeans Introspector...
			Set<Method> ambiguousCandidates = new HashSet<Method>();
			for (Method method : beanClass.getMethods()) {
				if (method.getName().equals(writeMethodToUse.getName()) &&
						!method.equals(writeMethodToUse) && !method.isBridge() &&
						method.getParameterTypes().length == writeMethodToUse.getParameterTypes().length) {
					ambiguousCandidates.add(method);
				}
			}
			if (!ambiguousCandidates.isEmpty()) {
				this.ambiguousWriteMethods = ambiguousCandidates;
			}
		}
		this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
		GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
	}

	if (this.readMethod != null) {
		this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
	}
	else if (this.writeMethodParameter != null) {
		this.propertyType = this.writeMethodParameter.getParameterType();
	}

	this.propertyEditorClass = propertyEditorClass;
}
 
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);

	if (beanClass == null)  {
		throw new IntrospectionException("Bean class must not be null");
	}
	this.beanClass = beanClass;

	Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
	Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
	if (writeMethodToUse == null && readMethodToUse != null) {
		// Fallback: Original JavaBeans introspection might not have found matching setter
		// method due to lack of bridge method resolution, in case of the getter using a
		// covariant return type whereas the setter is defined for the concrete property type.
		Method candidate = ClassUtils.getMethodIfAvailable(
				this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
		if (candidate != null && candidate.getParameterTypes().length == 1) {
			writeMethodToUse = candidate;
		}
	}
	this.readMethod = readMethodToUse;
	this.writeMethod = writeMethodToUse;

	if (this.writeMethod != null) {
		if (this.readMethod == null) {
			// Write method not matched against read method: potentially ambiguous through
			// several overloaded variants, in which case an arbitrary winner has been chosen
			// by the JDK's JavaBeans Introspector...
			Set<Method> ambiguousCandidates = new HashSet<Method>();
			for (Method method : beanClass.getMethods()) {
				if (method.getName().equals(writeMethodToUse.getName()) &&
						!method.equals(writeMethodToUse) && !method.isBridge() &&
						method.getParameterTypes().length == writeMethodToUse.getParameterTypes().length) {
					ambiguousCandidates.add(method);
				}
			}
			if (!ambiguousCandidates.isEmpty()) {
				this.ambiguousWriteMethods = ambiguousCandidates;
			}
		}
		this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
		GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
	}

	if (this.readMethod != null) {
		this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
	}
	else if (this.writeMethodParameter != null) {
		this.propertyType = this.writeMethodParameter.getParameterType();
	}

	this.propertyEditorClass = propertyEditorClass;
}
 
源代码20 项目: compass   文件: JdbcMethodUtils.java
/**
 * 通过反射来执行JDBC接口的方法
 * @param interfaceClass
 * @param methodName
 * @param argTypes
 * @param target
 * @param args
 * @return
 * @throws SQLException
 */
public static Object invokeJdbcMethod(Class<?> interfaceClass,String methodName,Class<?>[] argTypes,Object target,Object[] args) throws SQLException
{
 Method method=ClassUtils.getMethodIfAvailable(interfaceClass, methodName, argTypes);
 if(method == null)
 {
  return null;
 }
 return ReflectionUtils.invokeJdbcMethod(method, target, args);
}