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:org.plos.namedentity.validate.NamedEntityValidator.java

License:Open Source License

public Object validate(ProceedingJoinPoint call) throws Throwable {

    /* ------------------------------------------------------------------ */
    /*  BEFORE-VALIDATION                                                 */
    /* ------------------------------------------------------------------ */

    Object[] args = call.getArgs();

    if (args[0] instanceof Validatable)
        ((Validatable) args[0]).validate();

    /* ------------------------------------------------------------------ */
    /*  METHOD EXECUTION                                                  */
    /* ------------------------------------------------------------------ */

    Object returnValue;//from  ww  w . j a  va  2 s .c om

    try {
        returnValue = call.proceed();
    } catch (NonTransientDataAccessException e) {
        throw NedExceptionTranslator.translate(e);
    }

    /* ------------------------------------------------------------------ */
    /*  AFTER-VALIDATION                                                  */
    /* ------------------------------------------------------------------ */

    // an exception will be thrown if post validation fails
    entityPostValidator.validate(returnValue);

    return returnValue;
}

From source file:org.raspinloop.agent.internal.aspect.I2CFactoryAspect.java

License:Apache License

@Around("call(com.pi4j.io.i2c.I2CBus com.pi4j.io.i2c.I2CFactory.getInstance(..)) ")
public com.pi4j.io.i2c.I2CBus i2CGetInstance(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    return Adapters.forPi4j(I2CEmulation.getInstance(args));
}

From source file:org.raspinloop.agent.internal.aspect.SimulatedTimeAspect.java

License:Apache License

@Around("call(long java.util.concurrent.locks.Condition.awaitNanos(..)) && within(org.raspinloop.agent.internal.timeemulation.*) && !within(org.raspinloop.fmi.internal.timeemulation.SimulatedTime)")
public long awaitnano(ProceedingJoinPoint joinPoint) throws Throwable {
    return SimulatedTime.awaitNanos((long) joinPoint.getArgs()[0], (Condition) joinPoint.getTarget());
}

From source file:org.raspinloop.agent.internal.aspect.SleepAspect.java

License:Apache License

@Around("call(void Thread.sleep(..)) && !within(java.*) && !within(org.raspinloop.standalone.*)&& !within(org.raspinloop.internal.timeemulation.*)")
public void sleep(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    if (args.length == 1 && args[0] instanceof Long)
        SimulatedTime.sleep((Long) args[0]);
    else if (args.length == 2 && args[0] instanceof Long && args[1] instanceof Integer)
        SimulatedTime.sleep((Long) args[0], (Integer) args[1]);
}

From source file:org.raspinloop.agent.internal.aspect.SpiFactoryAspect.java

License:Apache License

@Around("call(com.pi4j.io.spi.SpiDevice com.pi4j.io.spi.SpiFactory.getInstance(..)) ")
public com.pi4j.io.spi.SpiDevice spiGetInstance(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();

    if (args.length == 1 && args[0] instanceof SpiChannel)
        return Adapters.forPi4j(SpiEmulation.getInstance(Adapters.forPi4j((SpiChannel) args[0])));

    if (args.length == 2 && args[0] instanceof SpiChannel && args[1] instanceof SpiMode)
        return Adapters.forPi4j(SpiEmulation.getInstance(Adapters.forPi4j((SpiChannel) args[0]),
                Adapters.forPi4j((SpiMode) args[1])));
    if (args.length == 2 && args[0] instanceof SpiChannel && args[1] instanceof Integer)
        return Adapters
                .forPi4j(SpiEmulation.getInstance(Adapters.forPi4j((SpiChannel) args[0]), (Integer) args[1]));

    if (args.length == 3 && args[0] instanceof SpiChannel && args[1] instanceof Integer
            && args[2] instanceof SpiMode)
        return Adapters.forPi4j(SpiEmulation.getInstance(Adapters.forPi4j((SpiChannel) args[0]),
                (Integer) args[1], Adapters.forPi4j((SpiMode) args[2])));

    throw new IOException("Invalid parameter in call to SPIFactory.getInstance.");

}

From source file:org.raspinloop.fmi.RILLogingAspect.java

License:Apache License

