org.springframework.core.BridgeMethodResolver Java Examples

The following examples show how to use org.springframework.core.BridgeMethodResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: mica   Author: lets-mica   File: ClassUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param method         Method
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
@Nullable
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) {
	Class<?> targetClass = method.getDeclaringClass();
	// The method may be on an interface, but we need attributes from the target class.
	// If the target class is null, the method will be unchanged.
	Method specificMethod = ClassUtil.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	// 先找方法,再找方法上的类
	A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
}
 
Example #2
Source Project: smaker   Author: renzl321   File: ClassUtils.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param method         Method
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) {
	Class<?> targetClass = method.getDeclaringClass();
	// The method may be on an interface, but we need attributes from the target class.
	// If the target class is null, the method will be unchanged.
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	// 先找方法,再找方法上的类
	A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
	;
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
}
 
Example #3
Source Project: beihu-boot   Author: beihu-stack   File: ApiBootDataSourceSwitchAnnotationInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    try {
        Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
        Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
        Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
        // get class declared DataSourceSwitch annotation
        DataSourceSwitch dataSourceSwitch = targetClass.getDeclaredAnnotation(DataSourceSwitch.class);
        if (dataSourceSwitch == null) {
            // get declared DataSourceSwitch annotation
            dataSourceSwitch = userDeclaredMethod.getDeclaredAnnotation(DataSourceSwitch.class);
        }
        if (dataSourceSwitch != null) {
            // setting current thread use data source pool name
            DataSourceContextHolder.set(dataSourceSwitch.value());
        }
        return invocation.proceed();
    } finally {
        // remove current thread use datasource pool name
        DataSourceContextHolder.remove();
    }

}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: HandlerMethod.java    License: MIT License 6 votes vote down vote up
/**
 * Create an instance from a bean name, a method, and a {@code BeanFactory}.
 * The method {@link #createWithResolvedBean()} may be used later to
 * re-create the {@code HandlerMethod} with an initialized bean.
 */
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
	Assert.hasText(beanName, "Bean name is required");
	Assert.notNull(beanFactory, "BeanFactory is required");
	Assert.notNull(method, "Method is required");
	this.bean = beanName;
	this.beanFactory = beanFactory;
	Class<?> beanType = beanFactory.getType(beanName);
	if (beanType == null) {
		throw new IllegalStateException("Cannot resolve bean type for bean with name '" + beanName + "'");
	}
	this.beanType = ClassUtils.getUserClass(beanType);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
}
 
Example #5
Source Project: spring-analysis-note   Author: Vip-Augus   File: AnnotationsScanner.java    License: MIT License 6 votes vote down vote up
@Nullable
private static <C, R> R processMethodAnnotations(C context, int aggregateIndex, Method source,
		AnnotationsProcessor<C, R> processor, @Nullable BiPredicate<C, Class<?>> classFilter) {

	Annotation[] annotations = getDeclaredAnnotations(context, source, classFilter, false);
	R result = processor.doWithAnnotations(context, aggregateIndex, source, annotations);
	if (result != null) {
		return result;
	}
	Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(source);
	if (bridgedMethod != source) {
		Annotation[] bridgedAnnotations = getDeclaredAnnotations(context, bridgedMethod, classFilter, true);
		for (int i = 0; i < bridgedAnnotations.length; i++) {
			if (ObjectUtils.containsElement(annotations, bridgedAnnotations[i])) {
				bridgedAnnotations[i] = null;
			}
		}
		return processor.doWithAnnotations(context, aggregateIndex, source, bridgedAnnotations);
	}
	return null;
}
 
Example #6
Source Project: spring-analysis-note   Author: Vip-Augus   File: HandlerMethod.java    License: MIT License 6 votes vote down vote up
/**
 * Create an instance from a bean name, a method, and a {@code BeanFactory}.
 * The method {@link #createWithResolvedBean()} may be used later to
 * re-create the {@code HandlerMethod} with an initialized bean.
 */
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
	Assert.hasText(beanName, "Bean name is required");
	Assert.notNull(beanFactory, "BeanFactory is required");
	Assert.notNull(method, "Method is required");
	this.bean = beanName;
	this.beanFactory = beanFactory;
	Class<?> beanType = beanFactory.getType(beanName);
	if (beanType == null) {
		throw new IllegalStateException("Cannot resolve bean type for bean with name '" + beanName + "'");
	}
	this.beanType = ClassUtils.getUserClass(beanType);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
	evaluateResponseStatus();
	this.description = initDescription(this.beanType, this.method);
}
 
