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

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

Introduction

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

Prototype

Method getMethod();

Source Link

Usage

From source file:org.alfresco.traitextender.AJExtender.java

License:Open Source License

/**
 * @param method/*from  w  w  w.ja va2 s .  co  m*/
 * @return <code>true</code> if the given method has the same signature as
 *         the currently aspectJ extension-overridden method
 */
static boolean isLocalProceeder(Method method) {
    if (!ajLocalProceedingJoinPoints.get().isEmpty()) {
        ProceedingContext proceedingCotext = ajLocalProceedingJoinPoints.get().peek();
        MethodSignature ms = (MethodSignature) proceedingCotext.proceedingJoinPoint.getSignature();
        Method jpMethod = ms.getMethod();
        return jpMethod.getName().endsWith(method.getName())
                && Arrays.equals(jpMethod.getParameterTypes(), method.getParameterTypes());
    } else {
        return false;
    }
}

From source file:org.alfresco.traitextender.RouteExtensions.java

License:Open Source License

@Around("execution(@org.alfresco.traitextender.Extend * *(..)) && (@annotation(extendAnnotation))")
public Object intercept(ProceedingJoinPoint pjp, Extend extendAnnotation) throws Throwable {
    boolean ajPointsEnabled = AJExtender.areAJPointsEnabled();
    try {/*from w w w . ja v  a2 s  .c om*/
        AJExtender.enableAJPoints();
        if (ajPointsEnabled) {
            Object extensibleObject = pjp.getThis();
            if (!(extensibleObject instanceof Extensible)) {
                throw new InvalidExtension(
                        "Invalid extension point for non extensible class  : " + extensibleObject.getClass());
            }
            Extensible extensible = (Extensible) extensibleObject;

            @SuppressWarnings({ "rawtypes", "unchecked" })
            ExtensionPoint point = new ExtensionPoint(extendAnnotation.extensionAPI(),
                    extendAnnotation.traitAPI());
            @SuppressWarnings("unchecked")
            Object extension = Extender.getInstance().getExtension(extensible, point);
            if (extension != null) {

                return AJExtender.extendAroundAdvice(pjp, extensible, extendAnnotation, extension);
            } else if (logger.isDebugEnabled()) {
                MethodSignature ms = (MethodSignature) pjp.getSignature();
                Method traitMethod = ms.getMethod();

                AJExtender.oneTimeLiveLog(logger, new ExtensionRoute(extendAnnotation, traitMethod));
            }
        }
        return pjp.proceed();
    } finally {
        AJExtender.revertAJPoints();
    }
}

From source file:org.apache.rave.synchronization.SynchronizingAspect.java

License:Apache License

@Around("synchronizePointcut()")
public Object synchronizeInvocation(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
    Method method = methodSignature.getMethod();
    Object target = proceedingJoinPoint.getTarget();
    Object[] args = proceedingJoinPoint.getArgs();
    Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
    Synchronized annotation = getAnnotation(targetClass, method);
    Validate.notNull(annotation, "Could not find @Synchronized annotation!");

    Lock lock = getLock(targetClass, method, args, annotation);
    if (lock == null) {
        logger.debug(//w w  w  . j  a  va  2 s.c  o  m
                "No lock obtained for call [{}] on targetClass [{}] - proceeding without synchronization on "
                        + "thread {}",
                new Object[] { method.getName(), targetClass.getName(), Thread.currentThread().getId() });
        return proceedingJoinPoint.proceed();
    } else {
        try {
            logger.debug(
                    "Lock obtained for call [{}] on targetClass [{}] - proceeding with synchronization on thread {}",
                    new Object[] { method.getName(), targetClass.getName(), Thread.currentThread().getId() });
            lock.lock();
            return proceedingJoinPoint.proceed();
        } finally {
            lock.unlock();
            lockService.returnLock(lock);
        }
    }
}

From source file:org.apache.rave.synchronization.SynchronizingAspectTest.java

License:Apache License

