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:com.ecsteam.subservices.SubserviceDiscoveryManager.java
public Iterable<Link> getLinks() { Map<String, Object> beans = applicationContext.getBeansWithAnnotation(Controller.class); List<Link> links = new LinkedList<Link>(); for (Map.Entry<String, Object> entry : beans.entrySet()) { String beanName = entry.getKey(); Object bean = entry.getValue(); Class<?> beanClass = bean.getClass(); if (AnnotationUtils.findAnnotation(beanClass, DiscoverableSubservice.class) != null) { links.add(linkTo(bean.getClass()).withRel(beanName)); }//from ww w. ja va 2 s . co m } return links; }
From source file:com.iflytek.edu.cloud.frame.spring.rest.ServiceMethodHandlerMapping.java
@Override protected ServiceMethodInfo getMappingForMethod(Method method, Class<?> handlerType) { ServiceMethodInfo info = null;/*from ww w .j av a 2 s .c o m*/ ServiceMethod methodAnnotation = AnnotationUtils.findAnnotation(method, ServiceMethod.class); if (methodAnnotation != null) { info = createServiceMethodInfo(methodAnnotation); ServiceMethod typeAnnotation = AnnotationUtils.findAnnotation(handlerType, ServiceMethod.class); if (typeAnnotation != null) { info = createServiceMethodInfo(typeAnnotation).combine(info); } } return info; }
From source file:org.ldaptive.beans.spring.SpringClassDescriptor.java
/** {@inheritDoc} */ @Override//ww w . j av a2 s .com public void initialize(final Class<?> type) { // check for entry annotation final Entry entryAnnotation = AnnotationUtils.findAnnotation(type, Entry.class); if (entryAnnotation != null) { if (!entryAnnotation.dn().equals("")) { setDnValueMutator(new DnValueMutator() { @Override public String getValue(final Object object) { final ExpressionParser parser = new SpelExpressionParser(); final Expression exp = parser.parseExpression(entryAnnotation.dn()); return exp.getValue(context, object, String.class); } @Override public void setValue(final Object object, final String value) { } }); } for (final Attribute attr : entryAnnotation.attributes()) { final String expr = attr.property(); final ExpressionParser parser = new SpelExpressionParser(); final Expression exp = parser.parseExpression(expr); addAttributeValueMutator(new AttributeValueMutator() { @Override public String getName() { return attr.name(); } @Override public boolean isBinary() { return attr.binary(); } @Override public SortBehavior getSortBehavior() { return attr.sortBehavior(); } @Override public Collection<String> getStringValues(final Object object) { @SuppressWarnings("unchecked") final Collection<String> values = (Collection<String>) exp.getValue(context, object, Collection.class); return values; } @Override public Collection<byte[]> getBinaryValues(final Object object) { @SuppressWarnings("unchecked") final Collection<byte[]> values = (Collection<byte[]>) exp.getValue(context, object, Collection.class); return values; } @Override public void setStringValues(final Object object, final Collection<String> values) { exp.setValue(context, object, values); } @Override public void setBinaryValues(final Object object, final Collection<byte[]> values) { exp.setValue(context, object, values); } }); } } }
From source file:com.xemantic.tadedon.guice.matcher.TypeLiteralMethodAnnotationTypeMatcher.java
/** {@inheritDoc} */ @Override// w w w. j av a2s . c om public boolean matches(TypeLiteral<?> element) { Method[] methods = element.getRawType().getMethods(); boolean matches = false; for (Method method : methods) { Annotation annotation = AnnotationUtils.findAnnotation(method, m_annotationType); if (annotation != null) { matches = true; break; } } return matches; }
From source file:springfox.documentation.swagger.schema.ApiModelBuilder.java
@Override public void apply(ModelContext context) { ApiModel annotation = AnnotationUtils.findAnnotation(forClass(context), ApiModel.class); if (annotation != null) { context.getBuilder().description(annotation.description()); }/*from w ww . ja v a2s . c o m*/ }
From source file:com.cloudera.csd.validation.references.components.ReflectionHelper.java
/** * Finds the annotation of the provided method by searching * the entire method hierarchy.// ww w .j a v a 2 s .c om * * @param method the method. * @param annotationType the annotation class. * @param <A> the annotation type. * @return the annotation if it is found. Null otherwise. */ @Nullable public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) { return AnnotationUtils.findAnnotation(method, annotationType); }
From source file:cn.guoyukun.spring.jpa.repository.RepositoryHelper.java
/** * @param entityClass ??// ww w .j a v a 2 s. co m */ public RepositoryHelper(Class<?> entityClass) { this.entityClass = entityClass; EnableQueryCache enableQueryCacheAnnotation = AnnotationUtils.findAnnotation(entityClass, EnableQueryCache.class); boolean enableQueryCache = false; if (enableQueryCacheAnnotation != null) { enableQueryCache = enableQueryCacheAnnotation.value(); } this.enableQueryCache = enableQueryCache; }
From source file:com.zb.app.common.component.ComponentController.java
@ExceptionHandler(Throwable.class) public ModelAndView handleIOException(Throwable e) throws Throwable { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e;//w ww . ja v a 2s. c o m } if (request == null && response == null) { throw e; } if (request == null && response != null) { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8")); pw.println("{\"code\":1,\"msg\":\",?!\",\"data\":\"\"}"); pw.flush(); pw.close(); } ModelAndView mav = new ModelAndView(); if (InvokeTypeTools.isAjax(request)) { return createJsonMav("server exceptin or error", ResultCode.ERROR, e.getMessage()); } mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString()); mav.addObject("msg", StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage()); mav.addObject("stackTrace", e.getStackTrace().toString()); if (request.getRequestURI() != null) { mav.addObject("url", request.getRequestURI().toString()); } mav.setViewName("error"); return mav; }
From source file:org.trustedanalytics.utils.errorhandling.RestErrorHandler.java
@ExceptionHandler(Exception.class) public void handleException(Exception e, HttpServletResponse response) throws Exception { // Generate error reference id (to be used both in logs and in error sent from the service) long errorId = ErrorIdGenerator.getNewId(); // If the exception is annotated with @ResponseStatus rethrow it and let // the framework handle it - like the OrderNotFoundException example // at the start of this post. // AnnotationUtils is a Spring Framework utility class. ResponseStatus responseStatus = AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class); if (responseStatus != null) { ErrorLogger.logError("Controller error, reference id: " + errorId, e); response.sendError(responseStatus.value().value(), ErrorFormatter.formatErrorMessage(responseStatus.reason(), errorId)); return;/*from w w w .ja v a 2s .c o m*/ } HttpStatus errorStatus = HttpStatus.INTERNAL_SERVER_ERROR; ErrorLogger.logError("Unhandled controller error, reference id: " + errorId, e); response.sendError(errorStatus.value(), ErrorFormatter.formatErrorMessage(errorStatus, errorId)); }
From source file:springfox.documentation.schema.Enums.java
private static Optional<Method> findJsonValueAnnotatedMethod(Object enumConstant) { for (Method each : enumConstant.getClass().getMethods()) { JsonValue jsonValue = AnnotationUtils.findAnnotation(each, JsonValue.class); if (jsonValue != null && jsonValue.value()) { return Optional.of(each); }//from w w w . j av a2 s.co m } return Optional.absent(); }