List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:org.onebusaway.container.cache.CacheableMethodKeyFactoryManager.java
License:Apache License
public List<Method> getMatchingMethodsForJoinPoint(ProceedingJoinPoint pjp) { Signature sig = pjp.getSignature(); Object target = pjp.getTarget(); Class<?> type = target.getClass(); List<Method> matches = new ArrayList<Method>(); for (Method m : type.getDeclaredMethods()) { if (!m.getName().equals(sig.getName())) continue; // if (m.getModifiers() != sig.getModifiers()) // continue; Object[] args = pjp.getArgs(); Class<?>[] types = m.getParameterTypes(); if (args.length != types.length) continue; boolean miss = false; for (int i = 0; i < args.length; i++) { Object arg = args[i]; Class<?> argType = types[i]; if (argType.isPrimitive()) { if (argType.equals(Double.TYPE) && !arg.getClass().equals(Double.class)) miss = true;// www. j a v a2 s .co m } else { if (arg != null && !argType.isInstance(arg)) miss = true; } } if (miss) continue; matches.add(m); } return matches; }
From source file:org.onebusaway.container.cache.DefaultCacheableKeyFactory.java
License:Apache License
@Override public CacheKeyInfo createKey(ProceedingJoinPoint point) { Object[] args = point.getArgs(); if (args.length != _keyFactories.length) throw new IllegalArgumentException(); // Short circuit for single argument keys if (args.length == 1) return _keyFactories[0].createKey(args[0]); KeyImpl keys = new KeyImpl(args.length); boolean refreshCache = false; for (int i = 0; i < args.length; i++) { CacheKeyInfo keyInfo = _keyFactories[i].createKey(args[i]); keys.set(i, keyInfo.getKey());//from ww w . j a v a2 s . c o m refreshCache |= keyInfo.isCacheRefreshIndicated(); } return new CacheKeyInfo(keys, refreshCache); }
From source file:org.openehealth.ipf.platform.camel.flow.aspect.ExchangeAggregate.java
License:Apache License
/** * Preserves the {@link SplitHistory} of exchanges that are processed by the * {@link MulticastProcessor#process(Exchange)} method. * /*from ww w.j a v a 2 s .c om*/ * @param pjp * proceeding join point. * @throws Throwable */ protected Object doAroundExchangeProcess(ProceedingJoinPoint pjp) throws Throwable { ManagedMessage message = getMessage(pjp); SplitHistory original = message.getSplitHistory(); Object result = pjp.proceed(pjp.getArgs()); SplitHistory current = message.getSplitHistory(); if (!original.equals(current)) { message.setSplitHistory(original); } return result; }
From source file:org.openehealth.ipf.platform.camel.flow.aspect.ExchangeAggregate.java
License:Apache License
private ManagedMessage getMessage(ProceedingJoinPoint pjp) { return new PlatformMessage((Exchange) pjp.getArgs()[0]); }
From source file:org.openinfinity.core.aspect.CryptoAspect.java
License:Apache License
/** * Method for managing encryption of the entity fields. * //w w w . ja va 2s . c o m * @param joinPoint Represent the actual binded joinpoint providing method arguments. * @param encrypt Represents the annotation found from the joinpoint. * @return The original arguments. */ @Around(value = "encryptObjectContentAfterOperation() && @annotation(encrypt)") public Object encryptObjectContentAfterMethod(ProceedingJoinPoint joinPoint, final Encrypt encrypt) { LOGGER.debug("Encryption for the object has started."); try { ArgumentBuilder argumentBuilder = new ArgumentBuilder(); StringBuilder builder = new StringBuilder(); ArgumentStrategy argumentStrategy = encrypt.argumentStrategy(); switch (argumentStrategy) { case ALL: executeGatheringOfAllArguments(joinPoint.getArgs(), encrypt, argumentBuilder, builder); LOGGER.debug("Encryption of the all object fields started."); return joinPoint.proceed(joinPoint.getArgs()); case CUSTOM: executeGatheringOfDefinedArguments(joinPoint.getArgs(), encrypt, argumentBuilder, builder); LOGGER.debug("Encryption of defined object fields started."); return joinPoint.proceed(joinPoint.getArgs()); case NONE: return joinPoint.proceed(joinPoint.getArgs()); default: return joinPoint.proceed(joinPoint.getArgs()); } } catch (Throwable throwable) { ExceptionUtil.throwSystemException(throwable.getMessage(), throwable); } finally { LOGGER.debug("Encryption object fields ended."); } return joinPoint.getArgs(); }
From source file:org.openinfinity.core.aspect.CryptoAspect.java
License:Apache License
/** * Method for managing decryption of the entity fields. * /* w ww.j ava 2 s . c om*/ * @param joinPoint Represent the actual binded joinpoint providing method arguments. * @param encrypt Represents the annotation found from the joinpoint. * @return The original arguments. */ @Around(value = "decryptObjectContentBeforeOperation() && @annotation(decrypt)") public Object decryptObjectContentAfterMethod(ProceedingJoinPoint joinPoint, final Decrypt decrypt) { LOGGER.debug("Decryption for the object has started."); try { ArgumentBuilder argumentBuilder = new ArgumentBuilder(); StringBuilder builder = new StringBuilder(); ArgumentStrategy argumentStrategy = decrypt.argumentStrategy(); switch (argumentStrategy) { case ALL: executeGatheringOfAllArguments(joinPoint.getArgs(), decrypt, argumentBuilder, builder); return joinPoint.proceed(joinPoint.getArgs()); case CUSTOM: executeGatheringOfDefinedArguments(joinPoint.getArgs(), decrypt, argumentBuilder, builder); return joinPoint.proceed(joinPoint.getArgs()); case NONE: return joinPoint.proceed(joinPoint.getArgs()); default: return joinPoint.proceed(joinPoint.getArgs()); } } catch (Throwable throwable) { ExceptionUtil.throwSystemException(throwable.getMessage(), throwable); } finally { LOGGER.debug("Encryption object fields ended."); } return joinPoint.getArgs(); }
From source file:org.openinfinity.core.aspect.CryptoAspectBehaviour.java
License:Apache License
@When("executing business operation and encryption of an object graphs is needed") public void executingBusinessOperationAndEncryptionOfAnObjectGraphsIsNeeded() { //TODO: imitate proceed functionality of the aspect ProceedingJoinPoint joinPoint = (ProceedingJoinPoint) Mockito.mock(Joinpoint.class); Encrypt encrypt = Mockito.mock(Encrypt.class); when(joinPoint.getArgs()).thenReturn(new Object[] { actual }); when(encrypt.argumentStrategy()).thenReturn(ArgumentStrategy.ALL); cipherAspect.encryptObjectContentAfterMethod(joinPoint, encrypt); System.out.println("Doing stuff"); assertTrue(EXPECTED_ID.equals(actual.getId())); }
From source file:org.openinfinity.core.aspect.MultiTenantAspect.java
License:Apache License
/** * Injection of tenant id will be done based on the <code>org.openinfinity.core.annotation.MultiTenant</code> annotation on method level. After injection of the tenant id * <code>org.openinfinity.core.domain.entity.MultiTenantBaseEntity</code> can be used to retrieve the actual tenant id. <code>org.openinfinity.core.domain.entity.MultiTenantBaseEntity</code> * can be extended by <code>org.openinfinity.core.domain.entity.MultiTenantBaseEntity</code>. * /*from ww w . j a v a 2 s . c o m*/ * @param method Represents the method to be executed when exposing <code>org.openinfinity.core.annotation.MultiTenant</code> metadata to it. * @param multiTenant Represents the annotation which executed by the aspect. * @return Object Represents the original arguments for the method with injected tenant id. * @throws Throwable Represents the occurred exception during the execution of the aspect. */ @Around("multiTenantMethod() && @annotation(multiTenant)") public Object populateTenantIdToMultiTenantEntity(ProceedingJoinPoint method, MultiTenant multiTenant) throws Throwable { if (LOGGER.isDebugEnabled()) LOGGER.debug("MultiTenantAspect.populateTenantIdToMultiTenantEntity initialized."); SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); if (authentication instanceof Identity) { Identity identity = (Identity) authentication; Object[] arguments = method.getArgs(); for (Object object : arguments) { if (object instanceof MultiTenantBaseEntity) { if (LOGGER.isDebugEnabled()) LOGGER.debug( "MultiTenantAspect.populateTenantIdToMultiTenantEntity arguments is istance of MultiTenantBaseEntity."); MultiTenantBaseEntity<?, ?, ?> multiTenantBaseEntity = (MultiTenantBaseEntity<?, ?, ?>) object; Object tenantId = identity.getTenantPrincipal().getId(); Field tenantIdField = multiTenantBaseEntity.getClass().getField(TENANT_ID_FIELD); if (!tenantIdField.isAccessible()) { tenantIdField.setAccessible(true); } Object convertedTenantId = typeConverter.convert(tenantId); if (tenantIdField.getType().isAssignableFrom(convertedTenantId.getClass())) { if (LOGGER.isDebugEnabled()) LOGGER.debug( "MultiTenantAspect.populateTenantIdToMultiTenantEntity tenant id is assignable from [" + convertedTenantId.getClass().getName() + "."); ReflectionUtils.setField(tenantIdField, multiTenantBaseEntity, convertedTenantId); if (LOGGER.isInfoEnabled()) LOGGER.info("MultiTenantAspect.populateTenantIdToMultiTenantEntity injected tenant id [" + convertedTenantId.toString() + "] to the entity."); } else { ExceptionUtil.throwSystemException("Field [" + tenantIdField.getType().getName() + "] is not assignable from [" + convertedTenantId.getClass().getName()); } } } } return method.proceed(); }
From source file:org.openo.client.cli.fw.log.OpenOCommandLogger.java
License:Apache License
/** * Logging intercepter./*w w w . j a va2 s . c o m*/ * * @param joinPoint * joinpoint * @return object * @throws Throwable * exception */ @Around("execution(* org.openo.client.cli.fw*(..))") public Object log(ProceedingJoinPoint joinPoint) throws Throwable { // NOSONAR LOGGER.info(joinPoint.getThis().toString() + "->" + joinPoint.getSignature().getName() + "(" + joinPoint.getArgs() + ")"); Object response = joinPoint.proceed(); LOGGER.info(response.toString()); return response; }
From source file:org.openregistry.aspect.LogAspect.java
License:Apache License
@Around("(execution (public * org.openregistry.core..*.*(..))) && !(execution( * org.openregistry.core..*.set*(..)))") public Object traceMethod(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Object returnVal = null;/*from w ww. j a v a 2 s .com*/ final Logger log = getLog(proceedingJoinPoint); final String methodName = proceedingJoinPoint.getSignature().getName(); try { if (log.isTraceEnabled()) { final Object[] args = proceedingJoinPoint.getArgs(); if (args == null || args.length == 0) { log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_BEGIN, new Object[] { methodName, "" }, Locale.getDefault())); } else { final StringBuilder stringBuilder = new StringBuilder(); for (final Object o : args) { stringBuilder.append(o != null ? o.toString() : null).append(", "); } final String argString = stringBuilder.substring(0, stringBuilder.length() - 3); log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_BEGIN, new Object[] { methodName, argString }, Locale.getDefault())); } } returnVal = proceedingJoinPoint.proceed(); return returnVal; } finally { if (log.isTraceEnabled()) { log.trace(this.messageSourceAccessor.getMessage(TRACE_METHOD_END, new Object[] { methodName, (returnVal != null ? returnVal.toString() : "null") }, Locale.getDefault())); } } }