Example usage for org.springframework.core.annotation AnnotationUtils findAnnotation

List of usage examples for org.springframework.core.annotation AnnotationUtils findAnnotation

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotationUtils findAnnotation.

Prototype

@Nullable
public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType) 

Source Link

Document

Find a single Annotation of annotationType on the supplied Class , traversing its interfaces, annotations, and superclasses if the annotation is not directly present on the given class itself.

Usage

From source file:com.expedia.seiso.domain.meta.ItemMetaLookup.java

private void mapItemClass(Class itemClass, Class repoInterface) {
    val ann = AnnotationUtils.findAnnotation(repoInterface, RestResource.class);
    if (ann == null) {
        log.warn("No @RestResource for {}", repoInterface.getSimpleName());
    } else {//from  w ww. j  av a  2s .c  o m
        val repoKey = ann.path();
        log.info("Mapping repo key {} to item class {}", repoKey, itemClass.getName());
        itemClassesByRepoKey.put(repoKey, itemClass);
    }
}

From source file:org.xmatthew.spy2servers.config.ComponentPostProcessor.java

private void detectSpyComponent(Object bean) throws RuntimeException {
    Class<?> beanClass = this.getBeanClass(bean);
    SpyComponent spyComponentAnnotation = AnnotationUtils.findAnnotation(beanClass, SpyComponent.class);
    if (spyComponentAnnotation != null) {
        if (bean instanceof org.xmatthew.spy2servers.core.SpyComponent) {
            org.xmatthew.spy2servers.core.SpyComponent spyComponent;
            spyComponent = (org.xmatthew.spy2servers.core.SpyComponent) bean;

            String name = spyComponentAnnotation.name();
            if (StringUtils.isNotBlank(name)) {
                spyComponent.setName(name);
            }//from  w  w  w . jav  a 2  s  .  c o  m
        } else {
            throw new RuntimeException("@SpyComponent mark class must implement "
                    + "org.xmatthew.spy2servers.core.SpyComponent interface");
        }
    }
}

From source file:com.coinblesk.server.utils.ApiVersionRequestMappingHandlerMapping.java

@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
    RequestMappingInfo info = super.getMappingForMethod(method, handlerType);

    // no request mapping for this method
    if (info == null) {
        return null;
    }//from  w ww .j  a v a  2  s .c  o  m

    ApiVersion methodAnnotation = AnnotationUtils.findAnnotation(method, ApiVersion.class);
    if (methodAnnotation != null) {
        RequestCondition<?> methodCondition = getCustomMethodCondition(method);
        // Concatenate our ApiVersion with the usual request mapping
        info = createApiVersionInfo(methodAnnotation, methodCondition).combine(info);
    } else {
        ApiVersion typeAnnotation = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class);
        if (typeAnnotation != null) {
            RequestCondition<?> typeCondition = getCustomTypeCondition(handlerType);
            // Concatenate our ApiVersion with the usual request mapping
            info = createApiVersionInfo(typeAnnotation, typeCondition).combine(info);
        }
    }

    return info;
}

From source file:br.com.mv.modulo.web.ExceptionController.java

@ExceptionHandler(Exception.class)
@RequestMapping("/exception")
public ModelAndView handleException(HttpServletRequest req, Exception e) throws Exception {
    log.trace("Exceo capturada:", e);
    e.printStackTrace();//from  w  ww.  java  2  s.c  o  m
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;
    }

    ModelAndView mav = new ModelAndView("exception");
    mav.addObject("exception", e);
    exception = e;

    mav.addObject("timestamp", new Date());
    mav.addObject("url", req.getRequestURL());
    mav.addObject("status", 500);
    return mav;
}

From source file:org.arrow.runtime.execution.listener.BpmnNodeListenerComparator.java

/**
 * Indicates if the given {@link ExecutionListener} is a infrastructure
 * execution listener./* ww  w .  j  a va 2 s  .c o  m*/
 * 
 * @param listener the execution listener instance
 * @return boolean
 */
