Example usage for org.aspectj.lang Signature getName

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

Introduction

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

Prototype

String getName();

Source Link

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.bbm.common.aspect.ExceptionTransfer.java

License:Apache License

/**
 * ? Exception ? ?  ??   ??  ? ./* w ww .  j  a v  a 2  s.c o m*/
 * @param thisJoinPoint joinPoint ?
 * @param exception ? Exception 
 */
public void transfer(JoinPoint thisJoinPoint, Exception exception) throws Exception {
    log.debug("execute ExceptionTransfer.transfer ");

    Class clazz = thisJoinPoint.getTarget().getClass();
    Signature signature = thisJoinPoint.getSignature();

    Locale locale = LocaleContextHolder.getLocale();
    /**
     * BizException ?  ??     ? ?.
     * Exception   ?? ? ?? Exception? ? ? ?.
     *   ?    . 
     * ?   ??  Handler     ?  ?.
     */

    String servicename = ""; //  
    String errorCode = ""; // ? 
    String errorMessage = ""; // ? 
    String classname = ""; // ??  

    int servicepos = clazz.getCanonicalName().lastIndexOf("."); //   .? 
    if (servicepos > 0) {
        String tempStr = clazz.getCanonicalName().substring(servicepos + 1);
        servicepos = tempStr.lastIndexOf("Impl"); //   Impl? 
        servicename = tempStr.substring(0, servicepos);
    } else {
        servicename = clazz.getCanonicalName();
    }
    classname = exception.getClass().getName();

    //EgovBizException ? ? 
    if (exception instanceof EgovBizException) {
        log.debug("Exception case :: EgovBizException ");

        EgovBizException be = (EgovBizException) exception;
        getLog(clazz).error(be.getMessage(), be.getCause());

        // Exception Handler ? ?? Package  Exception . (runtime ?  ExceptionHandlerService )
        processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices);

        throw be;

        //RuntimeException ? ? ? DataAccessException ?   ?? throw  .
    } else if (exception instanceof RuntimeException) {
        log.debug("RuntimeException case :: RuntimeException ");

        RuntimeException be = (RuntimeException) exception;
        getLog(clazz).error(be.getMessage(), be.getCause());

        // Exception Handler ? ?? Package  Exception .
        processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices);

        if (be instanceof DataAccessException) {
            /*
            log.debug("RuntimeException case :: DataAccessException ");
            DataAccessException sqlEx = (DataAccessException) be;
            throw sqlEx;
            */
            log.debug("RuntimeException case :: DataAccessException ");

            DataAccessException dataEx = (DataAccessException) be;
            Throwable t = dataEx.getRootCause();
            String exceptionname = t.getClass().getName();

            if (exceptionname.equals("java.sql.SQLException")) {
                java.sql.SQLException sqlException = (java.sql.SQLException) t;
                errorCode = String.valueOf(sqlException.getErrorCode());
                errorMessage = sqlException.getMessage();
            } else if (exception instanceof org.springframework.jdbc.BadSqlGrammarException) {
                org.springframework.jdbc.BadSqlGrammarException sqlEx = (org.springframework.jdbc.BadSqlGrammarException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else if (exception instanceof org.springframework.jdbc.UncategorizedSQLException) {
                org.springframework.jdbc.UncategorizedSQLException sqlEx = (org.springframework.jdbc.UncategorizedSQLException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else if (exception instanceof org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) {
                org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException sqlEx = (org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) exception;
                errorCode = String.valueOf(sqlEx.getActualRowsAffected());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.SQLWarningException) {
                org.springframework.jdbc.SQLWarningException sqlEx = (org.springframework.jdbc.SQLWarningException) exception;
                errorCode = String.valueOf(sqlEx.SQLWarning().getErrorCode());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.CannotGetJdbcConnectionException) {
                org.springframework.jdbc.CannotGetJdbcConnectionException sqlEx = (org.springframework.jdbc.CannotGetJdbcConnectionException) exception;
                errorCode = String.valueOf(sqlEx.getMessage());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.InvalidResultSetAccessException) {
                org.springframework.jdbc.InvalidResultSetAccessException sqlEx = (org.springframework.jdbc.InvalidResultSetAccessException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else {

                if (exception instanceof java.lang.reflect.InvocationTargetException) {

                    java.lang.reflect.InvocationTargetException ce = (java.lang.reflect.InvocationTargetException) exception;
                    errorCode = "";
                    errorMessage = ce.getTargetException().getMessage();
                    //strErrorMessage = getValue(ce.getTargetException().toString(), "");

                }
            }

            //  , ?, ?, ,  
            String[] messages = new String[] { "DataAccessException", errorCode, errorMessage, servicename,
                    signature.getName(), classname };
            throw processException(clazz, "fail.common.msg", messages, exception, locale);
        }

        //  , ?, ?, ,  
        errorMessage = exception.getMessage();
        String[] messages = new String[] { "RuntimeException", errorCode, errorMessage, servicename,
                signature.getName(), classname };
        throw processException(clazz, "fail.common.msg", messages, exception, locale);
        //throw be;

        // ? ? Exception (: ) :: ?  ?.
    } else if (exception instanceof FdlException) {
        log.debug("FdlException case :: FdlException ");

        FdlException fe = (FdlException) exception;
        getLog(clazz).error(fe.getMessage(), fe.getCause());
        errorMessage = exception.getMessage();
        //  , ?, ?, ,  
        String[] messages = new String[] { "FdlException", errorCode, errorMessage, servicename,
                signature.getName(), classname };

        throw processException(clazz, "fail.common.msg", messages, exception, locale);
        //throw fe;

    } else {
        //? ? Exception ?  BaseException (: fail.common.msg)     ?. 
        //:: ?  ?.
        log.debug("case :: Exception ");

        getLog(clazz).error(exception.getMessage(), exception.getCause());

        errorMessage = exception.getMessage();
        //  , ?, ?, ,  
        String[] messages = new String[] { "Exception", errorCode, errorMessage, servicename,
                signature.getName(), classname };

        throw processException(clazz, "fail.common.msg", messages, exception, locale);

    }
}

From source file:com.create.aop.LoggingAspect.java

License:Apache License

private String getMethodName(Signature signature) {
    return signature.getName();
}

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

License:Apache License

public SignatureInfo(Signature signature) {
    if (signature == null) {
        return;// w w w  .jav a 2 s.com
    }

    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 a va2  s  .com*/
 */
@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.klistret.cmdb.aspect.crud.ElementIntegration.java

License:Open Source License

public Object transmit(ProceedingJoinPoint pjp) throws Throwable {
    try {/* ww w  .j a v  a 2s  .c  om*/
        Element element = (Element) pjp.proceed();

        Signature signature = pjp.getSignature();
        String name = signature.getName().toUpperCase();
        Object[] args = pjp.getArgs();

        if (name.equals("GET"))
            name = "READ";
        try {
            SignatureMethod method = SignatureMethod.valueOf(name);

            switch (method) {
            case CREATE:
            case DELETE:
            case UPDATE:
            case READ:
                Element precedent = null;

                for (Object arg : args)
                    if (arg instanceof Element)
                        precedent = (Element) arg;

                logger.debug("Generating a message with CRUD function {} on element [id: {}, version: {}]",
                        new Object[] { name, element.getId(), element.getVersion() });

                Message<Element> message = MessageBuilder.withPayload(element).setHeader("function", name)
                        .setHeader("precedent", precedent == null ? null : precedent.getVersion()).build();
                channel.send(message);
                break;
            }
        } catch (IllegalArgumentException e) {
            logger.debug("Method {} is not trasmitted", name);
        }

        return element;
    } catch (HibernateOptimisticLockingFailureException e) {
        throw new ApplicationException("Stale element.", new StaleStateException(e.getMessage()));
    } catch (Exception e) {
        logger.error("Unknown exception: {}", e.getMessage());
        throw e;
    }
}

From source file:com.klistret.cmdb.aspect.crud.RelationIntegration.java

License:Open Source License

public Object transmit(ProceedingJoinPoint pjp) throws Throwable {
    try {//from   www  .  jav a 2s  .  c o  m
        Relation relation = (Relation) pjp.proceed();

        Signature signature = pjp.getSignature();
        String name = signature.getName().toUpperCase();
        Object[] args = pjp.getArgs();

        if (name.equals("GET"))
            name = "READ";
        try {
            SignatureMethod method = SignatureMethod.valueOf(name);

            switch (method) {
            case CREATE:
            case DELETE:
            case UPDATE:
            case READ:
                Relation precedent = null;

                for (Object arg : args)
                    if (arg instanceof Relation)
                        precedent = (Relation) arg;

                logger.debug("Generating a message with CRUD function {} on relation [id: {}, version: {}]",
                        new Object[] { name, relation.getId(), relation.getVersion() });

                Message<Relation> message = MessageBuilder.withPayload(relation).setHeader("function", name)
                        .setHeader("precedent", precedent == null ? null : precedent.getVersion()).build();
                channel.send(message);
                break;
            }
        } catch (IllegalArgumentException e) {
            logger.debug("Method {} is not trasmitted", name);
        }

        return relation;
    } catch (HibernateOptimisticLockingFailureException e) {
        throw new ApplicationException("Stale relation.", new StaleStateException(e.getMessage()));
    } catch (Exception e) {
        logger.error("Unknown exception: {}", e.getMessage());
        throw e;
    }
}

From source file:com.klistret.cmdb.utility.spring.OptimisticLocking.java

License:Open Source License

public Object commitTransaction(ProceedingJoinPoint pjp) throws Throwable {
    try {//www. j a v  a 2  s.  c om
        return pjp.proceed();
    } catch (HibernateOptimisticLockingFailureException e) {
        Signature signature = pjp.getSignature();
        logger.error("Stale in declaration:{}, name: {}, long: {} message: {}", new Object[] {
                signature.getDeclaringTypeName(), signature.getName(), pjp.toLongString(), e.getMessage() });
        throw new ApplicationException("Stale entity captured.");
    }
}

From source file:com.liferay.portal.workflow.WorkflowLinkAdvice.java

License:Open Source License

public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

    Signature signature = proceedingJoinPoint.getSignature();

    String methodName = signature.getName();

    Object[] arguments = proceedingJoinPoint.getArgs();

    if (methodName.equals(_UPDATE_ACTIVE)) {
        long companyId = (Long) arguments[0];
        String name = (String) arguments[2];
        int version = (Integer) arguments[3];
        boolean active = (Boolean) arguments[4];

        if (!active) {
            int workflowDefinitionLinksCount = WorkflowDefinitionLinkLocalServiceUtil
                    .getWorkflowDefinitionLinksCount(companyId, name, version);

            if (workflowDefinitionLinksCount >= 1) {
                throw new RequiredWorkflowDefinitionException();
            }/*from   ww  w  . ja v  a  2 s.  c o  m*/
        }
    }

    return proceedingJoinPoint.proceed();
}