List of usage examples for java.lang.reflect Method getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:io.opencensus.contrib.spring.aop.CensusSpringAspect.java
/** * trace handles methods executed with the `@Traced` annotation. A new span will be created with * an optionally customizable span name. * * @param call the join point to execute * @return the result of the invocation//from w ww .j a v a 2s. com * @throws Throwable if the underlying target throws an exception * @since 0.16.0 */ @Around("@annotation(io.opencensus.contrib.spring.aop.Traced)") public Object trace(ProceedingJoinPoint call) throws Throwable { MethodSignature signature = (MethodSignature) call.getSignature(); Method method = signature.getMethod(); Traced annotation = method.getAnnotation(Traced.class); if (annotation == null) { return call.proceed(); } String spanName = annotation.name(); if (spanName.isEmpty()) { spanName = method.getName(); } return Handler.proceed(call, tracer, spanName); }
From source file:org.callimachusproject.rewrite.MissingAdvice.java
private String[] getMediaType(Method method) { if (method.isAnnotationPresent(type.class)) return method.getAnnotation(type.class).value(); return new String[0]; }
From source file:org.fishwife.jrugged.spring.AnnotatedMethodScanner.java
Set<Method> extractAnnotatedMethods(Set<BeanDefinition> filteredComponents, Class<? extends Annotation> annoClass) { Set<Method> annotatedMethods = new HashSet<Method>(); for (BeanDefinition bd : filteredComponents) { try {/*w w w.j a va 2s .c o m*/ String className = bd.getBeanClassName(); Class<?> beanClass = classLoader.loadClass(className); for (Method m : beanClass.getMethods()) { if (m.getAnnotation(annoClass) != null) { annotatedMethods.add(m); } } } catch (ClassNotFoundException cnfe) { // no-op } } return annotatedMethods; }
From source file:pl.com.bottega.ecommerce.system.saga.impl.SpringSagaRegistry.java
private void registerSagaLoader(Class<?> loaderClass, String beanName) { for (Method method : loaderClass.getMethods()) { if (method.getAnnotation(SagaAction.class) != null || method.getAnnotation(LoadSaga.class) != null) { Class<?>[] params = method.getParameterTypes(); if (params.length == 1) { loadersInterestedIn.put(params[0], beanName); } else { throw new RuntimeException("incorred event hadndler: " + method); }//from w ww .jav a2 s. c o m } } }
From source file:com.ryantenney.metrics.spring.MeteredMethodInterceptor.java
@Override public void doWith(Method method) throws IllegalAccessException { final Metered annotation = method.getAnnotation(Metered.class); final String metricName = Util.forMeteredMethod(targetClass, method, annotation); final MethodKey methodKey = MethodKey.forMethod(method); final Meter meter = metrics.meter(metricName); meters.put(methodKey, meter);//from ww w.j a v a 2s. c om LOG.debug("Created Meter {} for method {}", metricName, methodKey); }
From source file:com.heliumv.annotation.HvCallrateAspect.java
@Before("anyPublicOperation() && inHeliumv() && processHvCallTracerPointcut()") public void processAttribute(JoinPoint pjp) throws Throwable { MethodSignature methodSig = getMethodSignatureFrom(pjp); Method method = getMethodFrom(pjp); HvCallrate theModul = (HvCallrate) method.getAnnotation(HvCallrate.class); if (theModul == null) return;//ww w. jav a2 s . c om log.debug("'" + theModul.maxCalls() + "' maxCalls and '" + theModul.durationMs() + "' duration<"); callTracer.trace(theModul, methodSig.getMethod()); }
From source file:com.mmj.app.common.interceptor.TokenAnnotationInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; Method method = handlerMethod.getMethod(); Token annotation = method.getAnnotation(Token.class); if (annotation != null) { boolean needSaveSession = annotation.save(); if (needSaveSession) { // request.getSession(false).setAttribute("token", UUIDUtils.createUUID()); request.getSession().setAttribute(TOKEN, UUIDGenerator.createUUID()); }// w w w . j a v a2s . c o m boolean needRemoveSession = annotation.remove(); if (needRemoveSession) { if (isRepeatSubmit(request)) { return false; } // request.getSession(false).removeAttribute("token"); request.getSession().removeAttribute(TOKEN); } } return true; } else { return super.preHandle(request, response, handler); } }
From source file:com.ryantenney.metrics.spring.TimedMethodInterceptor.java
@Override public void doWith(Method method) throws IllegalAccessException { final Timed annotation = method.getAnnotation(Timed.class); final String metricName = Util.forTimedMethod(targetClass, method, annotation); final MethodKey methodKey = MethodKey.forMethod(method); final Timer timer = metrics.timer(metricName); timers.put(methodKey, timer);/* w w w .j a va 2 s. c o m*/ LOG.debug("Created Timer {} for method {}", metricName, methodKey); }
From source file:corner.transaction.services.impl.SpringTransactionAdvisor.java
/** * @see org.apache.tapestry5.hibernate.HibernateTransactionAdvisor#addTransactionCommitAdvice(org.apache.tapestry5.ioc.MethodAdviceReceiver) *//*from w w w. j ava 2 s . co m*/ @Override public void addTransactionCommitAdvice(MethodAdviceReceiver receiver) { for (Method m : receiver.getInterface().getMethods()) { if (m.getAnnotation(Transactional.class) != null) { receiver.adviseMethod(m, new SpringTransactionMethodAdvice(m)); } } }
From source file:net.nelz.simplesm.aop.UpdateAssignCacheAdvice.java
@AfterReturning(pointcut = "updateAssign()", returning = "retVal") public Object cacheUpdateAssign(final JoinPoint jp, final Object retVal) throws Throwable { // This is injected caching. If anything goes wrong in the caching, LOG the crap outta it, // but do not let it surface up past the AOP injection itself. try {// ww w .j ava2 s .co m final Method methodToCache = getMethodToCache(jp); final UpdateAssignCache annotation = methodToCache.getAnnotation(UpdateAssignCache.class); final AnnotationData annotationData = AnnotationDataBuilder.buildAnnotationData(annotation, UpdateAssignCache.class, methodToCache); final String cacheKey = buildCacheKey(annotationData.getAssignedKey(), annotationData); final Object dataObject = annotationData.getDataIndex() == -1 ? retVal : getIndexObject(annotationData.getDataIndex(), jp, methodToCache); final Object submission = (dataObject == null) ? new PertinentNegativeNull() : dataObject; cache.set(cacheKey, annotationData.getExpiration(), submission); } catch (Exception ex) { LOG.warn("Updating caching via " + jp.toShortString() + " aborted due to an error.", ex); } return retVal; }