@Around("org.raspinloop.fmi.RILLogingAspect.rilTraceCall()")
public Object myTrace(ProceedingJoinPoint joinPoint) throws Throwable {

    StringBuilder sb = new StringBuilder("ril:--> " + joinPoint.getTarget().getClass().getName() + "."
            + joinPoint.getSignature().getName() + ": ");
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    Annotation[][] annotations = method.getParameterAnnotations();
    for (int i = 0; i < annotations.length; ++i) {
        sb.append(joinPoint.getArgs()[i]);
        if (i != annotations.length - 1)
            sb.append(", ");
    }/*from w  w w .  java 2  s.c  o  m*/
    logger.trace(sb.toString());

    Object retVal = null;
    try {
        retVal = joinPoint.proceed();
    } finally {

        logger.trace("ril:<-- " + joinPoint.getTarget().getClass().getName() + "."
                + joinPoint.getSignature().getName() + " retval=" + retVal);
    }
    return retVal;
}

From source file:org.slc.sli.aspect.ApiMigrationAspect.java

License:Apache License

/**
 * Migrate entities in a response (down transform) from the current DB schema version to the version of the API schema requested
 *//*from   w w  w .ja v a 2  s.c  om*/
@Around(value = "@annotation(annotation)")
public Object migrateResponse(final ProceedingJoinPoint proceedingJoinPoint, final MigrateResponse annotation)
        throws Throwable {
    Object obj = proceedingJoinPoint.proceed();
    String namespace = "";

    Object[] args = proceedingJoinPoint.getArgs();
    if (args.length > 0) {
        if (args[0] instanceof Resource) {
            Resource resource = (Resource) args[0];
            namespace = resource.getNamespace();
        }
    }

    int version = getVersion(namespace);

    if (version > 0 && obj instanceof ServiceResponse) {
        ServiceResponse response = (ServiceResponse) obj;
        List<EntityBody> bodyList = response.getEntityBodyList();
        obj = transformResponse(response, version);
    }
    return obj;
}

From source file:org.slc.sli.aspect.ApiMigrationAspect.java

License:Apache License

/**
 * Migrate posted entity (up transform) from the specified API version to the latest DB schema version
 *///  w  w w.  j  a v  a 2 s .  c  o  m
@Around(value = "@annotation(annotation)")
public Object migratePostedEntity(final ProceedingJoinPoint proceedingJoinPoint,
        final MigratePostedEntity annotation) throws Throwable {
    String namespace = "";

    EntityBody entityBody = null;
    int entityIndex = -1;

    Object[] args = proceedingJoinPoint.getArgs();
    for (int i = 0; i < args.length; i++) {
        if (args[i] instanceof EntityBody) {
            entityBody = (EntityBody) args[i];
            entityIndex = i;
        } else if (args[i] instanceof Resource) {
            Resource resource = (Resource) args[i];
            namespace = resource.getNamespace();
        }
    }

    int version = getVersion(namespace);

    if (version > 0 && entityBody != null) {
        EntityBody transformedBody = transformEntityBody(entityBody, version, true);
        args[entityIndex] = transformedBody;
    }
    return proceedingJoinPoint.proceed(args);
}

From source file:org.slc.sli.dal.aspect.MongoTrackingAspect.java

License:Apache License

private Object trackCalls(ProceedingJoinPoint pjp) throws Throwable {

    Object result;/*w  w w.  j  a  v a  2s  .c  o  m*/
    if (Boolean.valueOf(dbCallTracking)) {
        dbCallTracker.addEvent("s",
                pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName(),
                System.currentTimeMillis(), null);
        result = pjp.proceed();
        long end = System.currentTimeMillis();
        // capture the arguments
        Object[] callArgs = pjp.getArgs();
        List<String> args = new ArrayList<String>(callArgs.length);
        for (Object ca : callArgs) {
            args.add((null == ca) ? null : ca.getClass().getName() + ":" + ca.toString());
        }
        dbCallTracker.addEvent("e", "", end, args);
    } else {
        result = pjp.proceed();
    }

    return result;
}

From source file:org.slc.sli.dal.aspect.MongoTrackingAspect.java

License:Apache License

private String determineCollectionName(ProceedingJoinPoint pjp) {
    String collection = "UNKNOWN";
    Object[] args = pjp.getArgs();
    if (args.length > 0 && args[0] instanceof String) {
        collection = (String) args[0];
    } else if (args.length > 1 && args[1] instanceof String) {
        collection = (String) args[1];
    } else if (args.length > 2 && args[2] instanceof String) {
        collection = (String) args[2];
    }//  ww  w.  jav  a  2  s  . com

    if (collection.lastIndexOf("_") > -1) {
        collection = collection.substring(0, collection.lastIndexOf("_"));
    }

    if (pjp.getSignature().getName().equals("executeCommand")) {
        collection = "EXEC-UNKNOWN";
    }
    return collection;
}