List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:com.jmhz.device.sys.aop.UserCacheAspect.java
License:Apache License
@Around(value = "userServicePointcut() && cacheablePointcut()") public Object cacheableAdvice(ProceedingJoinPoint pjp) throws Throwable { String methodName = pjp.getSignature().getName(); Object arg = pjp.getArgs().length >= 1 ? pjp.getArgs()[0] : null; String key = ""; boolean isIdKey = false; if ("findOne".equals(methodName)) { key = idKey(String.valueOf(arg)); isIdKey = true;// ww w .j av a2 s . c om } else if ("findByUsername".equals(methodName)) { key = usernameKey((String) arg); } else if ("findByEmail".equals(methodName)) { key = telKey((String) arg); } User user = null; if (isIdKey == true) { user = get(key); } else { Long id = get(key); if (id != null) { key = idKey(String.valueOf(id)); user = get(key); } } //cache hit if (user != null) { log.debug("cacheName:{}, hit key:{}", cacheName, key); return user; } log.debug("cacheName:{}, miss key:{}", cacheName, key); //cache miss user = (User) pjp.proceed(); //put cache put(user); return user; }
From source file:com.job.lr.aop.LogAspect.java
License:Apache License
/** * ?? ProceedingJoinPoint ?. /*from w ww. jav a 2 s . com*/ * ??: ProceedingJoinPoint ???. * , ? */ @Around("pointcutExpression()") public Object aroundMethod(ProceedingJoinPoint pjd) { Object result = null; String methodName = pjd.getSignature().getName(); try { //? System.out.println("The method " + methodName + " begins with " + Arrays.asList(pjd.getArgs())); // result = pjd.proceed(); // System.out.println("The method " + methodName + " ends with " + result); } catch (Throwable e) { // System.out.println("The method " + methodName + " occurs exception:" + e); throw new RuntimeException(e); } //? System.out.println("The method " + methodName + " ends"); return result; }
From source file:com.joken.base.spring.aop.CacheableAop.java
License:Open Source License
/** * ?key//from ww w . ja v a2s . c o m * * @param pjp * * @param cache * * @return */ private String getCacheKey(ProceedingJoinPoint pjp, Cacheable cache) { Annotation[][] pas = ((MethodSignature) pjp.getSignature()).getMethod().getParameterAnnotations(); StringBuilder buf = new StringBuilder(); Object[] args = pjp.getArgs(); Object objVal; String val; BigDecimal expire; List<Object> params = new ArrayList<Object>(); for (int i = 0; i < pas.length; i++) { objVal = args[i]; if (objVal == null) { continue; } val = objVal.toString(); val = val.replaceAll(",", "-"); for (Annotation an : pas[i]) { if (an instanceof CacheKey) { if (buf.length() > 0) { buf.append(":"); } buf.append(val); params.add(val); break; } else if (an instanceof ExpireKey) {// ? try { expire = new BigDecimal(val); THREAD_CACHE_EXPIRE.set(expire.intValue()); } catch (Exception e) { } } } } if (StringUtils.isEmpty(cache.keyName())) { return buf.toString(); } if (cache.keyArray()) { return StringUtils.format(SystemGlobal.get(cache.keyName()), params.toArray(new Object[0])); } return StringUtils.format(SystemGlobal.get(cache.keyName()), buf.toString()); }
From source file:com.klistret.cmdb.aspect.crud.ElementIntegration.java
License:Open Source License
public Object transmit(ProceedingJoinPoint pjp) throws Throwable { try {/*from w w w .j a v a 2 s . c o m*/ 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 ww w . j a va 2 s . co 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.liferay.portal.messaging.proxy.MessagingProxyAdvice.java
License:Open Source License
protected ProxyRequest createProxyRequest(ProceedingJoinPoint proceedingJoinPoint) throws Exception { return new ProxyRequest(AspectJUtil.getMethod(proceedingJoinPoint), proceedingJoinPoint.getArgs()); }
From source file:com.liferay.portal.messaging.proxy.MultiDestinationMessagingProxyAdvice.java
License:Open Source License
protected ProxyRequest createProxyRequest(ProceedingJoinPoint proceedingJoinPoint) throws Exception { return new ProxyRequest(com.liferay.util.aspectj.AspectJUtil.getMethod(proceedingJoinPoint), proceedingJoinPoint.getArgs()); }
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 w w w.j a v a2 s . c om } } return proceedingJoinPoint.proceed(); }
From source file:com.liferay.portal.workflow.WorkflowLockingAdvice.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(_START_WORKFLOW_INSTANCE_METHOD_NAME)) { String workflowDefinitionName = (String) arguments[3]; Integer workflowDefinitionVersion = (Integer) arguments[4]; String className = WorkflowDefinition.class.getName(); String key = _encodeKey(workflowDefinitionName, workflowDefinitionVersion); if (LockLocalServiceUtil.isLocked(className, key)) { throw new WorkflowException("Workflow definition name " + workflowDefinitionName + " and version " + workflowDefinitionVersion + " is being undeployed"); }/*from www . j a v a 2s. c o m*/ return proceedingJoinPoint.proceed(); } else if (!methodName.equals(_UNDEPLOY_WORKFLOW_DEFINITION_METHOD_NAME)) { return proceedingJoinPoint.proceed(); } long userId = (Long) arguments[1]; String name = (String) arguments[2]; Integer version = (Integer) arguments[3]; String className = WorkflowDefinition.class.getName(); String key = _encodeKey(name, version); if (LockLocalServiceUtil.isLocked(className, key)) { throw new WorkflowException( "Workflow definition name " + name + " and version " + version + " is being undeployed"); } try { LockLocalServiceUtil.lock(userId, className, key, String.valueOf(userId), false, Time.HOUR); return proceedingJoinPoint.proceed(); } finally { LockLocalServiceUtil.unlock(className, key); } }
From source file:com.liferay.portal.workflow.WorkflowPermissionAdvice.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(_ASSIGN_WORKFLOW_TASK_TO_USER_METHOD_NAME)) { long userId = (Long) arguments[1]; PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); if (permissionChecker.getUserId() != userId) { throw new PrincipalException(); }/*from www . j av a 2 s . co m*/ } return proceedingJoinPoint.proceed(); }