List of usage examples for java.lang.reflect Method getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:net.nelz.simplesm.aop.UpdateMultiCacheAdvice.java
@AfterReturning(pointcut = "updateMulti()", returning = "retVal") public Object cacheUpdateSingle(final JoinPoint jp, final Object retVal) throws Throwable { // For Update*Cache, an AfterReturning aspect is fine. We will only apply our caching // after the underlying method completes successfully, and we will have the same // access to the method params. try {//from www. j a v a 2 s . c o m final Method methodToCache = getMethodToCache(jp); final UpdateMultiCache annotation = methodToCache.getAnnotation(UpdateMultiCache.class); final AnnotationData annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, UpdateMultiCache.class, methodToCache); final List<Object> dataList = annotationData.getDataIndex() == -1 ? (List<Object>) retVal : (List<Object>) getIndexObject(annotationData.getDataIndex(), jp, methodToCache); final List<Object> keyObjects = getKeyObjects(annotationData.getKeyIndex(), retVal, jp, methodToCache); final List<String> cacheKeys = getCacheKeys(keyObjects, annotationData); updateCache(cacheKeys, dataList, methodToCache, annotationData); } catch (Exception ex) { LOG.warn("Updating caching via " + jp.toShortString() + " aborted due to an error.", ex); } return retVal; }
From source file:com.ephesoft.dcma.workflows.aspects.DCMAPostProcessAspect.java
/** * Find and execute the method for this aspect. * /*from w w w . jav a 2 s . co m*/ * @param joinPoint {@link JoinPoint} * @param target {@link Object} * @param methods {@link Method}[] * @throws IllegalAccessException * @throws InvocationTargetException */ private void findAspectMethodsToExecute(final JoinPoint joinPoint, final Object target, final Method[] methods) throws IllegalAccessException, InvocationTargetException { for (int methodIndex = 0; methodIndex < methods.length; methodIndex++) { Method method = methods[methodIndex]; Annotation annotation = method.getAnnotation(PostProcess.class); if (null != annotation && joinPoint.getArgs().length >= 1) { Object aJoinPoint = joinPoint.getArgs()[0]; if (aJoinPoint instanceof BatchInstanceID) { method.invoke(target, aJoinPoint, joinPoint.getArgs()[1]); } else { LOGGER.info("Method ", method, " does not comply to Post-process agreement, thus method not invoked."); } } } }
From source file:com.ephesoft.dcma.workflows.aspects.DCMAPreProcessAspect.java
/** * Find and execute the method for this aspect. * /*from ww w.j a v a 2s.co m*/ * @param joinPoint {@link JoinPoint} * @param target {@link Object} * @param methods {@link Method}[] * @throws IllegalAccessException * @throws InvocationTargetException */ private void findAspectMethodsToExecute(final JoinPoint joinPoint, final Object target, final Method[] methods) throws IllegalAccessException, InvocationTargetException { for (int methodIndex = 0; methodIndex < methods.length; methodIndex++) { Method method = methods[methodIndex]; Annotation annotation = method.getAnnotation(PreProcess.class); if (null != annotation && joinPoint.getArgs().length >= 1) { Object aJoinPoint = joinPoint.getArgs()[0]; if (aJoinPoint instanceof BatchInstanceID) { method.invoke(target, aJoinPoint, joinPoint.getArgs()[1]); } else { LOGGER.info("Method ", method, " does not comply to Pre-process agreement, thus method not invoked."); } } } }
From source file:com.github.lightdocs.processor.DocumentedByAnnotationProcessor.java
@Subscribe public void handle(OperationAddedEvent e) { Method method = e.getMethod(); Operation operation = e.getOperation(); DocumentedBy ann = method.getAnnotation(DocumentedBy.class); if (ann != null) { runDocumentationScriptInAnnotation(operation, ann); }/* w w w. j a v a 2 s. com*/ }
From source file:org.manalith.ircbot.plugin.PluginManager.java
private void extractEventDelegates(Plugin plugin) { Method[] methods = plugin.getClass().getDeclaredMethods(); for (Method method : methods) { BotCommand command = method.getAnnotation(BotCommand.class); if (command != null) { commands.put(new Command(method, plugin), plugin); continue; }/*www . j ava2 s . c om*/ BotFilter filter = method.getAnnotation(BotFilter.class); if (filter != null) { filters.put(method, plugin); continue; } BotTimer timer = method.getAnnotation(BotTimer.class); if (timer != null) { timers.put(method, plugin); continue; } } }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java
@Override public Set<String> getIndexRangeKeyPropertyNames() { final Set<String> propertyNames = new HashSet<String>(); ReflectionUtils.doWithMethods(getJavaType(), new MethodCallback() { public void doWith(Method method) { if (method.getAnnotation(DynamoDBIndexRangeKey.class) != null) { if ((method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim() .length() > 0) || (method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && method.getAnnotation(DynamoDBIndexRangeKey.class) .localSecondaryIndexNames().length > 0)) { propertyNames.add(getPropertyNameForAccessorMethod(method)); }/* w w w. j ava 2s. c om*/ } } }); ReflectionUtils.doWithFields(getJavaType(), new FieldCallback() { public void doWith(Field field) { if (field.getAnnotation(DynamoDBIndexRangeKey.class) != null) { if ((field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim() .length() > 0) || (field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && field.getAnnotation(DynamoDBIndexRangeKey.class) .localSecondaryIndexNames().length > 0)) { propertyNames.add(getPropertyNameForField(field)); } } } }); return propertyNames; }
From source file:com.ryantenney.metrics.spring.ExceptionMeteredMethodInterceptor.java
@Override public void doWith(Method method) throws IllegalAccessException { final ExceptionMetered annotation = method.getAnnotation(ExceptionMetered.class); final String metricName = Util.forExceptionMeteredMethod(targetClass, method, annotation); final MethodKey methodKey = MethodKey.forMethod(method); final Meter meter = metrics.meter(metricName); meters.put(methodKey, new ExceptionMeter(meter, annotation.cause())); LOG.debug("Created Meter {} for method {}", metricName, methodKey); }
From source file:nl.edia.xapi.proxy.StatementGeneratorMethodInterceptor.java
/** * Runs the {@link StatementGenerator} enhancement. * @param invocation/* w w w. ja v a 2 s . c o m*/ * @param returnValue * @throws IllegalAccessException * @throws InvocationTargetException */ protected void doAnalysis(MethodInvocation invocation, Object returnValue) throws IllegalAccessException, InvocationTargetException { // Get the called method Method method = invocation.getMethod(); StatementGenerator annotation = method.getAnnotation(StatementGenerator.class); if (annotation != null) { nl.edia.xapi.statements.StatementGenerator bean = getStatementGenerator(annotation); if (bean == null) { LOG.error("Unable to locate StatementGenerator bean, @StatementGenerator annotation ignored."); } else { String verb = annotation.verb(); Map<Class<?>, Object> values = AopReflectionUtils.getParameterClassesAndValues(invocation, returnValue); gov.adlnet.xapi.model.Statement statement = bean.generate(verb, returnValue, values); StatementClient statementClient = statementClientFactory.build(invocation, returnValue); if (statement != null && statementClient != null) { send(statementClient, statement); } } } }
From source file:org.vaadin.spring.boot.config.AbstractServletConfiguration.java
private void addInitParameters(ServletRegistrationBean servletRegistrationBean) { getLogger().info("Looking for servlet init parameters"); int count = 0; final Method[] methods = VaadinServletConfiguration.class.getDeclaredMethods(); for (Method method : methods) { VaadinServletConfiguration.InitParameterName name = method .getAnnotation(VaadinServletConfiguration.InitParameterName.class); String propertyValue = environment.getProperty(getServletConfigurationParameterPrefix() + name.value()); if (propertyValue != null) { getLogger().info("Found servlet init parameter [{}] = [{}]", name.value(), propertyValue); servletRegistrationBean.addInitParameter(name.value(), propertyValue); count++;//from ww w . j a va 2s . c o m } } if (count == 0) { getLogger().info("Found no servlet init parameters"); } }
From source file:pl.com.bottega.ecommerce.system.saga.impl.SimpleSagaEngine.java
private Method findHandlerMethodForEvent(Class<?> type, Object event) { for (Method method : type.getMethods()) { if (method.getAnnotation(SagaAction.class) != null || method.getAnnotation(LoadSaga.class) != null) { if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(event.getClass())) { return method; }/*from w w w .ja v a 2 s . c om*/ } } throw new RuntimeException("no method handling " + event.getClass()); }