Example usage for org.springframework.core.annotation AnnotationAttributes AnnotationAttributes

List of usage examples for org.springframework.core.annotation AnnotationAttributes AnnotationAttributes

Introduction

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

Prototype

public AnnotationAttributes(Class<? extends Annotation> annotationType) 

Source Link

Document

Create a new, empty AnnotationAttributes instance for the specified annotationType .

Usage

From source file:org.zalando.spring.data.businesskey.config.AnnotationBusinessKeyConfiguration.java

public AnnotationBusinessKeyConfiguration(final AnnotationMetadata metadata,
        final Class<? extends Annotation> annotation) {

    Assert.notNull(metadata, "AnnotationMetadata must not be null!");
    Assert.notNull(annotation, "Annotation must not be null!");

    this.attributes = new AnnotationAttributes(metadata.getAnnotationAttributes(annotation.getName()));
}

From source file:hwolf.spring.boot.jsf.JsfConfiguration.java

private Collection<String> getBasePackages() {
    Set<String> basePackages = new LinkedHashSet<>();
    AnnotationAttributes attrs = new AnnotationAttributes(
            metaData.getAnnotationAttributes(EnableJsf.class.getName()));
    String[] basePackagesArray = attrs.getAliasedStringArray("basePackages", EnableJsf.class,
            metaData.getClassName());/*from w  w  w . j a va 2s . c o m*/
    for (String pkg : basePackagesArray) {
        String[] tokenized = StringUtils.tokenizeToStringArray(environment.resolvePlaceholders(pkg),
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        basePackages.addAll(Arrays.asList(tokenized));
    }
    for (Class<?> clazz : attrs.getClassArray("basePackageClasses")) {
        basePackages.add(ClassUtils.getPackageName(clazz));
    }
    if (basePackages.isEmpty()) {
        basePackages.add(ClassUtils.getPackageName(metaData.getClassName()));
    }
    return basePackages;
}

From source file:org.spring.guice.annotation.GuiceModuleRegistrar.java

private Set<Pattern> parsePatterns(AnnotationMetadata annotation, String attributeName) {
    Set<Pattern> result = new HashSet<Pattern>();
    AnnotationAttributes attributes = new AnnotationAttributes(
            annotation.getAnnotationAttributes(GuiceModule.class.getName()));
    String[] filters = attributes.getStringArray(attributeName);

    for (String filter : filters) {
        result.add(Pattern.compile(filter));
    }/* w  w  w. j  av  a  2 s  . c o m*/

    return result;
}

From source file:org.spring.guice.annotation.GuiceModuleRegistrar.java

private Set<String> parseNames(AnnotationMetadata annotation, String attributeName) {
    Set<String> result = new HashSet<String>();
    AnnotationAttributes attributes = new AnnotationAttributes(
            annotation.getAnnotationAttributes(GuiceModule.class.getName()));
    String[] filters = attributes.getStringArray(attributeName);

    for (String filter : filters) {
        result.add(filter);/*from  ww  w.  j a  v  a 2  s . c o  m*/
    }

    return result;
}

From source file:org.spring.guice.annotation.GuiceModuleRegistrar.java

private Set<TypeFilter> parseFilters(AnnotationMetadata annotation, String attributeName) {

    Set<TypeFilter> result = new HashSet<TypeFilter>();
    AnnotationAttributes attributes = new AnnotationAttributes(
            annotation.getAnnotationAttributes(GuiceModule.class.getName()));
    AnnotationAttributes[] filters = attributes.getAnnotationArray(attributeName);

    for (AnnotationAttributes filter : filters) {
        result.addAll(typeFiltersFor(filter));
    }/*from  www.  j a v  a 2  s  .c  o m*/

    return result;
}

From source file:org.springframework.core.annotation.AnnotationUtils.java

/**
 * Retrieve the given annotation's attributes as an {@link AnnotationAttributes} map.
 * <p>This method provides fully recursive annotation reading capabilities on par with
 * the reflection-based {@link org.springframework.core.type.StandardAnnotationMetadata}.
 * <p><strong>NOTE</strong>: This variant of {@code getAnnotationAttributes()} is
 * only intended for use within the framework. The following special rules apply:
 * <ol>/*from  w w w  .ja va  2 s  . c  o  m*/
 * <li>Default values will be replaced with default value placeholders.</li>
 * <li>The resulting, merged annotation attributes should eventually be
 * {@linkplain #postProcessAnnotationAttributes post-processed} in order to
 * ensure that placeholders have been replaced by actual default values and
 * in order to enforce {@code @AliasFor} semantics.</li>
 * </ol>
 * @param annotatedElement the element that is annotated with the supplied annotation;
 * may be {@code null} if unknown
 * @param annotation the annotation to retrieve the attributes for
 * @param classValuesAsString whether to convert Class references into Strings (for
 * compatibility with {@link org.springframework.core.type.AnnotationMetadata})
 * or to preserve them as Class references
 * @param nestedAnnotationsAsMap whether to convert nested annotations into
 * {@link AnnotationAttributes} maps (for compatibility with
 * {@link org.springframework.core.type.AnnotationMetadata}) or to preserve them as
 * {@code Annotation} instances
 * @return the annotation attributes (a specialized Map) with attribute names as keys
 * and corresponding attribute values as values (never {@code null})
 * @since 4.2
 * @see #postProcessAnnotationAttributes
 */
static AnnotationAttributes retrieveAnnotationAttributes(@Nullable Object annotatedElement,
        Annotation annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) {

    Class<? extends Annotation> annotationType = annotation.annotationType();
    AnnotationAttributes attributes = new AnnotationAttributes(annotationType);

    for (Method method : getAttributeMethods(annotationType)) {
        try {
            Object attributeValue = method.invoke(annotation);
            Object defaultValue = method.getDefaultValue();
            if (defaultValue != null && ObjectUtils.nullSafeEquals(attributeValue, defaultValue)) {
                attributeValue = new DefaultValueHolder(defaultValue);
            }
            attributes.put(method.getName(),
                    adaptValue(annotatedElement, attributeValue, classValuesAsString, nestedAnnotationsAsMap));
        } catch (Throwable ex) {
            if (ex instanceof InvocationTargetException) {
                Throwable targetException = ((InvocationTargetException) ex).getTargetException();
                rethrowAnnotationConfigurationException(targetException);
            }
            throw new IllegalStateException("Could not obtain annotation attribute value for " + method, ex);
        }
    }

    return attributes;
}