private ProceedingJoinPoint prepareJoinPoint(String expectedDiscriminator, String expectedId,
        TestService service, Method expectedMethod, TestObject argument, Object[] joinPointArgs)
        throws Throwable {
    MethodSignature methodSignature = createMock(MethodSignature.class);
    expect(methodSignature.getMethod()).andReturn(expectedMethod);
    replay(methodSignature);/*ww  w  . j a  v  a2 s.  com*/

    ProceedingJoinPoint joinPoint = createMock(ProceedingJoinPoint.class);
    expect(joinPoint.getSignature()).andReturn(methodSignature);
    expect(joinPoint.getTarget()).andReturn(service);
    expect(joinPoint.getArgs()).andReturn(joinPointArgs);
    expect(joinPoint.proceed()).andReturn(expectedMethod.invoke(service, argument));
    replay(joinPoint);

    Lock lock = new ReentrantLock();
    expect(lockService.borrowLock(expectedDiscriminator, expectedId)).andReturn(lock);
    lockService.returnLock(lock);
    replay(lockService);
    return joinPoint;
}

From source file:org.apache.syncope.core.logic.LogicInvocationHandler.java

License:Apache License

@Around("execution(* org.apache.syncope.core.logic.AbstractLogic+.*(..))")
public Object around(final ProceedingJoinPoint joinPoint) throws Throwable {
    Class<?> clazz = joinPoint.getTarget().getClass();

    Object[] input = joinPoint.getArgs();

    String category = clazz.getSimpleName();

    MethodSignature ms = (MethodSignature) joinPoint.getSignature();
    Method method = ms.getMethod();

    String event = joinPoint.getSignature().getName();

    AuditElements.Result result = null;
    Object output = null;//from  w  w w .  ja va2  s.  com
    Object before = null;

    try {
        LOG.debug("Before {}.{}({})", clazz.getSimpleName(), event,
                input == null || input.length == 0 ? "" : Arrays.asList(input));

        try {
            before = ((AbstractLogic) joinPoint.getTarget()).resolveBeanReference(method, input);
        } catch (UnresolvedReferenceException ignore) {
            LOG.debug("Unresolved bean reference ...");
        }

        output = joinPoint.proceed();
        result = AuditElements.Result.SUCCESS;

        LOG.debug("After returning {}.{}: {}", clazz.getSimpleName(), event, output);
        return output;
    } catch (Throwable t) {
        output = t;
        result = AuditElements.Result.FAILURE;

        LOG.debug("After throwing {}.{}", clazz.getSimpleName(), event);
        throw t;
    } finally {
        notificationManager.createTasks(AuditElements.EventCategoryType.LOGIC, category, null, event, result,
                before, output, input);

        auditManager.audit(AuditElements.EventCategoryType.LOGIC, category, null, event, result, before, output,
                input);
    }
}

From source file:org.apache.syncope.core.rest.controller.ControllerHandler.java

License:Apache License

@Around("execution(* org.apache.syncope.core.rest.controller.AbstractController+.*(..))")
public Object around(final ProceedingJoinPoint joinPoint) throws Throwable {
    final Class<?> clazz = joinPoint.getTarget().getClass();

    final Object[] input = joinPoint.getArgs();

    final String category = clazz.getSimpleName();

    final MethodSignature ms = (MethodSignature) joinPoint.getSignature();
    Method method = ms.getMethod();

    final String event = joinPoint.getSignature().getName();

    AuditElements.Result result = null;
    Object output = null;/*from w ww  .ja va 2 s  .c o  m*/
    Object before = null;

    try {
        LOG.debug("Before {}.{}({})", clazz.getSimpleName(), event,
                input == null || input.length == 0 ? "" : Arrays.asList(input));

        try {
            before = ((AbstractController) joinPoint.getTarget()).resolveBeanReference(method, input);
        } catch (UnresolvedReferenceException ignore) {
            LOG.debug("Unresolved bean reference ...");
        }

        output = joinPoint.proceed();
        result = AuditElements.Result.SUCCESS;

        LOG.debug("After returning {}.{}: {}", clazz.getSimpleName(), event, output);
        return output;
    } catch (Throwable t) {
        output = t;
        result = AuditElements.Result.FAILURE;

        LOG.debug("After throwing {}.{}", clazz.getSimpleName(), event);
        throw t;
    } finally {
        notificationManager.createTasks(AuditElements.EventCategoryType.REST, category, null, event, result,
                before, output, input);

        auditManager.audit(AuditElements.EventCategoryType.REST, category, null, event, result, before, output,
                input);
    }
}

