List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:edu.utah.further.dts.impl.aspect.DtsTransactionAspect.java
License:Apache License
/** * Execute DTS session wrapping for an applicable join point. * /*from w ww. java 2 s . com*/ * @param jp * proceeding join point * @param dtsTransactionalAnnotation * DTS-transactionality annotation * @return proceeding joint point's return value * @throws Throwable * if wrapped method invocation throws an exception */ private Object wrapInDtsSession(final ProceedingJoinPoint jp, final DtsTransactional dtsTransactionalAnnotation) throws Throwable { // Fetch join point parameters final String methodName = jp.getSignature().getDeclaringTypeName() + "." + jp.getSignature().getName(); final DtsPropagation propagation = dtsTransactionalAnnotation.propagation(); // Validate session boundaries final boolean sessionOpen = connectionFactory.isSessionOpen(); if ((propagation == DtsPropagation.NEVER) && sessionOpen) { throw new IllegalStateException("DTS session boundaries violation: method " + methodName + " declares propagation " + propagation + " but there is currently an open DTS session"); } if ((propagation == DtsPropagation.MANDATORY) && !sessionOpen) { throw new IllegalStateException("DTS session boundaries violation: method " + methodName + " declares propagation " + propagation + " but there is currently no open DTS session"); } // Wrap method invocation in a DTS session if needed final boolean needToCreateNewSession = !sessionOpen && (propagation == DtsPropagation.REQUIRED); if (needToCreateNewSession) { if (log.isDebugEnabled()) { log.debug("Starting session for " + methodName + ", propagation " + propagation); } connectionFactory.startSession(); } // Treat both happy and failed paths. If an exception is thrown, save it // in throwable; then close the session; then process throwable Throwable throwable = null; Object retval = null; try { retval = jp.proceed(); } catch (final Throwable t) { throwable = t; } if (needToCreateNewSession) { if (log.isDebugEnabled()) { log.debug("Closing session for " + methodName); } connectionFactory.closeSession(); } // ======================== // Exception handling // ======================== if (throwable != null) { // Discover if there's an options argument to the method; otherwise // always throw an exception final Object[] args = jp.getArgs(); DtsOptions options = discoverDtsOptionsMethodArgument(args); if (options == null) { options = newDefaultOptions(); } // Decide if to throw a FURTHeR-wrapped exception DtsUtil.wrapAndThrowApelonException(options.isThrowExceptionOnFailure(), throwable); // If not, throw the raw exception throw throwable; } return retval; }
From source file:fi.helsinki.opintoni.aop.logging.LoggingAspect.java
License:Open Source License
@Around("loggingPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { if (shouldSkip(joinPoint)) { return joinPoint.proceed(); }/* www . j a v a2 s . co m*/ if (log.isDebugEnabled()) { log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs())); } try { Object result = joinPoint.proceed(); if (log.isDebugEnabled()) { log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), result); } return result; } catch (IllegalArgumentException e) { log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); throw e; } }
From source file:fi.helsinki.opintoni.aop.logging.LoggingAspect.java
License:Open Source License
private List<Annotation> getMethodAnnotations(ProceedingJoinPoint joinPoint) throws NoSuchMethodException { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); String methodName = signature.getMethod().getName(); Class<?>[] parameterTypes = signature.getMethod().getParameterTypes(); return Lists.newArrayList( joinPoint.getTarget().getClass().getMethod(methodName, parameterTypes).getAnnotations()); }
From source file:fm.pattern.valex.annotations.ValidationAdvisor.java
License:Apache License
private <T> T getAnnotation(ProceedingJoinPoint pjp, Class<T> annotationType) throws Throwable { MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getDeclaringType().getDeclaredMethod(signature.getName(), signature.getParameterTypes()); for (Annotation annotation : method.getParameterAnnotations()[0]) { if (annotationType.isInstance(annotation)) { return (T) annotation; }// ww w . j av a 2s . c o m } return null; }
From source file:fr.wirth.aspect.GlobalAspect.java
License:Apache License
@Around("execution(* fr.wirth..*(..))") public Object methodsWithArgumentsLogger(ProceedingJoinPoint joinPoint) throws Throwable { StringBuilder sb = new StringBuilder("Calling : "); sb.append(joinPoint.getSignature().getDeclaringType().getName()); sb.append("."); sb.append(joinPoint.getSignature().getName()); sb.append("("); sb.append(Arrays.toString(joinPoint.getArgs())); sb.append(")"); LOGGER.debug(sb.toString());/*from w w w .ja va2 s . c o m*/ Object value = joinPoint.proceed(); sb = new StringBuilder("Result : "); sb.append(value); LOGGER.debug(sb.toString()); return value; }
From source file:gov.fda.open.demo.service.loggable.LoggingAspect.java
License:Open Source License
/** * ********************.//ww w. j av a2 s . co m * * @param joinPoint * the join point * @param annotation * the annotation * @return the object * @throws Throwable * the throwable */ @Around(value = "@annotation(annotation)") public Object logAround(final ProceedingJoinPoint joinPoint, final Loggable annotation) throws Throwable { final Object returnVal; Class<? extends Object> clazz = joinPoint.getTarget().getClass(); String name = joinPoint.getSignature().getName(); Object[] args = joinPoint.getArgs(); if (args == null || args.length == 0) { logger.log(annotation.value(), clazz, null, BEFORE_STRING, name, constructArgumentsString(clazz, joinPoint.getArgs())); } else { logger.log(annotation.value(), clazz, null, BEFORE_WITH_PARAMS_STRING, name, constructArgumentsString(clazz, joinPoint.getArgs())); } returnVal = joinPoint.proceed(); // Now Do The After Logging Part afterReturningLog(joinPoint, annotation, returnVal); return returnVal; }
From source file:gov.nih.nci.cabig.ctms.acegi.csm.authorization.CSMPrivilegeAndObjectRetrievalStrategy.java
License:BSD License
public PrivilegeAndObject retrieve(ProceedingJoinPoint pjp) { PrivilegeAndObject pao = null;//from w ww . j a va 2 s . c om for (SignatureToPrivilegeMapping mapping : getMappings()) { if (mapping.matches(pjp.getSignature())) { Object[] args = pjp.getArgs(); Object object = getDomainObject(args); String privilege = mapping.getPrivilege(); pao = new PrivilegeAndObject(privilege, object); break; } } return pao; }
From source file:gov.nih.nci.cacis.common.aop.LoggingAspect.java
License:BSD License
/** * Logging advice, logs entry and exit of designated methods. * * @param pjp ProceedingJoinPoint// w w w . j a v a2 s . com * @return Object returned object * @throws Throwable thrown exception */ @Around("PointCuts.withinService() && execution(public * *(..)) || " + "PointCuts.withinDao() && execution(* *..Dao.*(..))") // CHECKSTYLE:OFF to allow Throwable public Object loggingAdvice(ProceedingJoinPoint pjp) throws Throwable { // CHECKSTYLE:ON final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringTypeName()); if (log.isDebugEnabled()) { log.debug(pjp.getSignature().getName() + "() : Enter"); } final Object retVal = pjp.proceed(); if (log.isDebugEnabled()) { log.debug(pjp.getSignature().getName() + "() : Exit"); } return retVal; }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.aspect.cache.CacheAspect.java
@Around("cache()") public Object aroundCachedMethods(ProceedingJoinPoint thisJoinPoint) throws Throwable { // generate the key under which cached value is stored // will look like package.class.method(arg1=val1;arg2=val2;) StringBuilder keyBuff = new StringBuilder(); // append name of the class keyBuff.append(thisJoinPoint.getTarget().getClass().getName()); // append name of the method keyBuff.append(".").append(thisJoinPoint.getSignature().getName()); keyBuff.append("("); // find method arguments for (final Object arg : thisJoinPoint.getArgs()) { // append argument type and value keyBuff.append(arg.getClass().getSimpleName() + "=" + arg + ";"); }/*w w w.j a v a 2s . co m*/ keyBuff.append(")"); String key = keyBuff.toString(); Element element = cache.get(key); if (element == null) { logger.info("[" + Thread.currentThread().getId() + "] Result not yet cached for " + key + " let's proceed"); // Synchronizing calls to only getUUIDRows API. Because calling multiple getUUIDRows at the same time // might take more memory if (key.contains("UUIDBrowserDAOImpl.getUUIDRows()")) { synchronized (refreshDataLock) { // doing this one more time so that the threads that are waiting in this lock, will // use the cache instead of db element = cache.get(key); if (element == null) { element = storeDataInCache(thisJoinPoint, key); } } } else { element = storeDataInCache(thisJoinPoint, key); } } return (element != null) ? element.getValue() : null; }
From source file:hr.fer.zemris.vhdllab.service.aspect.LogAspect.java
License:Apache License
@Around("services()") public Object logExecution(ProceedingJoinPoint pjp) throws Throwable { long start = 0; String callSignature = null;//from w ww . j a v a 2 s. c o m String arguments = null; if (LOG.isTraceEnabled()) { Signature signature = pjp.getSignature(); callSignature = signature.getDeclaringType().getSimpleName() + "." + signature.getName(); arguments = Arrays.toString(pjp.getArgs()); LOG.trace("Entering " + callSignature + " with arguments: " + arguments); start = System.currentTimeMillis(); } Object returnValue = pjp.proceed(); if (LOG.isTraceEnabled()) { long end = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(1000); sb.append(callSignature); sb.append(" finished execution in ").append(end - start); sb.append(" ms for arguments: ").append(arguments); sb.append(" and returned: ").append(returnValue); LOG.trace(sb.toString()); } return returnValue; }