Example #7
Source Project: spring-microservice-exam   Author: wells2333   File: ClassUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param method         Method
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) {
    Class<?> targetClass = method.getDeclaringClass();
    // The method may be on an interface, but we need attributes from the target class.
    // If the target class is null, the method will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
    // If we are dealing with method with generic parameters, find the original method.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
    // 先找方法,再找方法上的类
    A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
    ;
    if (null != annotation) {
        return annotation;
    }
    // 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
    return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
}
 
Example #8
Source Project: magic-starter   Author: xkcoding   File: ClassUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param method         Method
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) {
	Class<?> targetClass = method.getDeclaringClass();
	// The method may be on an interface, but we need attributes from the target class.
	// If the target class is null, the method will be unchanged.
	Method specificMethod = ClassUtil.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	// 先找方法,再找方法上的类
	A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
	;
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
}
 
Example #9
Source Project: java-technology-stack   Author: codeEngraver   File: HandlerMethod.java    License: MIT License 6 votes vote down vote up
/**
 * Create an instance from a bean name, a method, and a {@code BeanFactory}.
 * The method {@link #createWithResolvedBean()} may be used later to
 * re-create the {@code HandlerMethod} with an initialized bean.
 */
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
	Assert.hasText(beanName, "Bean name is required");
	Assert.notNull(beanFactory, "BeanFactory is required");
	Assert.notNull(method, "Method is required");
	this.bean = beanName;
	this.beanFactory = beanFactory;
	Class<?> beanType = beanFactory.getType(beanName);
	if (beanType == null) {
		throw new IllegalStateException("Cannot resolve bean type for bean with name '" + beanName + "'");
	}
	this.beanType = ClassUtils.getUserClass(beanType);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
}
 
Example #10
Source Project: spring4-understanding   Author: langtianya   File: AbstractFallbackJCacheOperationSource.java    License: Apache License 2.0 6 votes vote down vote up
private JCacheOperation<?> computeCacheOperation(Method method, Class<?> targetClass) {
	// Don't allow no-public methods as required.
	if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
		return null;
	}

	// The method may be on an interface, but we need attributes from the target class.
	// If the target class is null, the method will be unchanged.
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

	// First try is the method in the target class.
	JCacheOperation<?> operation = findCacheOperation(specificMethod, targetClass);
	if (operation != null) {
		return operation;
	}
	if (specificMethod != method) {
		// Fall back is to look at the original method.
		operation = findCacheOperation(method, targetClass);
		if (operation != null) {
			return operation;
		}
	}
	return null;
}
 
Example #11
Source Project: java-technology-stack   Author: codeEngraver   File: HandlerMethod.java    License: MIT License 6 votes vote down vote up
/**
 * Create an instance from a bean name, a method, and a {@code BeanFactory}.
 * The method {@link #createWithResolvedBean()} may be used later to
 * re-create the {@code HandlerMethod} with an initialized bean.
 */
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
	Assert.hasText(beanName, "Bean name is required");
	Assert.notNull(beanFactory, "BeanFactory is required");
	Assert.notNull(method, "Method is required");
	this.bean = beanName;
	this.beanFactory = beanFactory;
	Class<?> beanType = beanFactory.getType(beanName);
	if (beanType == null) {
		throw new IllegalStateException("Cannot resolve bean type for bean with name '" + beanName + "'");
	}
	this.beanType = ClassUtils.getUserClass(beanType);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
	evaluateResponseStatus();
}
 
Example #12
Source Project: api-boot   Author: minbox-projects   File: ApiBootDataSourceSwitchAnnotationInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object methodResult;
    try {
        Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
        Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
        Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
        // get class declared DataSourceSwitch annotation
        DataSourceSwitch dataSourceSwitch = targetClass.getDeclaredAnnotation(DataSourceSwitch.class);
        if (dataSourceSwitch == null) {
            // get declared DataSourceSwitch annotation
            dataSourceSwitch = userDeclaredMethod.getDeclaredAnnotation(DataSourceSwitch.class);
        }
        if (dataSourceSwitch != null) {
            // setting current thread use data source pool name
            DataSourceContextHolder.set(dataSourceSwitch.value());
        }
        methodResult = invocation.proceed();
    } finally {
        // remove current thread use datasource pool name
        DataSourceContextHolder.remove();
    }
    return methodResult;

}
 
