本文整理汇总了Java中org.springframework.core.BridgeMethodResolver类的典型用法代码示例。如果您正苦于以下问题:Java BridgeMethodResolver类的具体用法?Java BridgeMethodResolver怎么用?Java BridgeMethodResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BridgeMethodResolver类属于org.springframework.core包,在下文中一共展示了BridgeMethodResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpecificmethod
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
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;
}
示例2: HandlerMethod
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* 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 the 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");
Assert.isTrue(beanFactory.containsBean(beanName),
"BeanFactory [" + beanFactory + "] does not contain bean [" + beanName + "]");
this.bean = beanName;
this.beanFactory = beanFactory;
this.method = method;
this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
this.parameters = initMethodParameters();
}
示例3: selectMethods
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* Select handler methods for the given handler type.
* <p>Callers define handler methods of interest through the {@link MethodFilter} parameter.
* @param handlerType the handler type to search handler methods on
* @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest
* @return the selected methods, or an empty set
*/
public static Set<Method> selectMethods(final Class<?> handlerType, final MethodFilter handlerMethodFilter) {
final Set<Method> handlerMethods = new LinkedHashSet<Method>();
Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
Class<?> specificHandlerType = null;
if (!Proxy.isProxyClass(handlerType)) {
handlerTypes.add(handlerType);
specificHandlerType = handlerType;
}
handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
for (Class<?> currentHandlerType : handlerTypes) {
final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) {
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
if (handlerMethodFilter.matches(specificMethod) &&
(bridgedMethod == specificMethod || !handlerMethodFilter.matches(bridgedMethod))) {
handlerMethods.add(specificMethod);
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
}
return handlerMethods;
}
示例4: findMethodsByAnnotation
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* 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;
}
示例5: computeCacheOperation
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
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;
}
示例6: getSpecificmethod
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* Finds out the most specific method when the execution reference is an
* interface or a method with generic parameters
*
* @param pjp
* @return
*/
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;
}
示例7: selectMethods
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* Select handler methods for the given handler type.
* <p>Callers define handler methods of interest through the {@link MethodFilter} parameter.
* @param handlerType the handler type to search handler methods on
* @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest
* @return the selected methods, or an empty set
*/
public static Set<Method> selectMethods(final Class<?> handlerType, final MethodFilter handlerMethodFilter) {
final Set<Method> handlerMethods = new LinkedHashSet<Method>();
Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
Class<?> specificHandlerType = null;
if (!Proxy.isProxyClass(handlerType)) {
handlerTypes.add(handlerType);
specificHandlerType = handlerType;
}
handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
for (Class<?> currentHandlerType : handlerTypes) {
final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
if (handlerMethodFilter.matches(specificMethod) &&
(bridgedMethod == specificMethod || !handlerMethodFilter.matches(bridgedMethod))) {
handlerMethods.add(specificMethod);
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
}
return handlerMethods;
}
示例8: invoke
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
public Object invoke(final MethodInvocation invocation) throws Throwable {
Class<?> targetClass = invocation.getThis() != null ? invocation.getThis().getClass() : null;
Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
// If we are dealing with method with generic parameters, find the original
// method.
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
AlfrescoTransaction alfrescoTransaction = parseAnnotation(specificMethod);
if (alfrescoTransaction != null) {
RetryingTransactionCallback<Object> exampleWork = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
return invocation.proceed();
}
};
boolean readonly = alfrescoTransaction.readOnly();
Propagation propagation = alfrescoTransaction.propagation();
boolean requiresNew = Propagation.REQUIRES_NEW.equals(propagation);
return serviceRegistry.getRetryingTransactionHelper().doInTransaction(exampleWork, readonly, requiresNew);
} else {
return invocation.proceed();
}
}
示例9: computeSecurityAttribute
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
private SecurityAttribute computeSecurityAttribute(Method method, Class<?> targetClass)
{
// 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.
if( JdkVersion.isAtLeastJava15() )
{
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
}
// First try is the method in the target class.
SecurityAttribute txAtt = findSecurityAttribute(specificMethod, targetClass);
if( txAtt != null )
{
return txAtt;
}
if( !specificMethod.equals(method) )
{
// Fallback is to look at the original method.
txAtt = findSecurityAttribute(method, targetClass);
if( txAtt != null )
{
return txAtt;
}
}
return null;
}
示例10: initBinder
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
protected void initBinder(Object handler, String attrName, WebDataBinder binder, NativeWebRequest webRequest)
throws Exception {
if (this.bindingInitializer != null) {
this.bindingInitializer.initBinder(binder, webRequest);
}
if (handler != null) {
Set<Method> initBinderMethods = this.methodResolver.getInitBinderMethods();
if (!initBinderMethods.isEmpty()) {
boolean debug = logger.isDebugEnabled();
for (Method initBinderMethod : initBinderMethods) {
Method methodToInvoke = BridgeMethodResolver.findBridgedMethod(initBinderMethod);
String[] targetNames = AnnotationUtils.findAnnotation(initBinderMethod, InitBinder.class).value();
if (targetNames.length == 0 || Arrays.asList(targetNames).contains(attrName)) {
Object[] initBinderArgs =
resolveInitBinderArguments(handler, methodToInvoke, binder, webRequest);
if (debug) {
logger.debug("Invoking init-binder method: " + methodToInvoke);
}
ReflectionUtils.makeAccessible(methodToInvoke);
Object returnValue = methodToInvoke.invoke(handler, initBinderArgs);
if (returnValue != null) {
throw new IllegalStateException(
"InitBinder methods must not have a return value: " + methodToInvoke);
}
}
}
}
}
}
示例11: init
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* Initialize a new HandlerMethodResolver for the specified handler type.
* @param handlerType the handler class to introspect
*/
public void init(final Class<?> handlerType) {
Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
Class<?> specificHandlerType = null;
if (!Proxy.isProxyClass(handlerType)) {
handlerTypes.add(handlerType);
specificHandlerType = handlerType;
}
handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
for (Class<?> currentHandlerType : handlerTypes) {
final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) {
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
if (isHandlerMethod(specificMethod) &&
(bridgedMethod == specificMethod || !isHandlerMethod(bridgedMethod))) {
handlerMethods.add(specificMethod);
}
else if (isInitBinderMethod(specificMethod) &&
(bridgedMethod == specificMethod || !isInitBinderMethod(bridgedMethod))) {
initBinderMethods.add(specificMethod);
}
else if (isModelAttributeMethod(specificMethod) &&
(bridgedMethod == specificMethod || !isModelAttributeMethod(bridgedMethod))) {
modelAttributeMethods.add(specificMethod);
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
}
this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
this.sessionAttributesFound = (sessionAttributes != null);
if (this.sessionAttributesFound) {
this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
}
}
示例12: computeTransactionAttribute
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* Same signature as {@link #getTransactionAttribute}, but doesn't cache the result.
* {@link #getTransactionAttribute} is effectively a caching decorator for this method.
* @see #getTransactionAttribute
*/
private TransactionAttribute computeTransactionAttribute(Method method, Class<?> targetClass) {
// Don't allow no-public methods as required.
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
return null;
}
// Ignore CGLIB subclasses - introspect the actual user class.
Class<?> userClass = ClassUtils.getUserClass(targetClass);
// 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, userClass);
// 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.
TransactionAttribute txAtt = findTransactionAttribute(specificMethod);
if (txAtt != null) {
return txAtt;
}
// Second try is the transaction attribute on the target class.
txAtt = findTransactionAttribute(specificMethod.getDeclaringClass());
if (txAtt != null) {
return txAtt;
}
if (specificMethod != method) {
// Fallback is to look at the original method.
txAtt = findTransactionAttribute(method);
if (txAtt != null) {
return txAtt;
}
// Last fallback is the class of the original method.
return findTransactionAttribute(method.getDeclaringClass());
}
return null;
}
示例13: GenericTypeAwarePropertyDescriptor
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
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;
}
}
}
示例14: computeCacheOperations
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
private Collection<CacheOperation> computeCacheOperations(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.
Collection<CacheOperation> opDef = findCacheOperations(specificMethod);
if (opDef != null) {
return opDef;
}
// Second try is the caching operation on the target class.
opDef = findCacheOperations(specificMethod.getDeclaringClass());
if (opDef != null) {
return opDef;
}
if (specificMethod != method) {
// Fall back is to look at the original method.
opDef = findCacheOperations(method);
if (opDef != null) {
return opDef;
}
// Last fall back is the class of the original method.
return findCacheOperations(method.getDeclaringClass());
}
return null;
}
示例15: determineType
import org.springframework.core.BridgeMethodResolver; //导入依赖的package包/类
/**
* Determine the expected type as the returned type of the method.
* If the return type is a List it will return the generic element type instead of a List.
* @param resource - resource with methods
* @param method Method
* @return Class - type of class it needs.
*/
@SuppressWarnings("rawtypes")
protected static Class determineType(Class resource, Method method)
{
Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method);
/*
* The api is consistent that the object passed in must match the object passed out
* however, operations are different, if the param is supplied it doesn't have to match
* the return type.
* So we need special logic for operations
*/
Annotation annot = AnnotationUtils.findAnnotation(resolvedMethod, Operation.class);
if (annot != null)
{
return determineOperationType(resource, method);
}
else
{
Class returnType = GenericTypeResolver.resolveReturnType(resolvedMethod, resource);
if (List.class.isAssignableFrom(returnType))
{
return GenericCollectionTypeResolver.getCollectionReturnType(method);
}
return returnType;
}
}