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

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

Introduction

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

Prototype

public static AnnotationAttributes getAnnotationAttributes(Annotation annotation, boolean classValuesAsString,
        boolean nestedAnnotationsAsMap) 

Source Link

Document

Retrieve the given annotation's attributes as an AnnotationAttributes map.

Usage

From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java

private void registerDefaultValues(Class<?> annotationClass) {
    // Check declared default values of attributes in the annotation type.
    Method[] annotationAttributes = annotationClass.getMethods();
    for (Method annotationAttribute : annotationAttributes) {
        String attributeName = annotationAttribute.getName();
        Object defaultValue = annotationAttribute.getDefaultValue();
        if (defaultValue != null && !this.attributes.containsKey(attributeName)) {
            if (defaultValue instanceof Annotation) {
                defaultValue = AnnotationAttributes.fromMap(
                        AnnotationUtils.getAnnotationAttributes((Annotation) defaultValue, false, true));
            } else if (defaultValue instanceof Annotation[]) {
                Annotation[] realAnnotations = (Annotation[]) defaultValue;
                AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
                for (int i = 0; i < realAnnotations.length; i++) {
                    mappedAnnotations[i] = AnnotationAttributes
                            .fromMap(AnnotationUtils.getAnnotationAttributes(realAnnotations[i], false, true));
                }// ww  w  .  ja va  2s  . c  o  m
                defaultValue = mappedAnnotations;
            }
            this.attributes.put(attributeName, defaultValue);
        }
    }
}

From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java

private void registerMetaAnnotations(Class<?> annotationClass) {
    // Register annotations that the annotation type is annotated with.
    Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
    for (Annotation metaAnnotation : annotationClass.getAnnotations()) {
        metaAnnotationTypeNames.add(metaAnnotation.annotationType().getName());
        if (!this.attributesMap.containsKey(metaAnnotation.annotationType().getName())) {
            this.attributesMap.put(metaAnnotation.annotationType().getName(),
                    AnnotationUtils.getAnnotationAttributes(metaAnnotation, true, true));
        }/*from   w  w  w  .j  a  va 2s .co m*/
        for (Annotation metaMetaAnnotation : metaAnnotation.annotationType().getAnnotations()) {
            metaAnnotationTypeNames.add(metaMetaAnnotation.annotationType().getName());
        }
    }
    if (this.metaAnnotationMap != null) {
        this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
    }
}