Example #13
Source Project: blade-tool   Author: chillzhuang   File: ClassUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param method         Method
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) {
	Class<?> targetClass = method.getDeclaringClass();
	// The method may be on an interface, but we need attributes from the target class.
	// If the target class is null, the method will be unchanged.
	Method specificMethod = ClassUtil.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	// 先找方法,再找方法上的类
	A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
	;
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
}
 
Example #14
Source Project: albedo   Author: somowhere   File: ClassUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param method         Method
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
public <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) {
	Class<?> targetClass = method.getDeclaringClass();
	// The method may be on an interface, but we need attributes from the target class.
	// If the target class is null, the method will be unchanged.
	Method specificMethod = ClassUtil.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	// 先找方法,再找方法上的类
	A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
}
 
Example #15
Source Project: jim-framework   Author: jiangmin168168   File: CachingAnnotationsAspect.java    License: Apache License 2.0 6 votes vote down vote up
private Method getSpecificmethod(ProceedingJoinPoint pjp) {
	MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
	Method method = methodSignature.getMethod();
	// The method may be on an interface, but we need attributes from the
	// target class. If the target class is null, the method will be
	// unchanged.
	Class<?> targetClass = AopProxyUtils.ultimateTargetClass(pjp.getTarget());
	if (targetClass == null && pjp.getTarget() != null) {
		targetClass = pjp.getTarget().getClass();
	}
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the
	// original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	return specificMethod;
}
 
Example #16
Source Project: lams   Author: lamsfoundation   File: AbstractFallbackJCacheOperationSource.java    License: GNU General Public License v2.0 6 votes vote down vote up
private JCacheOperation<?> computeCacheOperation(Method method, Class<?> targetClass) {
	// Don't allow no-public methods as required.
	if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
		return null;
	}

	// The method may be on an interface, but we need attributes from the target class.
	// If the target class is null, the method will be unchanged.
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
	// If we are dealing with method with generic parameters, find the original method.
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

	// First try is the method in the target class.
	JCacheOperation<?> operation = findCacheOperation(specificMethod, targetClass);
	if (operation != null) {
		return operation;
	}
	if (specificMethod != method) {
		// Fallback is to look at the original method.
		operation = findCacheOperation(method, targetClass);
		if (operation != null) {
			return operation;
		}
	}
	return null;
}
 
Example #17
Source Project: alfresco-remote-api   Author: Alfresco   File: ResourceInspectorUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Finds methods for the given annotation
 * 
 * It first finds all public member methods of the class or interface represented by objClass, 
 * including those inherited from superclasses and superinterfaces.
 * 
 * It then loops through these methods searching for a single Annotation of annotationType,
 * traversing its super methods if no annotation can be found on the given method itself.
 * 
 * @param objClass - the class
 * @param annotationType - the annotation to find
 * @return - the List of Method or an empty List
 */
@SuppressWarnings("rawtypes")
public static List<Method> findMethodsByAnnotation(Class objClass, Class<? extends Annotation> annotationType)
{

    List<Method> annotatedMethods = new ArrayList<Method>();
    Method[] methods = objClass.getMethods();
    for (Method method : methods)
    {
        Annotation annot = AnnotationUtils.findAnnotation(method, annotationType);
        if (annot != null) {
            //Just to be sure, lets make sure its not a Bridged (Generic) Method
            Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method);
            annotatedMethods.add(resolvedMethod);
        }
    }
    
    return annotatedMethods;
    
}
 
Example #18
Source Project: spring-analysis-note   Author: Vip-Augus   File: HandlerMethod.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance from a bean instance and a method.
 */
public HandlerMethod(Object bean, Method method) {
	Assert.notNull(bean, "Bean is required");
	Assert.notNull(method, "Method is required");
	this.bean = bean;
	this.beanFactory = null;
	this.beanType = ClassUtils.getUserClass(bean);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
}
 
Example #19
Source Project: spring-analysis-note   Author: Vip-Augus   File: HandlerMethod.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance from a bean instance, method name, and parameter types.
 * @throws NoSuchMethodException when the method cannot be found
 */
