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.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;/*from  w w  w.j a  v  a2  s .com*/
    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.openregistry.core.aspect.CapitalizationAspect.java

License:Apache License

@Around("set(* *) && @annotation(capitalize)")
public Object transformFieldValue(final ProceedingJoinPoint joinPoint, final Capitalize capitalize)
        throws Throwable {
    final String newValue = (String) joinPoint.getArgs()[0];

    if (newValue == null) {
        return joinPoint.proceed();
    }// w w w.j  a va2s .  com

    final Capitalization customCapitalization = this.overrideCapitalization.get(capitalize.property());

    final Capitalization capitalizationToUse;
    if (customCapitalization != null) {
        capitalizationToUse = customCapitalization;
    } else {
        capitalizationToUse = this.capitalization;
    }

    switch (capitalizationToUse) {

    case UPPER:
        return joinPoint.proceed(new Object[] { doUpperCaseCapitalization(newValue) });

    case LOWER:
        return joinPoint.proceed(new Object[] { doLowerCaseCapitalization(newValue) });

    case CAPITALIZE:
        return joinPoint.proceed(new Object[] { doNormalCaseCapitalization(newValue) });

    default:
        return joinPoint.proceed();
    }
}

From source file:org.openregistry.core.aspect.FirstNameAspect.java

License:Apache License

@Around("set(@org.openregistry.core.domain.normalization.FirstName * *)")
public Object transformFieldValue(final ProceedingJoinPoint joinPoint) throws Throwable {
    final String value = (String) joinPoint.getArgs()[0];

    if (isDisabled() || value == null || value.isEmpty()) {
        return joinPoint.proceed();
    }/*from w  ww .jav  a2 s. c o  m*/

    final String overrideValue = getCustomMapping().get(value);

    if (overrideValue != null) {
        return joinPoint.proceed(new Object[] { overrideValue });
    }

    return joinPoint.proceed(new Object[] { WordUtils.capitalizeFully(value) });
}

From source file:org.openregistry.core.aspect.LastNameAspect.java

License:Apache License

@Around("set(@org.openregistry.core.domain.normalization.LastName * *)")
public Object transformFieldValue(final ProceedingJoinPoint joinPoint) throws Throwable {
    final String value = (String) joinPoint.getArgs()[0];

    if (isDisabled() || value == null || value.isEmpty()) {
        return joinPoint.proceed();
    }/*from   w ww .  jav a 2  s  . c  o m*/

    final String overrideValue = getCustomMapping().get(value);

    if (overrideValue != null) {
        return joinPoint.proceed(new Object[] { overrideValue });
    }

    if (StringUtils.containsAny(value, delimiters)) {

        final String casifyValue = WordUtils.capitalizeFully(value, delimiters);

        if (casifyValue.startsWith("Mc") && casifyValue.length() > 2) {
            return joinPoint.proceed(
                    new Object[] { "Mc" + WordUtils.capitalizeFully(casifyValue.substring(2), delimiters) });

        }

        return joinPoint.proceed(new Object[] { casifyValue });
    } else {
        final String casifyValue = WordUtils.capitalizeFully(value);

        if (casifyValue.startsWith("Mc") && casifyValue.length() > 2) {
            return joinPoint
                    .proceed(new Object[] { "Mc" + WordUtils.capitalizeFully(casifyValue.substring(2)) });

        }

        return joinPoint.proceed(new Object[] { casifyValue });

    }
}

From source file:org.openregistry.core.aspect.NameSuffixAspect.java

License:Apache License

@Around("set(@org.openregistry.core.domain.normalization.NameSuffix * *)")
public Object transformFieldValue(final ProceedingJoinPoint joinPoint) throws Throwable {
    final String value = (String) joinPoint.getArgs()[0];

    if (isDisabled() || value == null || value.isEmpty()) {
        return joinPoint.proceed();
    }//from ww w  .  j  a  v  a 2  s. co m

    final String overrideValue = getCustomMapping().get(value);

    if (overrideValue != null) {
        return joinPoint.proceed(new Object[] { overrideValue });
    }

    final String casifyValue;
    if (value.matches("^[IiVv]+$")) { //TODO Generalize II - VIII
        casifyValue = value.toUpperCase();
    } else {
        casifyValue = WordUtils.capitalizeFully(value);
    }

    return joinPoint.proceed(new Object[] { casifyValue });
}

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  .  jav  a  2 s. co 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;
}

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

License:LGPL

