Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getSignature.

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:org.obiba.mica.core.LoggingAspect.java

License:Open Source License

@Around(WITHIN_EXPR)
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    logger.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
            joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    try {//from   ww  w. j  av  a2 s . c  o  m
        Object result = joinPoint.proceed();
        logger.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), result);
        return result;
    } catch (IllegalArgumentException e) {
        logger.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
        throw e;
    }
}

From source file:org.onebusaway.container.cache.CacheableMethodKeyFactoryManager.java

License:Apache License

public Method getMatchingMethodForJoinPoint(ProceedingJoinPoint pjp) {
    List<Method> methods = getMatchingMethodsForJoinPoint(pjp);
    if (methods.size() == 1) {
        return methods.get(0);
    } else if (methods.size() == 0) {
        throw new IllegalArgumentException("method not found: pjp=" + pjp.getSignature());
    } else {// w w  w  .  ja  v a2s.c o m
        throw new IllegalArgumentException("multiple methods found: pjp=" + pjp.getSignature());
    }
}

From source file:org.onebusaway.container.cache.CacheableMethodKeyFactoryManager.java

License:Apache License

public List<Method> getMatchingMethodsForJoinPoint(ProceedingJoinPoint pjp) {

    Signature sig = pjp.getSignature();

    Object target = pjp.getTarget();
    Class<?> type = target.getClass();

    List<Method> matches = new ArrayList<Method>();

    for (Method m : type.getDeclaredMethods()) {
        if (!m.getName().equals(sig.getName()))
            continue;

        // if (m.getModifiers() != sig.getModifiers())
        // continue;
        Object[] args = pjp.getArgs();
        Class<?>[] types = m.getParameterTypes();
        if (args.length != types.length)
            continue;
        boolean miss = false;
        for (int i = 0; i < args.length; i++) {
            Object arg = args[i];
            Class<?> argType = types[i];
            if (argType.isPrimitive()) {
                if (argType.equals(Double.TYPE) && !arg.getClass().equals(Double.class))
                    miss = true;// w  w  w .  ja  va2s . c o  m
            } else {
                if (arg != null && !argType.isInstance(arg))
                    miss = true;
            }
        }
        if (miss)
            continue;
        matches.add(m);
    }

    return matches;
}

From source file:org.onebusaway.container.cache.CacheableMethodManager.java

License:Apache License

protected String getCacheName(ProceedingJoinPoint pjp) {
    Signature sig = pjp.getSignature();
    StringBuilder b = new StringBuilder();
    if (_cacheNamePrefix != null)
        b.append(_cacheNamePrefix).append("-");
    b.append(sig.getDeclaringTypeName()).append('.').append(sig.getName());
    return b.toString();
}

From source file:org.openkoala.exception.support.springaop.AppExceptionInterceptor.java

License:Open Source License

public Object intercept(ProceedingJoinPoint point) throws Throwable {
    Method method = null;// w  w  w.  j  a v  a2s .c  o  m
    Class<? extends Object> target = point.getTarget().getClass();
    Method[] methods = target.getDeclaredMethods();
    for (Method tmp : methods) {
        if (point.getSignature().getName().equals(tmp.getName())) {
            method = tmp;
            break;
        }
    }

    Object o = null;
    try {
        o = point.proceed();
    } catch (Exception e) {
        logger.error("Method[" + target.getName() + "." + method.getName() + "]", e);
        throw new BaseException(e);
    }
    return o;
}

From source file:org.opennms.core.profiler.ProfilerAspect.java

License:Open Source License

@Around("@within(profile) || @annotation(profile)")
public Object logAroundByMethod(ProceedingJoinPoint joinPoint, Profile profile) throws Throwable {
    Timer timer = new Timer();
    try {/*from  w  w w . j ava 2 s.com*/
        timer.start();
        return joinPoint.proceed();
    } finally {
        log(joinPoint.getKind(), joinPoint.getSignature().toShortString(), timer.stop());
    }
}

From source file:org.openo.client.cli.fw.log.OpenOCommandLogger.java

License:Apache License

/**
 * Logging intercepter.//  w  w  w.  j  av a2 s  . c  om
 *
 * @param joinPoint
 *            joinpoint
 * @return object
 * @throws Throwable
 *             exception
 */
