Example usage for org.springframework.core BridgeMethodResolver findBridgedMethod

List of usage examples for org.springframework.core BridgeMethodResolver findBridgedMethod

Introduction

In this page you can find the example usage for org.springframework.core BridgeMethodResolver findBridgedMethod.

Prototype

public static Method findBridgedMethod(Method bridgeMethod) 

Source Link

Document

Find the original method for the supplied Method bridge Method .

Usage

From source file:io.dyn.core.handler.HandlerMethod.java

public HandlerMethod(Method method, HandlerMethodArgument[] arguments, Guard guard) {
    this.method = method;
    ReflectionUtils.makeAccessible(method);
    this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
    ReflectionUtils.makeAccessible(bridgedMethod);
    this.arguments = arguments;
    this.guard = guard;
    this.invocationHandler = (Proxy.isProxyClass(method.getDeclaringClass())
            ? Proxy.getInvocationHandler(method.getDeclaringClass())
            : null);/*from  w w  w .j a  v a2  s . c  o m*/
}

From source file:com.gradecak.alfresco.mvc.aop.RunAsAdvice.java

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./* w  ww .j ava 2s  .  c o m*/
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
    AlfrescoRunAs alfrescounRunAs = parseRunAsAnnotation(specificMethod);
    if (alfrescounRunAs != null) {
        String runAs = alfrescounRunAs.value();
        if (StringUtils.hasText(runAs)) {
            RunAsWork<Object> getUserNameRunAsWork = new RunAsWork<Object>() {
                public Object doWork() throws Exception {
                    try {
                        return invocation.proceed();
                    } catch (Throwable e) {
                        throw new Exception(e.getMessage(), e);
                    }
                }
            };
            return AuthenticationUtil.runAs(getUserNameRunAsWork, runAs);
        }
    }

    return invocation.proceed();
}

From source file:com.gradecak.alfresco.mvc.aop.TransactionalAdvice.java

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./* w  ww. j a v  a 2s .c  o  m*/
    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.getTransactionService().getRetryingTransactionHelper()
                .doInTransaction(exampleWork, readonly, requiresNew);
    } else {
        return invocation.proceed();
    }

}

From source file:com.gradecak.alfresco.mvc.aop.AuthenticationAdvice.java

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.//from  w w  w. ja v  a  2 s. c  o  m
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    AlfrescoAuthentication alfrescoAuthentication = parseAnnotation(specificMethod);

    if (alfrescoAuthentication != null) {

        AuthenticationType authenticationType = alfrescoAuthentication.value();

        if (authenticationType != null && !AuthenticationType.NONE.equals(authenticationType)) {
            AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
            AuthorityService authorityService = serviceRegistry.getAuthorityService();

            String ticket = getTicket();
            if (StringUtils.hasText(ticket)) {
                authenticationService.validate(ticket);
                if (AuthenticationType.USER.equals(authenticationType)
                        && authorityService.hasGuestAuthority()) {
                    throw new AuthenticationException(
                            "User has guest authority where at least a user authentication is required.");
                } else if (AuthenticationType.ADMIN.equals(authenticationType)
                        && !authorityService.hasAdminAuthority()) {
                    throw new AuthenticationException(
                            "User does not have admin authority where at least named admin authentication is required .");
                }
            } else if (AuthenticationType.GUEST.equals(authenticationType)
                    && authenticationService.guestUserAuthenticationAllowed()) {
                authenticationService.authenticateAsGuest();
            } else {
                throw new AuthenticationException(
                        "\nUnable to authenticate due to one of the following reasons:\n"
                                + "Credentials are not provided in HTTP request where at least named user or admin authentication is required.\n"
                                + "Guest user authentication is not allowed where at least guest authentication is required.\n");
            }
        }
    }

    return invocation.proceed();
}

From source file:org.zkybase.kite.throttle.interceptor.AnnotationThrottleSource.java

public ThrottleTemplate getThrottle(Method method, Class<?> targetClass) {
    Assert.notNull(method, "method can't be null");

    // Method may be on an interface, but we need annotations from the
    // target class. If target class is null, method will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);

    // If we are dealing with a method with generic parameters, find the
    // original method.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    ThrottleTemplate throttle = parseAnnotation(specificMethod);
    if (throttle != null) {
        return throttle;
    } else {// w  w  w.j a va 2s.c  o m
        return parseAnnotation(method);
    }
}