private boolean isInfrastructureListener(Object listener) {
    Class<?> cls = listener.getClass();
    return AnnotationUtils.findAnnotation(cls, Infrastructure.class) != null;
}

From source file:springfox.documentation.schema.property.bean.Accessors.java

private static Optional<JsonGetter> getterAnnotation(Method method) {
    return Optional.fromNullable(AnnotationUtils.findAnnotation(method, JsonGetter.class));
}

From source file:de.otto.mongodb.profiler.web.CacheInterceptor.java

protected boolean noCache(HandlerMethod handler) {

    return handler.getMethodAnnotation(NoCache.class) != null
            || AnnotationUtils.findAnnotation(handler.getBeanType(), NoCache.class) != null;
}

From source file:it.cosenonjaviste.alfresco.annotations.processors.runtime.ChildOfConfigurer.java

@Override
protected void processBeanDefinition(ConfigurableListableBeanFactory beanFactory, BeanDefinition bd,
        String beanClassName, String definitionName) throws FatalBeanException {
    try {/* ww w  .  j  av  a  2 s .c om*/
        final ChildOf childOf = AnnotationUtils.findAnnotation(Class.forName(beanClassName), ChildOf.class);
        if (childOf != null) {
            final String parentName = childOf.value();
            if (StringUtils.hasText(parentName)) {
                bd.setParentName(parentName);
            } else {
                throw new FatalBeanException(
                        String.format("%s is @ChildOf annotated, but no value set.", beanClassName));
            }
        }
    } catch (ClassNotFoundException e) {
        logger.warn(String.format(
                "ClassNotFoundException while searching for ChildOf annotation on bean name '%s' of type '%s'. This error is expected on Alfresco Community 4.2.c. for some classes in package 'org.alfresco.repo'",
                definitionName, beanClassName));
    }
}

From source file:springfox.documentation.swagger.readers.operation.OperationImplicitParametersReader.java

protected List<Parameter> readParameters(OperationContext context) {
    HandlerMethod handlerMethod = context.getHandlerMethod();
    Method method = handlerMethod.getMethod();
    ApiImplicitParams annotation = AnnotationUtils.findAnnotation(method, ApiImplicitParams.class);

    List<Parameter> parameters = Lists.newArrayList();
    if (null != annotation) {
        for (ApiImplicitParam param : annotation.value()) {
            parameters.add(OperationImplicitParameterReader.implicitParameter(param));
        }/*from  ww  w. j a  v a 2 s.  co m*/
    }

    return parameters;
}

From source file:ch.ralscha.extdirectspring.util.MethodInfoCache.java

/**
 * Put a method into the MethodCache./*from   w ww .  j  av a  2  s. c  om*/
 * 
 * @param beanName the name of the bean
 * @param clazz the class of the bean
 * @param method the method
 * @param context the Spring application context
 */
public void put(String beanName, Class<?> clazz, Method method, ApplicationContext context) {
    MethodInfo info = new MethodInfo(clazz, context, beanName, method);

    // START: add by chiknin
    String group = info.getGroup();
    String clrValue = null;
    Controller contAnn = AnnotationUtils.findAnnotation(clazz, Controller.class);
    if (contAnn != null) {
        clrValue = contAnn.value();
    } else {
        Component compAnn = AnnotationUtils.findAnnotation(clazz, Component.class);
        clrValue = compAnn.value();
    }
    if (StringUtil.isBlank(clrValue)) {
        clrValue = StringUtil.uncapitalize(clazz.getSimpleName());
    }

    if (StringUtil.isNotBlank(group)) {
        if (ArrayUtils.indexOf(group.split(","), clrValue) == -1) {
            group = clrValue + "," + group;
        }
    } else {
        group = clrValue;
    }

    ReflectUtil.setFieldValue(info, "group", group);

    cache.put(new Key(beanName, method.getName()), info);
}