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

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

Introduction

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

Prototype

String VALUE

To view the source code for org.springframework.core.annotation AnnotationUtils VALUE.

Click Source Link

Document

The attribute name for annotations with a single element.

Usage

From source file:com.github.yulechen.springannotation.test.ConfigurationClassUtils.java

/**
 * Check whether the given bean definition is a candidate for a
 * configuration class (or a nested component class declared within a
 * configuration/component class, to be auto-registered as well), and mark
 * it accordingly.//from w  ww  .  ja  v  a 2  s  . co m
 * 
 * @param beanDef
 *            the bean definition to check
 * @param metadataReaderFactory
 *            the current factory in use by the caller
 * @return whether the candidate qualifies as (any kind of) configuration
 *         class
 */
public static boolean checkConfigurationClassCandidate(BeanDefinition beanDef,
        MetadataReaderFactory metadataReaderFactory) {
    String className = beanDef.getBeanClassName();
    if (className == null) {
        return false;
    }

    AnnotationMetadata metadata;
    if (beanDef instanceof AnnotatedBeanDefinition
            && className.equals(((AnnotatedBeanDefinition) beanDef).getMetadata().getClassName())) {
        // Can reuse the pre-parsed metadata from the given
        // BeanDefinition...
        metadata = ((AnnotatedBeanDefinition) beanDef).getMetadata();
    } else if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) beanDef).hasBeanClass()) {
        // Check already loaded Class if present...
        // since we possibly can't even load the class file for this Class.
        Class<?> beanClass = ((AbstractBeanDefinition) beanDef).getBeanClass();
        metadata = new StandardAnnotationMetadata(beanClass, true);
    } else {
        try {
            MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(className);
            metadata = metadataReader.getAnnotationMetadata();
        } catch (IOException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "Could not find class file for introspecting configuration annotations: " + className,
                        ex);
            }
            return false;
        }
    }

    if (isFullConfigurationCandidate(metadata)) {
        beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_FULL);
    } else if (isLiteConfigurationCandidate(metadata)) {
        beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_LITE);
    } else {
        return false;
    }

    // It's a full or lite configuration candidate... Let's determine the
    // order value, if any.
    Map<String, Object> orderAttributes = metadata.getAnnotationAttributes(Order.class.getName());
    if (orderAttributes != null) {
        beanDef.setAttribute(ORDER_ATTRIBUTE, orderAttributes.get(AnnotationUtils.VALUE));
    }

    return true;
}

From source file:org.springframework.context.annotation.ConfigurationClassUtils.java

/**
 * Determine the order for the given configuration class metadata.
 * @param metadata the metadata of the annotated class
 * @return the {@link @Order} annotation value on the configuration class,
 * or {@link Ordered#LOWEST_PRECEDENCE} if none declared
 * @since 5.0// w  ww  .  j  a v  a2 s. c  om
 */
@Nullable
public static Integer getOrder(AnnotationMetadata metadata) {
    Map<String, Object> orderAttributes = metadata.getAnnotationAttributes(Order.class.getName());
    return (orderAttributes != null ? ((Integer) orderAttributes.get(AnnotationUtils.VALUE)) : null);
}