@Around("execution(* org.openo.client.cli.fw*(..))")
public Object log(ProceedingJoinPoint joinPoint) throws Throwable { // NOSONAR
    LOGGER.info(joinPoint.getThis().toString() + "->" + joinPoint.getSignature().getName() + "("
            + joinPoint.getArgs() + ")");

    Object response = joinPoint.proceed();
    LOGGER.info(response.toString());

    return response;
}

From source file:org.openregistry.aspect.LogAspect.java

License:Apache License

@Around("(execution (public * org.openregistry.core..*.*(..))) && !(execution( * org.openregistry.core..*.set*(..)))")
public Object traceMethod(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    Object returnVal = null;//  w w w.ja  v a  2 s .  c o m
    final Logger log = getLog(proceedingJoinPoint);
    final String methodName = proceedingJoinPoint.getSignature().getName();

    try {
        if (log.isTraceEnabled()) {
            final Object[] args = proceedingJoinPoint.getArgs();
            if (args == null || args.length == 0) {
                log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_BEGIN,
                        new Object[] { methodName, "" }, Locale.getDefault()));
            } else {
                final StringBuilder stringBuilder = new StringBuilder();
                for (final Object o : args) {
                    stringBuilder.append(o != null ? o.toString() : null).append(", ");
                }
                final String argString = stringBuilder.substring(0, stringBuilder.length() - 3);
                log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_BEGIN,
                        new Object[] { methodName, argString }, Locale.getDefault()));
            }
        }
        returnVal = proceedingJoinPoint.proceed();
        return returnVal;
    } finally {
        if (log.isTraceEnabled()) {
            log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_END,
                    new Object[] { methodName, (returnVal != null ? returnVal.toString() : "null") },
                    Locale.getDefault()));
        }
    }
}

From source file:org.openregistry.aspect.LogAspect.java

License:Apache License

@Around("(within(org.openregistry.core.service.PersonService+) && (execution (* *(..))))")
public Object logInfoPersonService(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    Object retVal = null;/*  ww w.  j a v  a 2s.  co  m*/
    final String methodName = proceedingJoinPoint.getSignature().getName();
    final Logger log = getLog(proceedingJoinPoint);
    try {

        if (log.isInfoEnabled()) {
            final Object arg0;

            if (proceedingJoinPoint.getArgs().length > 0) {
                arg0 = proceedingJoinPoint.getArgs()[0];
            } else {
                arg0 = null;
            }
            final String argumentString = arg0 == null ? "null" : arg0.toString();
            log.info(this.messageSourceAccessor.getMessage(TRACE_METHOD_BEGIN,
                    new Object[] { methodName, argumentString }, Locale.getDefault()));
        }

        retVal = proceedingJoinPoint.proceed();
        return retVal;
    } finally {

        if (log.isInfoEnabled()) {
            log.info(this.messageSourceAccessor.getMessage(TRACE_METHOD_END,
                    new Object[] { methodName, (retVal == null ? "null" : retVal.toString()) },
                    Locale.getDefault()));
        }
    }
}

From source file:org.opensaas.jaudit.service.spring.AuditExecutor.java

License:LGPL

/**
 * Create an audit record detailing that a particular operation has taken
 * place./*from w ww.  j  av a  2  s.c  o m*/
 * 
 * @param jp
 *            The join point currently being fired.
 * @param annotation
 *            The required annotation that triggers this join point.
 * @return The result of executing the method wrapped by this join point.
 * @throws Throwable
 *             When there is an error.
 */
public Object recordAction(final ProceedingJoinPoint jp, final LifeCycleAudit annotation) throws Throwable {
    LOGGER.log(Level.FINE, "joinpoint={0}, target={2}, args={1}",
            new Object[] { jp.getSignature().toLongString(), Arrays.toString(jp.getArgs()), jp.getTarget() });

    // make the call
    final Object retval = jp.proceed();

    final AuditSubject auditSubject = getAuditSubject(jp, annotation, retval);
    String description = annotation.description();
    if (description == null || description.length() < 1) {
        description = annotation.type().name();
    }
    auditService.createLifeCycleAuditEvent(annotation.type(), auditSubject, description);

    return retval;
}