From source file:org.zkybase.kite.circuitbreaker.interceptor.AnnotationCircuitBreakerSource.java

public CircuitBreakerTemplate getBreaker(Method method, Class<?> targetClass) {
    Assert.notNull(method, "method can't be null");

    // Method may be on an interface, but we need annotations from the
    // target class. If target class is null, method will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);

    // If we are dealing with a method with generic parameters, find the
    // original, bridged method.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    CircuitBreakerTemplate breaker = parseAnnotation(specificMethod);
    return (breaker != null ? breaker : parseAnnotation(method));
}

From source file:com.springinpractice.ch14.kite.interceptor.AnnotationGuardListSource.java

@Override
public List<Guard> getGuards(Method method, Class<?> targetClass) {
    notNull(method, "method can't be null");

    // Method may be on an interface, but we need annotations from the target class. If target class is null, method
    // will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);

    // If we are dealing with a method with generic parameters, find the original method.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    List<Guard> guards = parseAnnotation(specificMethod);
    return (guards != null ? guards : parseAnnotation(method));
}

From source file:org.craftercms.commons.ebus.config.EBusBeanAutoConfiguration.java

private static Set<Method> findHandlerMethods(final Class<?> handlerType,
        final ReflectionUtils.MethodFilter listenerMethodFilter) {

    final Set<Method> handlerMethods = new LinkedHashSet<Method>();

    if (handlerType == null) {
        return handlerMethods;
    }//from   w  w w.  j a v  a2 s .c o m

    Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
    Class<?> specifiedHandlerType = null;
    if (!Proxy.isProxyClass(handlerType)) {
        handlerTypes.add(handlerType);
        specifiedHandlerType = handlerType;
    }
    handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
    for (Class<?> currentHandlerType : handlerTypes) {
        final Class<?> targetClass = (specifiedHandlerType != null ? specifiedHandlerType : currentHandlerType);
        ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
            @Override
            public void doWith(final Method method) throws IllegalArgumentException, IllegalAccessException {
                Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
                Method bridgeMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
                if (listenerMethodFilter.matches(specificMethod)
                        && (bridgeMethod == specificMethod || !listenerMethodFilter.matches(bridgeMethod))) {
                    handlerMethods.add(specificMethod);
                }
            }
        }, ReflectionUtils.USER_DECLARED_METHODS);
    }

    return handlerMethods;
}

From source file:org.jsr107.ri.annotations.spring.CacheContextSourceImpl.java

@Override
protected <T extends Annotation> T getAnnotation(Class<T> annotationClass, Method method,
        Class<? extends Object> 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.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    final T annotation = specificMethod.getAnnotation(annotationClass);
    if (annotation != null) {
        return annotation;
    }/*from  w w  w.  j  a va  2s.  c om*/

    if (specificMethod != method) {
        // Fallback is to look at the original method.
        return method.getAnnotation(annotationClass);
    }

    return null;
}

From source file:de.taimos.dvalin.interconnect.core.spring.InterconnectBeanPostProcessor.java

private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
    Class<?> targetClass = clazz;

    do {/*from  w w  w  .j  ava2s  .  c om*/
        LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
        for (Field field : targetClass.getDeclaredFields()) {
            if (field.isAnnotationPresent(Interconnect.class)) {
                if (Modifier.isStatic(field.getModifiers())) {
                    throw new IllegalStateException(
                            "@Interconnect annotation is not supported on static fields");
                }
                currElements.add(new InterconnectElement(field, null));
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
            if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
                continue;
            }
            if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                if (bridgedMethod.isAnnotationPresent(Interconnect.class)) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException(
                                "@Interconnect annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length != 1) {
                        throw new IllegalStateException(
                                "@Interconnect annotation requires a single-arg method: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
                    currElements.add(new InterconnectElement(method, pd));
                }
            }
        }
        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    } while ((targetClass != null) && (targetClass != Object.class));

    return new InjectionMetadata(clazz, elements);
}