/**
 * Create an audit record detailing that a particular operation has taken
 * place./*w  w w.j a  v a2s  . 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) throws Throwable {

    if (LOGGER.isLoggable(Level.FINE)) {
        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();

    if (PlatformTransactionManager.class.isAssignableFrom(jp.getTarget().getClass())) {

        final SessionRecord sr = AuditSession.getAuditSession() != null
                ? AuditSession.getAuditSession().getSessionRecord()
                : null;

        final String methodName = jp.getSignature().getName();

        if ("getTransaction".equals(methodName)) {
            final TransactionStatus ts = (TransactionStatus) retval;

            if (ts.isNewTransaction()) {
                _applicationContext.publishEvent(
                        new NewTransactionEvent((PlatformTransactionManager) jp.getTarget(), ts, sr));
            }
        }
    }

    return retval;
}

From source file:org.opentestsystem.delivery.testreg.aop.SecuredAnnotationAspect.java

License:Open Source License

@Around("execution(* org.opentestsystem.delivery.test*.*.*Controller.*(..)) && @annotation(method) && @annotation(secured)")
public Object aroundMethodInControllerClass(ProceedingJoinPoint pjp, final RequestMapping method,
        final Secured secured) throws Throwable {

    String[] permissions = secured.value();
    Object[] params = pjp.getArgs();
    Object retVal = null;/*from   ww w . j a  v  a2s  . c  om*/

    if (method.method() != null) {
        for (RequestMethod requestMethod : method.method()) {
            LOGGER.debug("intercepting " + requestMethod + " for " + pjp.toString() + " secured by "
                    + permissionArrayToString(permissions));
            if (requestMethod.equals(POST) || requestMethod.equals(PUT) || requestMethod.equals(DELETE)
                    || requestMethod.equals(PATCH)) {
                // in these situations we need to check the incoming params to deduce if we have access prior to the
                // action
                if (params != null) {
                    if (!checkIncomingParameters(params, permissions)) {
                        throw new AccessDeniedException("permission denied");
                    }
                    // in this special case we want to check if the file upload type specified in the params matches
                    // what file upload permission(s) the user has...
                    // they are allowed to upload based on having any one of these: "ROLE_Accommodations Upload",
                    // "ROLE_Student Upload", "ROLE_Entity Upload", "ROLE_StudentGroup Upload", "ROLE_User Upload, "ROLE_ExplicitEligibility Upload"
                    if (pjp.getSignature().getName().equals("uploadFile")
                            && pjp.getSignature().getDeclaringType().equals(Class.forName(
                                    "org.opentestsystem.delivery.testreg.rest.FileUploadDataController"))) {
                        // We should throw AccessDeniedException here if they don't have the proper upload
                        // role based on the file upload type (check params)
                        SbacUser currentUser = testRegUserDetailsService.getCurrentUser();
                        String testRegPermission = getCorrectRolePermissionByFormatType((String) params[1]);
                        // checking if logged-in-user has permission to upload corresponding file(user/student/institutions/..)
                        if (currentUser != null && !currentUser.hasPermission(testRegPermission)) {
                            throw new AccessDeniedException("permission denied");
                        }
                    } else if (pjp.getSignature().getName().equals("saveStudents")
                            && pjp.getSignature().getDeclaringType().equals(Class.forName(
                                    "org.opentestsystem.delivery.testreg.rest.ExternalStudentController"))) {
                        // We should throw AccessDeniedException here if they don't have the proper upload
                        // role based on the file upload type (check params)
                        SbacUser currentUser = testRegUserDetailsService.getCurrentUser();
                        String testRegPermission = getCorrectRolePermissionByFormatType("STUDENT");
                        // checking if logged-in-user has permission to upload corresponding file(user/student/institutions/..)
                        if (currentUser != null && !currentUser.hasPermission(testRegPermission)) {
                            throw new AccessDeniedException("permission denied");
                        }
                    }
                }
                // we let things continue normally...
                retVal = pjp.proceed();
            } else if (requestMethod.equals(GET)) {
                // in these situations we need to check the return values to determine if we have access
                retVal = pjp.proceed();
                if (retVal != null && !checkReturnValue(retVal, permissions)) {
                    throw new AccessDeniedException("permission denied");
                }
            } else {
                // for now we only handle securing methods get/post/put/delete (enhance code here for additional
                // request methods)
                throw new AccessDeniedException(
                        "non-standard request type for a @Secured rest request: " + requestMethod);
            }
        }
    }
    return retVal;
}

From source file:org.openwms.core.service.spring.aop.CoreServiceAspect.java

License:Open Source License

/**
 * Called around any service method invocation to log time consumption of
 * each method call./*w ww .  ja  va  2s .c  o m*/
 * 
 * @param pjp
 *            the ProceedingJoinPoint object
 * @return the return value of the service method invocation
 * @throws Throwable
 *             any exception thrown by the method invocation
 */
public Object around(ProceedingJoinPoint pjp) throws Throwable {
    StopWatch sw = null;
    if (LOGGER.isDebugEnabled()) {
        sw = new StopWatch();
        sw.start();
        LOGGER.debug("[S]>> Method call: " + pjp.toShortString());
    }
    try {
        Object[] args = pjp.getArgs();
        if (args != null && args.length > 0) {
            for (int i = 0; i < args.length; i++) {
                if (args[i] != null) {
                    validator.validate(args[i]);
                }
            }
        }
        return pjp.proceed();
    } finally {
        if (LOGGER.isDebugEnabled() && sw != null) {
            sw.stop();
            LOGGER.debug("[S]<< " + pjp.toShortString() + " took about [ms]: " + sw.getTotalTimeMillis());
        }
    }
}

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();
        }/*from   w  w  w .  ja  va 2s .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();
        }

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