Example usage for org.aspectj.lang ProceedingJoinPoint getTarget

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

Introduction

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

Prototype

Object getTarget();

Source Link

Document

Returns the target object.

Usage

From source file:validation.ValidationInterceptor.java

License:Apache License

@Around("execution(public * *(..)) && @within(validation.AutoValidating)")
public Object validateMethodInvocation(ProceedingJoinPoint pjp) throws Throwable {
    Object result;//  ww  w  . j a va  2 s .com
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    MethodValidator methodValidator = validator.unwrap(MethodValidator.class);

    Set<MethodConstraintViolation<Object>> parametersViolations = methodValidator
            .validateAllParameters(pjp.getTarget(), signature.getMethod(), pjp.getArgs());
    if (!parametersViolations.isEmpty()) {
        throw new MethodConstraintViolationException(parametersViolations);
    }

    result = pjp.proceed(); //Execute the method

    Set<MethodConstraintViolation<Object>> returnValueViolations = methodValidator
            .validateReturnValue(pjp.getTarget(), signature.getMethod(), result);
    if (!returnValueViolations.isEmpty()) {
        throw new MethodConstraintViolationException(returnValueViolations);
    }

    return result;
}