Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

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

Introduction

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

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:net.sf.infrared.aspects.aj.JspAjAspect.java

License:Apache License

@SuppressWarnings("unchecked")
@Around("condition()")
public Object around(ProceedingJoinPoint thisJoinPointStaticPart) throws Throwable {
    final Class classObj = thisJoinPointStaticPart.getSignature().getDeclaringType();

    Object returnVal;//from  www .  j  a  v a2  s .  co  m
    JspContext ctx = new JspContext(classObj);

    MonitorFacade facade = MonitorFactory.getFacade();
    MonitorConfig cfg = facade.getConfiguration();

    if (cfg.isMonitoringEnabled()) {
        ExecutionTimer timer = new ExecutionTimer(ctx);
        MonitorFactory.getFacade().recordExecutionBegin(timer);
        try {
            returnVal = thisJoinPointStaticPart.proceed();
        } finally {
            MonitorFactory.getFacade().recordExecutionEnd(timer);
        }
    } else {
        returnVal = thisJoinPointStaticPart.proceed();
    }

    return returnVal;

}

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   ww 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.sourceforge.safr.core.interceptor.SecurityAspect.java

License:Apache License

@Around("securityAnnotatedDomainObjectMethod()")
public Object methodInvocation(ProceedingJoinPoint pjp) throws Throwable {
    if (!isConfigured()) {
        return pjp.proceed();
    }/* w  w  w .ja v  a2  s.  c om*/

    MethodSignature signature = (MethodSignature) pjp.getSignature();
    SecureAttribute msa = getMethodSecureAttribute(signature);
    SecureAttribute[] psa = getParameterSecureAttributes(signature);

    ProceedingInvocation pi = new AspectJProceedingInvocation(pjp);

    // pre-processing
    beforeProceed(msa, pi);
    checkMethodAction(msa, pi);
    checkParameterActions(psa, pi.getArguments());

    // around processing
    Object result = aroundProceed(msa, pi);

    // post-processing
    FilterAttribute mfa = getMethodFilterAttribute(signature);
    result = filterResult(mfa, pi.getMethod(), result);
    return afterProceed(msa, pi, result);

}

From source file:net.sourceforge.safr.core.interceptor.SecurityAspect.java

License:Apache License

@Around("set(* *.*) && encryptAnnotatedDomainObjectField()")
public Object setFieldAccess(ProceedingJoinPoint pjp) throws Throwable {
    FieldSignature signature = (FieldSignature) pjp.getSignature();
    EncryptAttribute ea = getFieldEncryptAttribute(signature);

    Object[] args = pjp.getArgs();
    // exchange original value with encrypted value
    args[0] = encrypt(ea, pjp.getTarget(), args[0]);
    // perform field access with encrypted value
    return pjp.proceed(args);
}

From source file:net.sourceforge.safr.core.interceptor.SecurityAspect.java

License:Apache License

@Around("get(* *.*) && encryptAnnotatedDomainObjectField()")
public Object getFieldAccess(ProceedingJoinPoint pjp) throws Throwable {
    FieldSignature signature = (FieldSignature) pjp.getSignature();
    EncryptAttribute ea = getFieldEncryptAttribute(signature);

    // obtain encrypted value from field
    Object value = pjp.proceed();
    // decrypt encrypted field value and return it
    return decrypt(ea, pjp.getTarget(), value);
}

From source file:net.sourceforge.safr.core.invocation.AspectJProceedingInvocation.java

License:Apache License

private static Method getMethod(ProceedingJoinPoint pjp) {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    return signature.getMethod();

}

From source file:net.zcarioca.zcommons.profile.aspects.LoggerAspect.java

License:Open Source License

/**
 * Wraps the execution of a method in a simple log statement.
 *///from   ww w. j  av  a2  s  .  c  o  m
@Around("@annotation(net.zcarioca.zcommons.profile.annotations.LoggedExecutionTime)")
public Object logExecutionTime(final ProceedingJoinPoint pjp) throws Throwable {
    long start = System.currentTimeMillis();

    try {
        return pjp.proceed();
    } finally {
        long time = System.currentTimeMillis() - start;
        Signature signature = pjp.getSignature();
        Class<?> type = signature.getDeclaringType();
        Logger logger = LoggerFactory.getLogger(type);

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Call to '%s' executed in %d ms.", signature.toLongString(), time));
        }
    }
}

From source file:net.zcarioca.zcommons.profile.aspects.LoggerAspect.java

License:Open Source License

@Around("@annotation(net.zcarioca.zcommons.profile.annotations.LoggedExecutionCount)")
public Object logExecutionCounter(final ProceedingJoinPoint pjp) throws Throwable {
    try {/* w ww  .j av  a 2s  .c  o m*/
        return pjp.proceed();
    } finally {
        Signature signature = pjp.getSignature();
        String sigString = signature.toLongString();
        if (!counterMap.containsKey(sigString)) {
            counterMap.put(sigString, new AtomicLong(0));
        }
        long count = counterMap.get(sigString).incrementAndGet();

        Class<?> type = signature.getDeclaringType();
        Logger logger = LoggerFactory.getLogger(type);

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Call to '%s' executed %d times.", sigString, count));
        }
    }
}

From source file:net.zcarioca.zcommons.profile.aspects.LoggerAspect.java

License:Open Source License

@Around("@annotation(net.zcarioca.zcommons.profile.annotations.LoggedAverageExecutionTime)")
public Object logAverageExecutionTime(final ProceedingJoinPoint pjp) throws Throwable {
    long start = System.currentTimeMillis();
    try {// w  w w  .  j  a v a2 s. c om
        return pjp.proceed();
    } finally {
        long time = System.currentTimeMillis() - start;
        Signature signature = pjp.getSignature();
        String sigString = signature.toLongString();
        if (!averageMap.containsKey(sigString)) {
            averageMap.put(sigString, new AtomicAverage());
        }
        double average = averageMap.get(sigString).addAndCalculate(time);

        Class<?> type = signature.getDeclaringType();
        Logger logger = LoggerFactory.getLogger(type);

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Call to '%s' executes takes %.2f ms (AVG).", sigString, average));
        }
    }
}