Example usage for org.aspectj.lang ProceedingJoinPoint getThis

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

Introduction

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

Prototype

Object getThis();

Source Link

Document

Returns the currently executing object.

Usage

From source file:fr.xebia.audit.AuditAspect.java

License:Apache License

@Around(value = "execution(* *(..)) && @annotation(audited)", argNames = "pjp,audited")
public Object logMessage(ProceedingJoinPoint pjp, Audited audited) throws Throwable {

    long nanosBefore = System.nanoTime();
    try {//from w w w  .  jav a2 s.co m
        Object returned = pjp.proceed();
        long durationInNanos = System.nanoTime() - nanosBefore;
        String message = buildMessage(audited.message(), pjp.getThis(), pjp.getArgs(), returned, null,
                durationInNanos);
        logger.info(message);
        return returned;
    } catch (Throwable t) {
        long durationInNanos = System.nanoTime() - nanosBefore;
        String message = buildMessage(audited.message(), pjp.getThis(), pjp.getArgs(), null, t,
                durationInNanos);
        logger.warn(message);
        throw t;
    }
}

From source file:net.jperf.aop.AbstractTimingAspect.java

License:Open Source License

protected Object runProfiledMethod(final ProceedingJoinPoint pjp, Profiled profiled) throws Throwable {
    //We just delegate to the super class, wrapping the AspectJ-specific ProceedingJoinPoint as an AbstractJoinPoint
    return runProfiledMethod(new AbstractJoinPoint() {
        public Object proceed() throws Throwable {
            return pjp.proceed();
        }/* w  w  w  .j a va2 s. co  m*/

        public Object getExecutingObject() {
            return pjp.getThis();
        }

        public Object[] getParameters() {
            return pjp.getArgs();
        }

        public String getMethodName() {
            return pjp.getSignature().getName();
        }

        public Class<?> getDeclaringClass() {
            return pjp.getSignature().getDeclaringType();
        }
    }, profiled, newStopWatch(profiled.logger() + "", profiled.level()));
}

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 .  j av  a 2s . co m
        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.apromore.aop.AuditAspect.java

License:Open Source License

@Around(value = "execution(* *(..)) && @annotation(audited)", argNames = "pjp,audited")
public Object logMessage(ProceedingJoinPoint pjp, Audited audited) throws Throwable {

    long nanosBefore = System.nanoTime();
    try {//from   ww w .  j  a  va2 s . c  om
        Object returned = pjp.proceed();
        long durationInNanos = System.nanoTime() - nanosBefore;
        String message = buildMessage(audited.message(), pjp.getThis(), pjp.getArgs(), returned, null,
                durationInNanos);
        LOGGER.info(message);
        return returned;
    } catch (Throwable t) {
        long durationInNanos = System.nanoTime() - nanosBefore;
        String message = buildMessage(audited.message(), pjp.getThis(), pjp.getArgs(), null, t,
                durationInNanos);
        LOGGER.warn(message);
        throw t;
    }
}

From source file:org.biopax.validator.impl.ExceptionsAspect.java

License:Open Source License

@Around("execution(* org.biopax.paxtools.io.SimpleIOHandler.processIndividual(*)) " + "&& args(model)")
public String adviseProcessIndividual(ProceedingJoinPoint jp, Model model) {
    String id = null;//w  w  w.ja  v  a2  s .  c  o m
    SimpleIOHandler reader = (SimpleIOHandler) jp.getThis();

    try {
        id = (String) jp.proceed();
    } catch (Throwable ex) {
        reportException(ex, reader, "syntax.error", "SimpleIOHandler.processIndividual interceptor", null);
    }
    return id;
}

From source file:org.broadleafcommerce.common.vendor.service.monitor.ServiceMonitor.java

License:Apache License

public Object checkServiceAOP(ProceedingJoinPoint call) throws Throwable {
    try {//  ww w.ja  v a2 s  . co  m
        checkService((ServiceStatusDetectable) call.getThis());
    } catch (Throwable e) {
        LOG.error("Could not check service status", e);
    }
    return call.proceed();
}

From source file:org.jbb.lib.properties.encrypt.PropertiesEncryptionAspect.java

License:Apache License

@Around("this(org.jbb.lib.properties.ModuleProperties)")
public Object decryptIfApplicable(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();

    Config.Key key = method.getAnnotation(Config.Key.class);
    if (key != null) {
        ModuleProperties properties = (ModuleProperties) joinPoint.getThis();
        String value = properties.getProperty(key.value());
        if (isInDecPlaceholder(value)) {
            String decryptedString = propertiesEncryption.decryptIfNeeded(value);
            Class returnType = ((MethodSignature) joinPoint.getSignature()).getReturnType();
            return typeCasting.resolve(decryptedString, returnType);
        }/*from   ww  w.j  av a 2 s  .c  o m*/
    }

    return joinPoint.proceed();
}

From source file:org.jbb.lib.properties.SafeBlankPropertyAspect.java

License:Apache License

@Around("this(org.jbb.lib.properties.ModuleProperties)")
public Object makeSafeBlankProperty(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();

    Config.Key key = method.getAnnotation(Config.Key.class);
    if (key != null) {
        ModuleProperties properties = (ModuleProperties) joinPoint.getThis();
        String value = properties.getProperty(key.value());
        if (StringUtils.isBlank(value)) {
            return null;
        }//from www.  jav  a 2s.  c o  m
    }

    return joinPoint.proceed();
}

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

License:Apache License

/**
 * Logging intercepter.//from  w w w  .j a va2  s .  co  m
 *
 * @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.perf4j.aop.AbstractTimingAspect.java

License:Open Source License

protected Object runProfiledMethod(final ProceedingJoinPoint pjp, Profiled profiled) throws Throwable {
    //We just delegate to the super class, wrapping the AspectJ-specific ProceedingJoinPoint as an AbstractJoinPoint
    return runProfiledMethod(new AbstractJoinPoint() {
        public Object proceed() throws Throwable {
            return pjp.proceed();
        }//w w w.j ava  2 s. c o m

        public Object getExecutingObject() {
            return pjp.getThis();
        }

        public Object[] getParameters() {
            return pjp.getArgs();
        }

        public String getMethodName() {
            return pjp.getSignature().getName();
        }

        public Class<?> getDeclaringClass() {
            return pjp.getSignature().getDeclaringType();
        }

        public Map<String, Object> getContextData() {
            return new HashMap<String, Object>();
        }
    }, profiled, newStopWatch(profiled.logger() + "", profiled.level()));
}