Example usage for org.aspectj.lang.reflect MethodSignature getParameterTypes

List of usage examples for org.aspectj.lang.reflect MethodSignature getParameterTypes

Introduction

In this page you can find the example usage for org.aspectj.lang.reflect MethodSignature getParameterTypes.

Prototype

Class[] getParameterTypes();

Source Link

Usage

From source file:com.amazonaws.services.simpleworkflow.flow.aspectj.AsynchronousAspect.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Around("call(@com.amazonaws.services.simpleworkflow.flow.annotations.Asynchronous * *(..)) && @annotation(asynchronousAnnotation)")
public Object makeAsynchronous(ProceedingJoinPoint pjp, Asynchronous asynchronousAnnotation) throws Throwable {
    final Signature signature = pjp.getStaticPart().getSignature();
    if (signature instanceof MethodSignature) {
        final MethodSignature methodSignature = (MethodSignature) signature;
        int i = 0;
        Object[] methodArguments = pjp.getArgs();
        Annotation[][] parameterAnnotations = methodSignature.getMethod().getParameterAnnotations();
        List<Promise> valueParams = new ArrayList<Promise>();
        for (final Class<?> parameterType : methodSignature.getParameterTypes()) {
            if ((isPromise(parameterType) || isPromiseArray(parameterType)
                    || (isCollection(parameterType) && hasWaitAnnotation(parameterAnnotations[i])))
                    && !hasNoWaitAnnotation(parameterAnnotations[i])) {
                Object param = methodArguments[i];
                if (isPromise(parameterType)) {
                    valueParams.add((Promise) param);
                } else if (isCollection(parameterType)) {
                    valueParams.add(new AndPromise((Collection) param));
                } else {
                    valueParams.add(new AndPromise((Promise[]) param));
                }/*from  ww w .j av  a 2  s .c  om*/
            } else {
                valueParams.add(null);
            }
            i++;
        }

        Promise[] values = valueParams.toArray(new Promise[0]);
        Boolean daemon = asynchronousAnnotation.daemon() ? true : null;
        AsynchronousAspectTask task = new AsynchronousAspectTask(daemon, pjp, values);
        return task.getReturnValue();
    }

    return pjp.proceed();
}

From source file:com.betfair.tornjak.monitor.aop.MonitorAOP.java

License:Apache License

private MonitorMethod getAnnotation(final ProceedingJoinPoint pjp) {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    MonitorMethod fromSignature = signature.getMethod().getAnnotation(MonitorMethod.class);
    if (fromSignature != null) {
        return fromSignature;
    }// w w  w . jav  a  2 s  .  c om
    // right, couldn't find it on the method signature, but we might be looking at an implementation of an interface
    // so now look at the target object/class
    try {
        Method m = pjp.getTarget().getClass().getDeclaredMethod(signature.getName(),
                signature.getParameterTypes());
        return m.getAnnotation(MonitorMethod.class);
    } catch (NoSuchMethodException e) {
        // hmm, not sure we should ever see this
        throw new IllegalStateException("Couldn't find method that was called on the object it was called on");
    }
}

From source file:com.clicktravel.cheddar.application.retry.RetryableAspect.java

License:Apache License

private Method getHandlerMethod(final ProceedingJoinPoint proceedingJoinPoint,
        final Class<? extends Throwable> thrownExceptionClass, final String[] handlerMethodNames) {
    final Class<?> targetClass = proceedingJoinPoint.getThis().getClass();
    final MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
    final Class<?>[] handlerParameterTypes = getExceptionHandlerParameterTypes(thrownExceptionClass,
            methodSignature.getParameterTypes());
    for (final String handlerMethodName : handlerMethodNames) {
        try {// w  w  w.  j a v  a2  s .com
            return targetClass.getMethod(handlerMethodName, handlerParameterTypes);
        } catch (final ReflectiveOperationException e) {
            // Exception handler method signature does not match - Skip this exception handler
        }
    }
    return null;
}

From source file:com.clicktravel.cheddar.application.retry.RetryableAspectTest.java

License:Apache License

@Test
public void shouldAttemptMethodAndCallExceptionHandler_withExceptionThrownAndExceptionHandlerNamed()
        throws Throwable {
    // Given/*  w w  w .j a v  a  2  s  .  c o m*/
    final RetryableAspect retryableAspect = new RetryableAspect();
    final ProceedingJoinPoint mockProceedingJoinPoint = setupSimpleProceedingJoinPointMock();
    final Retryable mockRetryable = setupSimpleRetryableMock();
    final RetryExceptionHandler retryExceptionHandler = new RetryExceptionHandler();
    final MethodSignature mockMethodSignature = mock(MethodSignature.class);
    final String exceptionHandlerName = "joinPointMethodExceptionHandlingMethod";

    RetryableConfiguration.setRetryableEnabled(false);
    when(mockProceedingJoinPoint.proceed()).thenThrow(new RetryAspectTestException());
    when(mockProceedingJoinPoint.getThis()).thenReturn(retryExceptionHandler);
    when(mockProceedingJoinPoint.getSignature()).thenReturn(mockMethodSignature);
    when(mockProceedingJoinPoint.getArgs()).thenReturn(new Object[] { "exampleArgument" });
    when(mockMethodSignature.getParameterTypes()).thenReturn(
            RetryExceptionHandler.class.getDeclaredMethod("joinPointMethod", String.class).getParameterTypes());
    when(mockRetryable.exceptionHandlers()).thenReturn(new String[] { exceptionHandlerName });

    // When
    retryableAspect.attemptMethodAndRetryIfNeeded(mockProceedingJoinPoint, mockRetryable);

    // Then
    verify(mockProceedingJoinPoint).proceed();

    assertTrue(retryExceptionHandler.exceptionHandlerBeenCalled);
}

