Example usage for org.aspectj.lang Signature getDeclaringType

List of usage examples for org.aspectj.lang Signature getDeclaringType

Introduction

In this page you can find the example usage for org.aspectj.lang Signature getDeclaringType.

Prototype

Class getDeclaringType();

Source Link

Document

Returns a java.lang.Class object representing the class, interface, or aspect that declared this member.

Usage

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.aspects.DataSourceAspect.java

License:Apache License

private Field getFieldFromJoinPoint(JoinPoint joinPoint) throws NoSuchFieldException {
    Signature signature = joinPoint.getSignature();
    Class<?> clazz = signature.getDeclaringType();
    return clazz.getDeclaredField(signature.getName());
}

From source file:com.autentia.tnt.tracking.annotation.ChangesHistoryAspect.java

License:Open Source License

/**
 * return the method with no arguments of the target object class with the name passed
 * @param call/*from www.java2s  . co m*/
 * @param methodName
 * @return
 * @throws SecurityException
 * @throws NoSuchMethodException
 */
private Method getMethod(JoinPoint call, String methodName) throws SecurityException, NoSuchMethodException {
    Method metodo = null;

    Signature sig = call.getSignature();
    Class clase = sig.getDeclaringType();

    Class[] args = {};
    metodo = clase.getMethod(methodName, args);

    return metodo;
}

From source file:com.github.woozoo73.ht.SignatureInfo.java

License:Apache License

public SignatureInfo(Signature signature) {
    if (signature == null) {
        return;/*from w  w  w . j a v  a2 s.co  m*/
    }

    this.shortString = signature.toShortString();
    this.longString = signature.toLongString();
    this.name = signature.getName();
    this.modifiers = signature.getModifiers();
    this.declaringType = signature.getDeclaringType();
    this.declaringTypeName = signature.getDeclaringTypeName();
}

From source file:com.ideabase.repository.core.aspect.DataAccessEventAdvice.java

License:Open Source License

/**
 * Find Signature class. now publish event based on the specific class and
 * method signature.// ww w  . j av a  2 s .  c o m
 */
@Around("com.ideabase.repository.core.aspect.ArchitecturePointcuts.dataAccessOperation()")
public Object aroundOperation(final ProceedingJoinPoint pProceedingJoinPoint) throws Throwable {
    // Determine source class and mehtod.
    final Signature signature = pProceedingJoinPoint.getSignature();
    final Class signatureClass = signature.getDeclaringType();
    final String signatureMethod = signature.getName();
    final Object[] arguments = pProceedingJoinPoint.getArgs();

    // Execute the operation
    final Object returned = pProceedingJoinPoint.proceed();

    // publish event
    addEvent(returned, signatureClass, signatureMethod, arguments);

    // Return the executed output.
    return returned;
}

From source file:com.ideabase.repository.core.aspect.IndexEventAdvice.java

License:Open Source License

@Around("com.ideabase.repository.core.aspect.ArchitecturePointcuts.indexOperation()")
public Object aroundOperation(final ProceedingJoinPoint pProceedingJoinPoint) throws Throwable {
    // Determine source class and mehtod.
    final Signature signature = pProceedingJoinPoint.getSignature();
    final Class signatureClass = signature.getDeclaringType();
    final String signatureMethod = signature.getName();
    final Object[] arguments = pProceedingJoinPoint.getArgs();

    // Execute the operation
    final Object returned = pProceedingJoinPoint.proceed();

    // publish event
    addEvent(signatureClass, signatureMethod, arguments);

    // Return the executed output.
    return returned;
}

From source file:com.qrmedia.commons.aspect.advice.AbstractLoggingAdvice.java

License:Open Source License

/**
 * Returns a string representation of the target join point, of the form
 * <code>DefiningClass.targetMethod</code> or <code>TargetClass.targetMethod</code>.
 * //w  ww  . java  2 s .  c o  m
 * @param joinPoint the join point to be represented as a string
 * @param useTargetClassName <code>true</code> if the class name of the <u>target</u>
 *                           object should be used; otherwise, the class name of the
 *                           class defining the join point will be used 
 * @return  a string representation of the join point
 */
protected static String toShortJoinPointString(JoinPoint joinPoint, boolean useTargetClassName) {
    Signature signature = joinPoint.getSignature();
    return (useTargetClassName ? joinPoint.getTarget().getClass().getSimpleName()
            : signature.getDeclaringType().getSimpleName()) + "." + signature.getName();
}

From source file:de.escidoc.core.common.util.aop.TraceInterceptor.java

License:Open Source License

private static String createMessage(final boolean in, final String depthString, final Signature signature) {
    final StringWriter inMessage = new StringWriter();
    inMessage.append('[').append(String.valueOf(Thread.currentThread().getId())).append(']');
    inMessage.append(depthString);//from  w  ww . j av  a  2s. c o  m
    if (in) {
        inMessage.append(">> ");
        TraceDepthThreadLocal.increaseDepth();
    } else {
        inMessage.append("<< ");
        TraceDepthThreadLocal.decreaseDepth();
    }
    inMessage.append(signature.getDeclaringType().getName()).append('.').append(signature.getName())
            .append("()");
    return inMessage.toString();
}

