List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:com.thesoftwareguild.mavenflooringmastery.aspects.AuditAspect.java
public Object logDelete(ProceedingJoinPoint jp) { Object retVal = null;//w ww . j a v a 2 s . c o m try { //retVal = jp.proceed(); CANT DO THIS BECAUSE AFTER THE METHOD DELETE IN ORDERDAO IS CALLED, the order is gone. It'll throw a nullpointerexception! Integer orderNumber = (Integer) jp.getArgs()[0]; //This is an Integer because the argument passed in the delete method is an integer Order order = odao.get(orderNumber); retVal = jp.proceed(); Date now = new Date(); AuditEntry entry = new AuditEntry(now, order, "DELETED"); dao.log(entry); } catch (Throwable ex) { Logger.getLogger(AuditAspect.class.getName()).log(Level.SEVERE, null, ex); } return retVal; }
From source file:com.thinkbiganalytics.install.inspector.aop.logging.LoggingAspect.java
License:Apache License
/** * Advice that logs when a method is entered and exited. * * @param joinPoint join point for advice * @return result//from w ww.j a va 2 s.c o m * @throws Throwable throws IllegalArgumentException */ @Around("applicationPackagePointcut() && springBeanPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { 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:com.tikal.tallerWeb.servicio.monitor.imp.EditorMonitorImpV3.java
License:Apache License
@Around("modelChange()") public void updateProperty(ProceedingJoinPoint pjp) throws Throwable { if (encendido && activo) { Object target = pjp.getTarget(); Object proxyTarget = AopContext.currentProxy(); if (!(target instanceof Metadata)) { String methodName = pjp.getSignature().getName(); String propertyName = StringUtils.substringAfter(methodName, "set"); String primeraLetra = propertyName.charAt(0) + ""; propertyName = primeraLetra.toLowerCase() + StringUtils.substringAfter(propertyName, primeraLetra); processChange(proxyTarget, propertyName, pjp.getArgs()[0]); }// w ww. j a v a 2s. co m } pjp.proceed(); }
From source file:com.utest.domain.service.cache.CachedContextManager.java
License:Apache License
@Around(value = "@annotation(com.utest.annotations.CacheEvent) && @annotation(cacheEvent)") public Object processCacheEvent(final ProceedingJoinPoint joinPoint, final CacheEvent cacheEvent) throws Throwable { if (CacheEvent.CACHE_READ.equals(cacheEvent.operation())) { return checkCache(joinPoint, cacheEvent); }// w ww . j av a 2 s . c o m final Object ret = joinPoint.proceed(joinPoint.getArgs()); if (CacheEvent.CACHE_REFRESH.equals(cacheEvent.operation())) { cleanCache(joinPoint, cacheEvent); } return ret; }
From source file:com.utest.domain.service.cache.CachedContextManager.java
License:Apache License
@SuppressWarnings("unchecked") private Object checkCache(final ProceedingJoinPoint joinPoint, final CacheEvent cacheEvent) throws Throwable { final Object[] args = joinPoint.getArgs(); Object cachedValue = null;/*from www .j a v a 2 s .co m*/ if (CacheEvent.USER_MATCHING.equals(cacheEvent.type())) { final Integer userId = getUserFromArgs(args); if (userId != null) { cachedValue = holder.getTestCyclesForUser(userId); if (cachedValue == null) { cachedValue = joinPoint.proceed(args); holder.updateUserTestCycles(userId, (List<Integer>) cachedValue); } } } return cachedValue; }
From source file:com.utest.domain.service.cache.CachedContextManager.java
License:Apache License
private void cleanCache(final ProceedingJoinPoint joinPoint, final CacheEvent cacheEvent) throws Throwable { if (CacheEvent.USER_MATCHING.equals(cacheEvent.type())) { final Object[] args = joinPoint.getArgs(); final Integer userId = getUserFromArgs(args); if (userId != null) { holder.updateUserTestCycles(userId, null); }// w w w. j a v a2 s . c om } else if (CacheEvent.USER_CONTEXT.equals(cacheEvent.type())) { final Object[] args = joinPoint.getArgs(); final Integer userId = getUserFromArgs(args); if (userId != null) { holder.removeUser(userId); } } else if (CacheEvent.TEST_CYCLE_MATCHING.equals(cacheEvent.type())) { final Set<Integer> loggedInUsers = holder.getUserIds(); for (final Integer userId : loggedInUsers) { holder.updateUserTestCycles(userId, null); } } }
From source file:com.vaadin.addon.jpacontainer.demo.aspects.ProviderLoggerAspect.java
License:Apache License
@Around("methodsToBeLogged()") public Object log(ProceedingJoinPoint pjp) throws Throwable { if (logger.isDebugEnabled()) { StringBuilder sb = new StringBuilder(pjp.getSignature().getName()); sb.append("("); if (pjp.getArgs().length > 0) { for (int i = 0; i < pjp.getArgs().length - 2; i++) { sb.append(pjp.getArgs()[i]); sb.append(","); }//from ww w .j a v a 2 s. c o m sb.append(pjp.getArgs()[pjp.getArgs().length - 1]); } sb.append(")"); logger.debug("Calling method: " + sb.toString()); } Object result = pjp.proceed(); if (logger.isDebugEnabled()) { logger.debug("Result of method " + pjp.getSignature().getName() + ": " + result); } return result; }
From source file:com.variacode.utils.object.changelistener.ObservableObjectAspect.java
License:Apache License
@Around("execution(* *.set*(..)) && @within(annotation)") public Object setMethod(ProceedingJoinPoint joinPoint, Observe annotation) throws Throwable { ObserverSingleton.INSTANCE.change(new Change(annotation.stream(), Introspector.decapitalize(joinPoint.toShortString() .replaceFirst("execution\\(" + joinPoint.getThis().getClass().getSimpleName() + ".set", "") .replaceAll("\\.", "").replaceAll("\\)", "").replaceAll("\\(", "")), joinPoint.getArgs()[0], joinPoint.getThis())); return joinPoint.proceed(); }
From source file:com.vladmihalcea.util.ReflectionUtils.java
License:Apache License
public static <T extends Annotation> T getAnnotation(ProceedingJoinPoint pjp, Class<T> annotationClass) throws NoSuchMethodException { MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getMethod(); T annotation = AnnotationUtils.findAnnotation(method, annotationClass); if (annotation != null) { return annotation; }//w w w. ja va 2s .c om Class[] argClasses = new Class[pjp.getArgs().length]; for (int i = 0; i < pjp.getArgs().length; i++) { argClasses[i] = pjp.getArgs()[i].getClass(); } method = pjp.getTarget().getClass().getMethod(pjp.getSignature().getName(), argClasses); return AnnotationUtils.findAnnotation(method, annotationClass); }
From source file:com.vmware.bdd.aop.lock.ClusterEntityConcurentWriteLockAdvice.java
License:Open Source License
public Object lock(ProceedingJoinPoint pjp) throws Throwable { Object[] objs = pjp.getArgs(); String clusterName = (String) objs[0]; logger.info("Lock competitive write for cluster " + clusterName); boolean locked = false; try {/*from w ww.j a va 2 s . c o m*/ lockConcurrentWrite((String) clusterName); locked = true; return pjp.proceed(); } finally { if (locked) { unlockConcurrentWrite(clusterName); logger.info("Unlock competitive write for cluster " + clusterName); } } }