Example usage for org.aspectj.lang ProceedingJoinPoint getArgs

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

Introduction

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

Prototype

Object[] getArgs();

Source Link

Usage

From source file:net.firejack.platform.processor.interceptor.LogEntryDetailsInterceptor.java

License:Apache License

/**
 * @param pjp/*from w  ww . j  av  a2s.  c  o  m*/
 * @param broker
 * @return
 * @throws Throwable
 */
@Around(value = "execution(* execute(..)) && target(broker) && @target(net.firejack.platform.web.statistics.annotation.TrackDetails)", argNames = "pjp,broker")
public Object trackActionDetails(ProceedingJoinPoint pjp, ServiceBroker broker) throws Throwable {
    if (TrackContainer.getCurrentTrack() != null) {
        Object[] arguments = pjp.getArgs();
        ServiceRequest serviceRequest = (ServiceRequest) arguments[0];
        try {
            OPFContext context = OPFContext.getContext();
            String currentAction = context == null ? null : context.getCurrentActionLookup();
            String username = context == null ? "Undefined" : context.getPrincipal().getName();
            if (TrackContainer.getCurrentTrack() != null) {
                if (currentAction != null) {
                    String actionName = humanNameFromLookup(currentAction);
                    String entityName = humanNameFromLookup(extractPathFromLookup(currentAction));
                    String messageTemplate = getMessageTemplateByActionLookup(currentAction);
                    if (messageTemplate != null) {
                        messageTemplate = messageTemplate.replaceAll("\\[USERNAME\\]", username);
                        messageTemplate = messageTemplate.replaceAll("\\[ACTION\\]", actionName);
                        messageTemplate = messageTemplate.replaceAll("\\[ENTITY\\]", entityName);

                        Object identifier = broker.getDetailedMessageArgs(serviceRequest);
                        if (identifier != null) {
                            messageTemplate = messageTemplate.replaceAll("\\[ID\\]", identifier.toString());
                        }
                        TrackContainer.getCurrentTrack().setDetails(messageTemplate);
                    } else {
                        String message = username + " performed the " + actionName + " operation for "
                                + entityName + " records.";
                        TrackContainer.getCurrentTrack().setDetails(message);
                    }
                } else {
                    TrackContainer.getCurrentTrack().setDetails("Action has not been defined.");
                }
            }
        } catch (Throwable th) {
            logger.warn(th.getMessage(), th);
        }
    }
    try {
        return pjp.proceed();
    } catch (Throwable th) {
        logger.error(MSG_ERROR_OCCURRED);
        throw th;
    }
}

From source file:net.joala.bdd.aop.JUnitAopStepsLogger.java

License:Open Source License

/**
 * <p>//from   w  ww .  j  a  v  a  2 s .c  o  m
 * Adviser to log steps.
 * </p>
 *
 * @param joinPoint where we are
 * @return the result of the step call
 * @throws Throwable in case of any error
 */
@Around("execution(* given_*(..))||execution(* when_*(..))||execution(* then_*(..))")
public Object logGivenWhenThen(@Nonnull final ProceedingJoinPoint joinPoint) throws Throwable { // NOSONAR: Need to
    // deal with generic throwables here
    final String stepName = joinPoint.getSignature().getName();
    final Object[] arguments = joinPoint.getArgs();
    final Description stepDescription = describeStep(stepName, arguments);
    final Object result;
    try {
        LOG.info("{}", stepDescription);
        result = joinPoint.proceed();
    } catch (Throwable throwable) { // NOSONAR: Need to deal with generic throwables here
        LOG.info("{} (FAILED)", stepDescription);
        throw throwable;
    }
    return result;
}

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();
        }//from  w w  w  .j  av a 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();
        }
    }, profiled, newStopWatch(profiled.logger() + "", profiled.level()));
}

From source file:net.nelz.simplesm.aop.ReadThroughMultiCacheAdvice.java

License:Open Source License

@Around("getMulti()")
public Object cacheMulti(final ProceedingJoinPoint pjp) throws Throwable {
    // This is injected caching.  If anything goes wrong in the caching, LOG the crap outta it,
    // but do not let it surface up past the AOP injection itself.
    final MultiCacheCoordinator coord = new MultiCacheCoordinator();
    Object[] args = pjp.getArgs();
    try {/* w  w  w .j ava2s.c o m*/
        // Get the target method being invoked, and make sure it returns the correct info.
        coord.setMethod(getMethodToCache(pjp));
        verifyReturnTypeIsList(coord.getMethod(), ReadThroughMultiCache.class);

        // Get the annotation associated with this method, and make sure the values are valid.
        final ReadThroughMultiCache annotation = coord.getMethod().getAnnotation(ReadThroughMultiCache.class);

        coord.setAnnotationData(AnnotationDataBuilder.buildAnnotationData(annotation,
                ReadThroughMultiCache.class, coord.getMethod()));

        // Get the list of objects that will provide the keys to all the cache values.
        coord.setKeyObjects(getKeyObjectList(coord.getAnnotationData().getKeyIndex(), pjp, coord.getMethod()));

        // Create key->object and object->key mappings.
        coord.setHolder(convertIdObjectsToKeyMap(coord.getKeyObjects(), coord.getAnnotationData()));

        // Get the full list of cache keys and ask the cache for the corresponding values.
        coord.setInitialKey2Result(cache.getBulk(coord.getKey2Obj().keySet()));

        // We've gotten all positive cache results back, so build up a results list and return it.
        if (coord.getMissObjects().size() < 1) {
            return coord.generateResultList();
        }

        // Create the new list of arguments with a subset of the key objects that aren't in the cache.
        args = coord.modifyArgumentList(args);
    } catch (Throwable ex) {
        LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex);
        return pjp.proceed();
    }

    /*
    Call the target method with the new subset of arguments.
    We are calling this outside of the try/catch block in case there are some
    'not our fault' problems with the target method. (Connection issues, etc...)
    Though, this decision could go either way, really.
     */
    final List results = (List) pjp.proceed(args);

    try {

        if (results.size() != coord.getMissObjects().size()) {
            throw new RuntimeException("Did not receive a correlated amount of data from the target method.");
        }

        for (int ix = 0; ix < results.size(); ix++) {
            final Object keyObject = coord.getMissObjects().get(ix);
            final Object resultObject = results.get(ix) == null ? new PertinentNegativeNull() : results.get(ix);
            final String cacheKey = coord.obj2Key.get(keyObject);
            cache.set(cacheKey, coord.getAnnotationData().getExpiration(), resultObject);
            coord.getKey2Result().put(cacheKey, resultObject);
        }

        return coord.generateResultList();
    } catch (Throwable ex) {
        LOG.warn("Caching on " + pjp.toShortString()
                + " aborted due to an error. The underlying method will be called twice.", ex);
        return pjp.proceed();
    }
}