From source file:de.huxhorn.lilith.tracing.TracingAspect.java

License:Open Source License

public Object trace(ProceedingJoinPoint call) throws Throwable {
    if (logger == null) {
        setLoggerName(null);//from w w w  .  ja  v  a 2  s .  co m
        // this initializes the logger
    }
    Signature signature = call.getSignature();
    Class<?> clazz = signature.getDeclaringType();
    Object theTarget = call.getTarget();
    if (theTarget != null) {
        clazz = theTarget.getClass();
    }
    String fullClassName = clazz.getName();
    String methodName = signature.getName();
    StringBuilder msg = new StringBuilder();
    if (showingModifiers) {
        msg.append(Modifier.toString(signature.getModifiers())).append(' ');
    }
    if (usingShortClassName) {
        msg.append(clazz.getSimpleName());
    } else {
        msg.append(fullClassName);
    }
    msg.append('.').append(methodName);
    String methodBaseName = msg.toString();
    if (signature instanceof MethodSignature) {
        MethodSignature methodSignature = (MethodSignature) signature;
        msg.append('(');
        if (showingParameterValues) {
            Object[] args = call.getArgs();
            boolean first = true;
            for (Object arg : args) {
                if (first) {
                    first = false;
                } else {
                    msg.append(", ");
                }
                msg.append(SafeString.toString(arg, SafeString.StringWrapping.ALL,
                        SafeString.StringStyle.GROOVY, SafeString.MapStyle.GROOVY));
            }
        } else {
            Method method = methodSignature.getMethod();
            Class<?>[] parameterTypes = method.getParameterTypes();
            boolean first = true;
            for (Class<?> param : parameterTypes) {
                if (first) {
                    first = false;
                } else {
                    msg.append(", ");
                }
                msg.append(param.getSimpleName());
            }
            if (method.isVarArgs()) {
                int length = msg.length();
                msg.delete(length - 2, length); // cut of existing []
                msg.append("...");
            }
        }
        msg.append(')');
    }
    String methodSignatureString = msg.toString();

    String previousClass = MDC.get(TRACED_CLASS_MDC_KEY);
    String previousMethod = MDC.get(TRACED_METHOD_MDC_KEY);
    long nanoSeconds = 0;
    try {
        MDC.put(TRACED_CLASS_MDC_KEY, fullClassName);
        MDC.put(TRACED_METHOD_MDC_KEY, methodName);
        if (logger.isInfoEnabled(ENTERING_MARKER))
            logger.info(ENTERING_MARKER, "{} entered.", methodSignatureString);
        Object result;
        nanoSeconds = System.nanoTime();
        result = call.proceed();
        nanoSeconds = System.nanoTime() - nanoSeconds;
        profile(methodBaseName, methodSignatureString, nanoSeconds);
        if (result == null || !showingParameterValues) {
            if (logger.isInfoEnabled(EXITING_MARKER))
                logger.info(EXITING_MARKER, "{} returned.", methodSignatureString);
        } else {
            if (logger.isInfoEnabled(EXITING_MARKER))
                logger.info(EXITING_MARKER, "{} returned {}.", methodSignatureString, result);
        }
        return result;
    } catch (Throwable t) {
        nanoSeconds = System.nanoTime() - nanoSeconds;
        profile(methodBaseName, methodSignatureString, nanoSeconds);
        if (logger.isInfoEnabled(THROWING_MARKER))
            logger.info(THROWING_MARKER, "{} failed.", methodSignatureString, t);
        throw t; // rethrow
    } finally {
        if (previousClass == null) {
            MDC.remove(TRACED_CLASS_MDC_KEY);
        } else {
            MDC.put(TRACED_CLASS_MDC_KEY, previousClass);
        }
        if (previousMethod == null) {
            MDC.remove(TRACED_METHOD_MDC_KEY);
        } else {
            MDC.put(TRACED_METHOD_MDC_KEY, previousMethod);
        }
    }
}

From source file:es.frnd.logging.MethodLoggingAdvice.java

License:Open Source License

/**
 * Extract the logger for the specific class of the poincut
 *
 * @param call//from   w  w w . ja va2s  . co m
 * @return
 */
private Logger extractLogger(JoinPoint call) {
    Class<?> declaringType;
    Signature signature;
    Logger logger;

    signature = call.getSignature();
    declaringType = signature.getDeclaringType();
    logger = LoggerFactory.getLogger(declaringType);

    return logger;
}

From source file:hr.fer.zemris.vhdllab.service.aspect.EntitySecurityAspect.java

License:Apache License

private String getCallSignature(JoinPoint jp) {
    Signature signature = jp.getSignature();
    return signature.getDeclaringType().getSimpleName() + "." + signature.getName();
}