public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
	Assert.notNull(bean, "Bean is required");
	Assert.notNull(methodName, "Method name is required");
	this.bean = bean;
	this.beanFactory = null;
	this.beanType = ClassUtils.getUserClass(bean);
	this.method = bean.getClass().getMethod(methodName, parameterTypes);
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(this.method);
	this.parameters = initMethodParameters();
}
 
Example #20
Source Project: spring-analysis-note   Author: Vip-Augus   File: MethodValidationInterceptor.java    License: MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Object invoke(MethodInvocation invocation) throws Throwable {
	// Avoid Validator invocation on FactoryBean.getObjectType/isSingleton
	if (isFactoryBeanMetadataMethod(invocation.getMethod())) {
		return invocation.proceed();
	}

	Class<?>[] groups = determineValidationGroups(invocation);

	// Standard Bean Validation 1.1 API
	ExecutableValidator execVal = this.validator.forExecutables();
	Method methodToValidate = invocation.getMethod();
	Set<ConstraintViolation<Object>> result;

	try {
		result = execVal.validateParameters(
				invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
	}
	catch (IllegalArgumentException ex) {
		// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
		// Let's try to find the bridged method on the implementation class...
		methodToValidate = BridgeMethodResolver.findBridgedMethod(
				ClassUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass()));
		result = execVal.validateParameters(
				invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
	}
	if (!result.isEmpty()) {
		throw new ConstraintViolationException(result);
	}

	Object returnValue = invocation.proceed();

	result = execVal.validateReturnValue(invocation.getThis(), methodToValidate, returnValue, groups);
	if (!result.isEmpty()) {
		throw new ConstraintViolationException(result);
	}

	return returnValue;
}
 
Example #21
Source Project: spring-analysis-note   Author: Vip-Augus   File: ApplicationListenerMethodAdapter.java    License: MIT License 5 votes vote down vote up
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) {
	this.beanName = beanName;
	this.method = BridgeMethodResolver.findBridgedMethod(method);
	this.targetMethod = (!Proxy.isProxyClass(targetClass) ?
			AopUtils.getMostSpecificMethod(method, targetClass) : this.method);
	this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass);

	EventListener ann = AnnotatedElementUtils.findMergedAnnotation(this.targetMethod, EventListener.class);
	this.declaredEventTypes = resolveDeclaredEventTypes(method, ann);
	this.condition = (ann != null ? ann.condition() : null);
	this.order = resolveOrder(this.targetMethod);
}
 
Example #22
Source Project: spring-analysis-note   Author: Vip-Augus   File: CacheAspectSupport.java    License: MIT License 5 votes vote down vote up
public CacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass,
		KeyGenerator keyGenerator, CacheResolver cacheResolver) {

	this.operation = operation;
	this.method = BridgeMethodResolver.findBridgedMethod(method);
	this.targetClass = targetClass;
	this.targetMethod = (!Proxy.isProxyClass(targetClass) ?
			AopUtils.getMostSpecificMethod(method, targetClass) : this.method);
	this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass);
	this.keyGenerator = keyGenerator;
	this.cacheResolver = cacheResolver;
}
 
Example #23
Source Project: spring-analysis-note   Author: Vip-Augus   File: HandlerMethod.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance from a bean instance and a method.
 */
public HandlerMethod(Object bean, Method method) {
	Assert.notNull(bean, "Bean is required");
	Assert.notNull(method, "Method is required");
	this.bean = bean;
	this.beanFactory = null;
	this.beanType = ClassUtils.getUserClass(bean);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
	evaluateResponseStatus();
	this.description = initDescription(this.beanType, this.method);
}
 
Example #24
Source Project: spring-analysis-note   Author: Vip-Augus   File: HandlerMethod.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance from a bean instance, method name, and parameter types.
 * @throws NoSuchMethodException when the method cannot be found
 */
public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
	Assert.notNull(bean, "Bean is required");
	Assert.notNull(methodName, "Method name is required");
	this.bean = bean;
	this.beanFactory = null;
	this.beanType = ClassUtils.getUserClass(bean);
	this.method = bean.getClass().getMethod(methodName, parameterTypes);
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(this.method);
	this.parameters = initMethodParameters();
	evaluateResponseStatus();
	this.description = initDescription(this.beanType, this.method);
}
 
