Example usage for org.springframework.core.type AnnotationMetadata getMetaAnnotationTypes

List of usage examples for org.springframework.core.type AnnotationMetadata getMetaAnnotationTypes

Introduction

In this page you can find the example usage for org.springframework.core.type AnnotationMetadata getMetaAnnotationTypes.

Prototype

default Set<String> getMetaAnnotationTypes(String annotationName) 

Source Link

Document

Get the fully qualified class names of all meta-annotation types that are present on the given annotation type on the underlying class.

Usage

From source file:org.talend.daikon.spring.BndToSpringBeanNameGenerator.java

/**
 * Derive a bean name from one of the annotations on the class. First delegate to the super class and if it is not a
 * spring annotation then check for the bnd annotation
 * /*from w ww  .  j  a  v a 2 s .  c o  m*/
 * @param annotatedDef the annotation-aware bean definition
 * @return the bean name, or {@code null} if none is found
 */
@Override
protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
    String beanName = super.determineBeanNameFromAnnotation(annotatedDef);
    if (beanName != null) {
        return beanName;
    } // else check for BND annotation
    AnnotationMetadata amd = annotatedDef.getMetadata();
    Set<String> types = amd.getAnnotationTypes();
    for (String type : types) {
        AnnotationAttributes attributes = AnnotationAttributes
                .fromMap(amd.getAnnotationAttributes(type, false));
        if (isStereotypeWithBndNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
            Object value = attributes.get("name");
            if (value instanceof String) {
                String strVal = (String) value;
                if (StringUtils.hasLength(strVal)) {
                    if (beanName != null && !strVal.equals(beanName)) {
                        throw new IllegalStateException("Stereotype annotations suggest inconsistent "
                                + "component names: '" + beanName + "' versus '" + strVal + "'");
                    }
                    beanName = strVal;
                }
            }
        }
    }
    return beanName;
}

From source file:org.springframework.integration.config.MessagingGatewayRegistrar.java

/**
 * TODO until SPR-11710 will be resolved.
 * Captures the meta-annotation attribute values, in order.
 * @param importingClassMetadata The importing class metadata
 * @return The captured values.//  w  w w  .  jav a 2 s .  c  om
 */
private List<MultiValueMap<String, Object>> captureMetaAnnotationValues(
        AnnotationMetadata importingClassMetadata) {
    Set<String> directAnnotations = importingClassMetadata.getAnnotationTypes();
    List<MultiValueMap<String, Object>> valuesHierarchy = new ArrayList<MultiValueMap<String, Object>>();
    // Need to grab the values now; see SPR-11710
    for (String ann : directAnnotations) {
        Set<String> chain = importingClassMetadata.getMetaAnnotationTypes(ann);
        if (chain.contains(MessagingGateway.class.getName())) {
            for (String meta : chain) {
                valuesHierarchy.add(importingClassMetadata.getAllAnnotationAttributes(meta));
            }
        }
    }
    return valuesHierarchy;
}