List of usage examples for org.springframework.core.annotation AnnotationUtils findAnnotation
@Nullable public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType)
From source file:py.una.pol.karaku.test.util.TestUtils.java
private static Set<Class<?>> getReferencedClasses(Class<?> base, final Set<Class<?>> elements) { ReflectionUtils.doWithFields(base, new FieldCallback() { @Override//from www. j ava 2s . c o m public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { if (elements.add(getType(field))) { getReferencedClasses(getType(field), elements); } } }, new FieldFilter() { @Override public boolean matches(Field field) { return AnnotationUtils.findAnnotation(getType(field), Entity.class) != null; } }); return elements; }
From source file:com.conversantmedia.mapreduce.tool.RunJob.java
@SuppressWarnings("unchecked") protected static Map<String, DriverMeta> findAllDrivers(Reflections reflections) { Map<String, DriverMeta> idMap = new TreeMap<>(new Comparator<String>() { @Override//from w w w . j a v a 2 s . c o m public int compare(String s1, String s2) { return s1.compareTo(s2); } }); for (Class<?> c : reflections.getTypesAnnotatedWith(Driver.class)) { Driver d = AnnotationUtils.findAnnotation(c, Driver.class); String version = versionForDriverClass(c, d.version()); String driverId = d.value(); if (StringUtils.isBlank(driverId)) { driverId = MaraAnnotationUtil.INSTANCE.defaultDriverIdForClass(c); } DriverMeta meta = new DriverMeta(driverId, d.description(), version, c, d.listener()); idMap.put(driverId, meta); if (c.isAnnotationPresent(Hidden.class)) { meta.hidden = true; } } // Have to do this 2x - a second time for Tool for (Class<?> c : reflections.getTypesAnnotatedWith(Tool.class)) { Tool t = AnnotationUtils.findAnnotation(c, Tool.class); String version = versionForDriverClass(c, t.version()); String toolId = t.value(); if (StringUtils.isBlank(toolId)) { toolId = MaraAnnotationUtil.INSTANCE.defaultDriverIdForClass(c); } DriverMeta meta = new DriverMeta(toolId, t.description(), version, c, t.listener()); idMap.put(toolId, meta); if (c.isAnnotationPresent(Hidden.class)) { meta.hidden = true; } } return idMap; }
From source file:com.thorpora.module.core.error.ErrorLogger.java
private Level resolveLogLevel(Throwable ex) { ExceptionLog logAnnot = AnnotationUtils.findAnnotation(ex.getClass(), ExceptionLog.class); if (logAnnot != null) { return logAnnot.level(); }//w w w . j a v a 2 s. co m Level logLevel = levelMapping.get(ex.getClass()); if (logLevel != null) { return logLevel; } return DEFAULT_EXCEPTION_LEVEL; }
From source file:tv.arte.resteventapi.web.errors.GlobalDefaultExceptionHandler.java
/** * Handle all exceptions of type {@link ImageRepositoryException} thrown by (or passing trough) the Controller's layer * /*from w w w . ja va 2 s . com*/ * @param response The HttpServletResponse * @param e Thrown RestEventApiValidationException * @return * @throws Exception */ @SuppressWarnings("unchecked") @ExceptionHandler(value = RestEventApiValidationException.class) public ModelAndView restEventApiValidationExceptionHandler(HttpServletResponse response, RestEventApiValidationException e) throws Exception { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e; } RestEventApiStandardResponse<RestEventApiMessage> restEventApiStandardResponse = new RestEventApiStandardResponse<RestEventApiMessage>(); restEventApiStandardResponse .setErrors((Collection<RestEventApiMessage>) (Collection<?>) e.getValidationErrorMessages()); ModelAndView mav = new ModelAndView(); mav.addObject(restEventApiStandardResponse); mav.setView(restEventApiDefaultErrorView); if (e.getResponseHttpStatusCode() != null) { response.setStatus(e.getResponseHttpStatusCode()); } else { response.setStatus(HttpStatus.BAD_REQUEST.value()); } return mav; }
From source file:org.jnap.core.mvc.async.AsyncRequestInterceptor.java
/** * /*from ww w . jav a 2 s .com*/ * @param request * @param handler * @return */ protected boolean isAsync(HttpServletRequest request, Object handler) { RestController controllerAnnotation = AnnotationUtils.findAnnotation(handler.getClass(), RestController.class); return (controllerAnnotation != null && controllerAnnotation.async()) || request.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT) != null || request.getHeader("Sec-WebSocket-Version") != null; }
From source file:com.logsniffer.config.BeanConfigFactoryManager.java
@SuppressWarnings({ "unchecked", "rawtypes" }) protected <BeanType> void postConstruct(final ConfiguredBean bean) { if (bean == null) { return;/*from w ww . j a v a 2s .c o m*/ } final PostConstructed pc = AnnotationUtils.findAnnotation(bean.getClass(), PostConstructed.class); if (bean instanceof BeanPostConstructor<?> && (pc == null || !mappedPostConstrucors.containsKey(bean.getClass()))) { ((BeanPostConstructor) bean).postConstruct(bean, this); } if (pc != null) { final BeanPostConstructor bpc = mappedPostConstrucors.get(pc.constructor()); if (bpc != null) { bpc.postConstruct(bean, this); } else { logger.error("Unsatisfied bean construction of '{}' due to missing post constructor of type: {}", bean, pc.getClass()); } } configInjector.postProcessBeforeInitialization(bean, bean.getClass().getName()); }
From source file:com.github.kongchen.swagger.docgen.mavenplugin.ApiSource.java
private void setBasePathFromAnnotation() { for (Class<?> aClass : getValidClasses(SwaggerDefinition.class)) { SwaggerDefinition swaggerDefinition = AnnotationUtils.findAnnotation(aClass, SwaggerDefinition.class); basePath = swaggerDefinition.basePath(); }/* w ww .j a v a 2 s . c o m*/ }
From source file:com.thorpora.module.core.error.ErrorLogger.java
private boolean isStackTraceLogged(Throwable ex) { ExceptionLog logAnnot = AnnotationUtils.findAnnotation(ex.getClass(), ExceptionLog.class); if (logAnnot != null) { return logAnnot.stackTrace(); }/*w w w .j av a 2s .c o m*/ Boolean printStack = stackMapping.get(ex.getClass()); if (printStack != null) { return printStack; } return DEFAULT_STACK_TRACE_PRINTED; }
From source file:com.github.kongchen.swagger.docgen.mavenplugin.ApiSource.java
private void setHostFromAnnotation() { for (Class<?> aClass : getValidClasses(SwaggerDefinition.class)) { SwaggerDefinition swaggerDefinition = AnnotationUtils.findAnnotation(aClass, SwaggerDefinition.class); host = swaggerDefinition.host(); }// w w w. j a v a2s .com }
From source file:com.tyro.oss.pact.spring4.pact.provider.PactTestRunner.java
private PactDefinition getPactDefinition(Class<?> clazz) { PactDefinition pactDefinition = AnnotationUtils.findAnnotation(clazz, PactDefinition.class); if (pactDefinition == null) { throw new IllegalStateException("PactTest subclasses must be annotated with @PactDefinition"); }/*from w ww . j a v a 2 s.com*/ return pactDefinition; }