Example #25
Source Project: java-technology-stack   Author: codeEngraver   File: HandlerMethod.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance from a bean instance and a method.
 */
public HandlerMethod(Object bean, Method method) {
	Assert.notNull(bean, "Bean is required");
	Assert.notNull(method, "Method is required");
	this.bean = bean;
	this.beanFactory = null;
	this.beanType = ClassUtils.getUserClass(bean);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
}
 
Example #26
Source Project: java-technology-stack   Author: codeEngraver   File: HandlerMethod.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance from a bean instance, method name, and parameter types.
 * @throws NoSuchMethodException when the method cannot be found
 */
public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
	Assert.notNull(bean, "Bean is required");
	Assert.notNull(methodName, "Method name is required");
	this.bean = bean;
	this.beanFactory = null;
	this.beanType = ClassUtils.getUserClass(bean);
	this.method = bean.getClass().getMethod(methodName, parameterTypes);
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(this.method);
	this.parameters = initMethodParameters();
}
 
Example #27
Source Project: java-technology-stack   Author: codeEngraver   File: MethodValidationInterceptor.java    License: MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Object invoke(MethodInvocation invocation) throws Throwable {
	// Avoid Validator invocation on FactoryBean.getObjectType/isSingleton
	if (isFactoryBeanMetadataMethod(invocation.getMethod())) {
		return invocation.proceed();
	}

	Class<?>[] groups = determineValidationGroups(invocation);

	// Standard Bean Validation 1.1 API
	ExecutableValidator execVal = this.validator.forExecutables();
	Method methodToValidate = invocation.getMethod();
	Set<ConstraintViolation<Object>> result;

	try {
		result = execVal.validateParameters(
				invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
	}
	catch (IllegalArgumentException ex) {
		// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
		// Let's try to find the bridged method on the implementation class...
		methodToValidate = BridgeMethodResolver.findBridgedMethod(
				ClassUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass()));
		result = execVal.validateParameters(
				invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
	}
	if (!result.isEmpty()) {
		throw new ConstraintViolationException(result);
	}

	Object returnValue = invocation.proceed();

	result = execVal.validateReturnValue(invocation.getThis(), methodToValidate, returnValue, groups);
	if (!result.isEmpty()) {
		throw new ConstraintViolationException(result);
	}

	return returnValue;
}
 
Example #28
Source Project: java-technology-stack   Author: codeEngraver   File: ApplicationListenerMethodAdapter.java    License: MIT License 5 votes vote down vote up
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) {
	this.beanName = beanName;
	this.method = BridgeMethodResolver.findBridgedMethod(method);
	this.targetMethod = (!Proxy.isProxyClass(targetClass) ?
			AopUtils.getMostSpecificMethod(method, targetClass) : this.method);
	this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass);

	EventListener ann = AnnotatedElementUtils.findMergedAnnotation(this.targetMethod, EventListener.class);
	this.declaredEventTypes = resolveDeclaredEventTypes(method, ann);
	this.condition = (ann != null ? ann.condition() : null);
	this.order = resolveOrder(this.targetMethod);
}
 
Example #29
Source Project: java-technology-stack   Author: codeEngraver   File: CacheAspectSupport.java    License: MIT License 5 votes vote down vote up
public CacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass,
		KeyGenerator keyGenerator, CacheResolver cacheResolver) {

	this.operation = operation;
	this.method = BridgeMethodResolver.findBridgedMethod(method);
	this.targetClass = targetClass;
	this.targetMethod = (!Proxy.isProxyClass(targetClass) ?
			AopUtils.getMostSpecificMethod(method, targetClass) : this.method);
	this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass);
	this.keyGenerator = keyGenerator;
	this.cacheResolver = cacheResolver;
}
 
Example #30
Source Project: java-technology-stack   Author: codeEngraver   File: HandlerMethod.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance from a bean instance and a method.
 */
public HandlerMethod(Object bean, Method method) {
	Assert.notNull(bean, "Bean is required");
	Assert.notNull(method, "Method is required");
	this.bean = bean;
	this.beanFactory = null;
	this.beanType = ClassUtils.getUserClass(bean);
	this.method = method;
	this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
	this.parameters = initMethodParameters();
	evaluateResponseStatus();
}