From source file:org.audit4j.integration.spring.AuditAspect.java

License:Apache License

/**
 * Audit Aspect./*from w  w  w  .  j a  va2  s.c o m*/
 * 
 * @param jointPoint
 *            the joint point
 * @throws Throwable
 *             the throwable
 */
@Before("@within(org.audit4j.core.annotation.Audit) || @annotation(org.audit4j.core.annotation.Audit)")
public void audit(final JoinPoint jointPoint) throws Throwable {

    MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature();
    Method method = methodSignature.getMethod();

    if (method.getDeclaringClass().isInterface()) {
        try {
            method = jointPoint.getTarget().getClass().getDeclaredMethod(jointPoint.getSignature().getName(),
                    method.getParameterTypes());
        } catch (final SecurityException exception) {
            throw new Audit4jRuntimeException(
                    "Exception occured while proceding Audit Aspect in Audit4j Spring Integration", exception);
        } catch (final NoSuchMethodException exception) {
            throw new Audit4jRuntimeException(
                    "Exception occured while proceding Audit Aspect in Audit4j Spring Integration", exception);
        }
    }

    AuditManager.getInstance().audit(jointPoint.getTarget().getClass(), method, jointPoint.getArgs());
}

From source file:org.audit4j.integration.spring.AuditAspectOld.java

License:Apache License

/**
 * Audit.//from   w  ww  .j ava 2 s  .c  o  m
 * 
 * @param jointPoint
 *            the pjp
 * 
 * @throws Throwable
 *             the throwable
 */
public void audit(final JoinPoint jointPoint) throws Throwable {
    MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature();
    Method method = methodSignature.getMethod();
    AuditManager.getInstance().audit(jointPoint.getTarget().getClass(), method, jointPoint.getArgs());
}

From source file:org.bigtester.ate.model.casestep.StepDataLogger.java

License:Apache License

private RefreshDataType getDataType(JoinPoint thisJoinPoint) {

    MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature();
    String methodName = methodSignature.getMethod().getName();
    Class<?>[] parameterTypes = methodSignature.getMethod().getParameterTypes();
    Method targetMethod;/*w w w.  j  a  v  a  2 s.c  o m*/
    try {
        targetMethod = thisJoinPoint.getTarget().getClass().getMethod(methodName, parameterTypes);
        return ((RepeatStepRefreshable) targetMethod.getAnnotation(RepeatStepRefreshable.class)).dataType();
    } catch (NoSuchMethodException | SecurityException e) {
        throw GlobalUtils.createInternalError("jvm class method error", e);
    }
    // targetMethod = methodSignature.getMethod();

}

From source file:org.codehaus.grepo.statistics.service.MethodStatisticsAspect.java

License:Apache License

/**
 * @param pjp The proceeding join point.
 * @param annotation The {@link MethodStatistics} annotation.
 * @return Returns the entry./*from   w  ww  . j a  v  a 2s .  c  o m*/
 */
private StatisticsEntry createEntry(ProceedingJoinPoint pjp, MethodStatistics annotation) {
    StatisticsEntry entry = null;
    try {
        MethodSignature methodSig = (MethodSignature) pjp.getSignature();
        Method method = methodSig.getMethod();
        MethodParameterInfo mpi = new MethodParameterInfoImpl(method, pjp.getArgs());

        String identifier = statisticsIdentifierNamingStrategy.getIdentifier(mpi, annotation);

        entry = getStatisticsManager(annotation.manager()).createStatisticsEntry(identifier,
                annotation.origin());

    } catch (Exception e) {
        logger.error("Unable to create StatisticsEntry: " + e.getMessage(), e);
    }
    return entry;
}