From source file:com.clicktravel.cheddar.application.retry.RetryableAspectTest.java

License:Apache License

private ProceedingJoinPoint setupSimpleProceedingJoinPointMock() {
    final ProceedingJoinPoint mockProceedingJoinPoint = mock(ProceedingJoinPoint.class);
    final MethodSignature mockMethodSignature = mock(MethodSignature.class);

    when(mockProceedingJoinPoint.getThis()).thenReturn(mockProceedingJoinPoint);
    when(mockProceedingJoinPoint.getSignature()).thenReturn(mockMethodSignature);
    when(mockMethodSignature.getParameterTypes()).thenReturn(new Class[0]);
    return mockProceedingJoinPoint;
}

From source file:com.github.eemmiirr.redisdata.signalizer.RedisDataSignalizerAspect.java

License:LGPL

@Around("redisTransactionalPointcut()")
public Object redisTransactionalAroundAdvice(ProceedingJoinPoint pjp) throws Throwable {

    // Retrieve the RedisData annotation from either the Type or the Method
    // If both are present the Method will override the Type annotation
    final MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    final Method method = pjp.getTarget().getClass().getMethod(methodSignature.getName(),
            methodSignature.getParameterTypes());
    final RedisData redisData = retrieveRedisTransactionalAnnotation(method);

    try {//from   w  w  w.  j  av  a2 s  . c o  m
        redisTransactionalBeforeAdvice(redisData);
        final Object returnValue = pjp.proceed();
        redisTransactionalAfterAdvice(redisData);
        return returnValue;
    } catch (Throwable t) {
        redisTransactionalAfterThrowing(t, redisData);
        throw t;
    }
}

From source file:com.google.code.ssm.aop.CacheBase.java

License:Open Source License

public Method getMethodToCache(final JoinPoint jp) throws NoSuchMethodException {
    final Signature sig = jp.getSignature();
    if (!(sig instanceof MethodSignature)) {
        throw new InvalidAnnotationException("This annotation is only valid on a method.");
    }/*from  w  w  w. j  av  a2s. c  om*/

    final MethodSignature msig = (MethodSignature) sig;
    final Object target = jp.getTarget();

    // cannot use msig.getMethod() because it can return the method where annotation was declared i.e. method in
    // interface
    String name = msig.getName();
    Class<?>[] parameters = msig.getParameterTypes();

    Method method = findMethodFromTargetGivenNameAndParams(target, name, parameters);

    if (method.isBridge()) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Method is bridge. Name {}, params: {}", name, parameters);
        }

        parameters = bridgeMethodMappingStore.getTargetParamsTypes(target.getClass(), name, parameters);
        method = findMethodFromTargetGivenNameAndParams(target, name, parameters);
    }

    return method;
}

From source file:com.googlecode.easiest.cache.ever.CacheAspect.java

License:Apache License

private MethodCall buildMethodCall(ProceedingJoinPoint joinPoint) {
    final MethodSignature methodSignature;

    if (joinPoint.getSignature() instanceof MethodSignature) {
        methodSignature = (MethodSignature) joinPoint.getSignature();
    } else {// ww w.  jav a  2  s .  co  m
        throw new RuntimeException(
                "Spring can only join on methods, so casting to MethodSignature should always work.");
    }

    final String concreteClassName = joinPoint.getTarget().getClass().getName();

    return new MethodCall(concreteClassName, methodSignature.getName(), methodSignature.getParameterTypes(),
            joinPoint.getArgs());
}

From source file:com.liferay.util.aspectj.AspectJUtil.java

License:Open Source License

public static Method getMethod(MethodSignature methodSignature) throws NoSuchMethodException {

    Method method = null;/*  w  w w . jav a  2  s .  co m*/

    if (ServerDetector.isWebSphere()) {
        Class<?> declaringType = methodSignature.getDeclaringType();
        String name = methodSignature.getName();
        Class<?>[] parameterTypes = methodSignature.getParameterTypes();

        method = declaringType.getMethod(name, parameterTypes);
    } else {
        method = methodSignature.getMethod();
    }

    return method;
}

From source file:com.netflix.hystrix.contrib.javanica.utils.ajc.AjcUtils.java

License:Apache License

public static Method getAjcMethodAroundAdvice(Class<?> target, MethodSignature signature) {
    return getAjcMethodAroundAdvice(target, signature.getMethod().getName(), signature.getParameterTypes());
}