From source file:net.rrm.ehour.audit.aspect.AuditAspect.java

License:Open Source License

/**
 * Get parameters of advised method//  w  ww  .  j  ava2 s  .com
 *
 * @param pjp
 * @return
 */
private String getAuditParameters(ProceedingJoinPoint pjp) {
    StringBuilder parameters = new StringBuilder();

    int i = 0;

    for (Object object : pjp.getArgs()) {
        parameters.append(i++).append(":");

        if (object == null) {
            parameters.append("null");
        } else if (object instanceof Calendar) {
            parameters.append(((Calendar) object).getTime().toString());
        } else {
            parameters.append(object.toString());
        }
    }

    return parameters.length() > 1024 ? parameters.substring(0, 1023) : parameters.toString();
}

From source file:net.sf.dynamicreports.site.ExamplesAspect.java

License:Open Source License

@Around("export()")
public JasperReportBuilder to(ProceedingJoinPoint pjp) throws Throwable {
    JasperReportBuilder reportBuilder = (JasperReportBuilder) pjp.getTarget();
    GenerateSite.generateExampleImage(name, reportBuilder,
            (AbstractJasperExporterBuilder<?, ?>) pjp.getArgs()[0]);
    return reportBuilder;
}

From source file:net.sf.dynamicreports.site.ExamplesAspect.java

License:Open Source License

@Around("toConcatenatedPdf()")
public JasperConcatenatedReportBuilder toConcatenatedPdf(ProceedingJoinPoint pjp) throws Throwable {
    JasperConcatenatedReportBuilder reportBuilder = (JasperConcatenatedReportBuilder) pjp.getTarget();
    GenerateSite.generateExampleImage(name, reportBuilder, (JasperPdfExporterBuilder) pjp.getArgs()[0]);
    return reportBuilder;
}

From source file:net.sf.oval.guard.GuardAspect2.java

License:Open Source License

@Around("execution((@net.sf.oval.guard.Guarded *).new(..))")
public Object allConstructors(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
    final ConstructorSignature signature = (ConstructorSignature) thisJoinPoint.getSignature();

    LOG.debug("aroundConstructor() {1}", signature);

    final Constructor<?> ctor = signature.getConstructor();
    final Object[] args = thisJoinPoint.getArgs();
    final Object target = thisJoinPoint.getTarget();

    // pre conditions
    {/*from  w w w  .ja  v  a  2  s  .c om*/
        guard.guardConstructorPre(target, ctor, args);
    }

    final Object result = thisJoinPoint.proceed();

    // post conditions
    {
        guard.guardConstructorPost(target, ctor, args);
    }

    return result;
}

From source file:net.sf.oval.guard.GuardAspect2.java

License:Open Source License

@SuppressAjWarnings("adviceDidNotMatch")
@Around("execution(* (@net.sf.oval.guard.Guarded *).*(..))")
public Object allMethods(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
    final MethodSignature signature = (MethodSignature) thisJoinPoint.getSignature();

    LOG.debug("aroundMethod() {1}", signature);

    final Method method = signature.getMethod();
    final Object[] args = thisJoinPoint.getArgs();
    final Object target = thisJoinPoint.getTarget();

    return guard.guardMethod(target, method, args, new ProceedInvocable(thisJoinPoint));
}

From source file:net.sf.taverna.t2.reference.impl.CacheAspect.java

License:Open Source License

/**
 * Handle a 'get by T2Reference' operation on a Dao
 * //from  w  w  w . j a v  a 2  s  .c  om
 * @param pjp
 *            the join point representing the ongoing method call to the dao
 * @return the entity identified by the T2Reference supplied to the method
 *         to which this advice applies
 * @throws DaoException
 *             if anything goes wrong
 */
public final Identified getObject(final ProceedingJoinPoint pjp) throws DaoException {
    Identified result = null;

    // Get the T2Reference from the argument to the get method
    T2Reference id = (T2Reference) pjp.getArgs()[0];
    if (id != null) {
        result = getCacheProvider().get(id);
        if (result != null)
            return result;
    }
    // If we miss the cache then call the method as usual
    try {
        result = (Identified) pjp.proceed();
    } catch (DaoException e) {
        throw e;
    } catch (Throwable e) {
        throw new DaoException("Unexpected exception type during aspect " + "based invocation", e);
    }

    // Write back to the cache
    if (result != null)
        getCacheProvider().put(result);

    return result;
}