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; }
/** * 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(); }
/** * 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; }
/** * 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; }
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; }
/** * 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; }
/** * 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; }
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(); } }
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; }
/** * 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.method = method; this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); this.parameters = initMethodParameters(); }
/** * 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.method = bean.getClass().getMethod(methodName, parameterTypes); this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(this.method); this.parameters = initMethodParameters(); }
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); } } } } } }
/** * 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())); } }
/** * 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; }
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 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; }
/** * 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; } }
/** * 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(); }
/** * 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(); }
/** * 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"); this.bean = beanName; this.beanFactory = beanFactory; this.beanType = ClassUtils.getUserClass(beanFactory.getType(beanName)); this.method = method; this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); this.parameters = initMethodParameters(); }
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) { this.beanName = beanName; this.method = method; this.targetClass = targetClass; this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); this.declaredEventTypes = resolveDeclaredEventTypes(); this.methodKey = new AnnotatedElementKey(this.method, this.targetClass); }
/** * Same signature as {@link #getTransactionAttribute}, but doesn't cache the result. * {@link #getTransactionAttribute} is effectively a caching decorator for this method. * <p>As of 4.1.8, this method can be overridden. * @since 4.1.8 * @see #getTransactionAttribute */ protected 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; }
/** * 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(); this.resolvedFromHandlerMethod = null; }
/** * 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(); this.resolvedFromHandlerMethod = null; }
/** * 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; this.beanType = ClassUtils.getUserClass(beanFactory.getType(beanName)); this.method = method; this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); this.parameters = initMethodParameters(); this.resolvedFromHandlerMethod = null; }
/** * 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.names())); this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types())); } }
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 && ClassUtils.isUserLevelMethod(method)) { return opDef; } if (specificMethod != method) { // Fallback is to look at the original method. opDef = findCacheOperations(method); if (opDef != null) { return opDef; } // Last fallback is the class of the original method. opDef = findCacheOperations(method.getDeclaringClass()); if (opDef != null && ClassUtils.isUserLevelMethod(method)) { return opDef; } } return null; }
public UiEventListenerMethodAdapter(Object instance, Class<?> targetClass, Method method, Events events) { this.instanceRef = new WeakReference<>(instance); this.method = method; this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); this.events = events; Method targetMethod = ClassUtils.getMostSpecificMethod(method, targetClass); EventListener ann = AnnotatedElementUtils.findMergedAnnotation(targetMethod, EventListener.class); this.declaredEventTypes = resolveDeclaredEventTypes(method, ann); if (!ann.condition().isEmpty()) { throw new UnsupportedOperationException("@EventListener condition is not supported for UiEvents"); } this.order = resolveOrder(method); }
private LockAttribute resolveAttribute(final Method method, final Class<?> targetClass) { if (!Modifier.isPublic(method.getModifiers())) { // Only support public methods 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); LockAttribute attribute = getLockAttribute(specificMethod); if (null != attribute) { return attribute; } attribute = getLockAttribute(specificMethod.getDeclaringClass()); if (null != attribute) { return attribute; } if (specificMethod != method) { // Fallback is to look at the original method. attribute = getLockAttribute(method); if (attribute != null) { return attribute; } // Last fallback is the class of the original method. return getLockAttribute(method.getDeclaringClass()); } return null; }
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); Intercept methodData = AnnotationUtils.findAnnotation(bridgedMethod, Intercept.class); if (methodData == null) { return methodProxy.invokeSuper(proxy, args); } else { String interceptionAnnotationData = methodData.value(); String[] paramNames = resolveParamNames(proxy, method, args, interceptionAnnotationData); interceptionAnnotationData = resolveExpression(proxy, method, args, interceptionAnnotationData, paramNames); return interceptor.handle(proxy, method, args, interceptionAnnotationData); } }
/** * Get a single {@link Annotation} of {@code annotationType} from the supplied {@link Method}. * <p>Correctly handles bridge {@link Method Methods} generated by the compiler. * @param method the method to look for annotations on * @param annotationType the annotation type to look for * @return the annotations found * @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method) */ public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) { Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method); A ann = resolvedMethod.getAnnotation(annotationType); if (ann == null) { for (Annotation metaAnn : resolvedMethod.getAnnotations()) { ann = metaAnn.annotationType().getAnnotation(annotationType); if (ann != null) { break; } } } return ann; }