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

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

Introduction

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

Prototype

boolean isInterface();

Source Link

Document

Return whether the underlying class represents an interface.

Usage

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

/**
 * Check the given metadata for a lite configuration class candidate (e.g. a
 * class annotated with {@code @Component} or just having {@code @Import}
 * declarations or {@code @Bean methods}).
 * /*from  www  .  ja  v  a2  s .  c o m*/
 * @param metadata
 *            the metadata of the annotated class
 * @return {@code true} if the given class is to be processed as a lite
 *         configuration class, just registering it and scanning it for
 *         {@code @Bean} methods
 */
public static boolean isLiteConfigurationCandidate(AnnotationMetadata metadata) {
    // Do not consider an interface or an annotation...
    if (metadata.isInterface()) {
        return false;
    }

    // Any of the typical annotations found?
    for (String indicator : candidateIndicators) {
        if (metadata.isAnnotated(indicator)) {
            return true;
        }
    }

    // Finally, let's look for @Bean methods...
    try {
        return metadata.hasAnnotatedMethods(Bean.class.getName());
    } catch (Throwable ex) {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Failed to introspect @Bean methods on class [" + metadata.getClassName() + "]: " + ex);
        }
        return false;
    }
}

From source file:org.zalando.stups.spring.cloud.netflix.feign.OAuth2FeignClientsRegsitrar.java

@Override
public void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata,
        final BeanDefinitionRegistry registry) {

    Set<String> basePackages = getBasePackages(importingClassMetadata);

    ClassPathScanningCandidateComponentProvider scanner = getScanner();
    scanner.addIncludeFilter(new AnnotationTypeFilter(FeignClient.class));
    scanner.setResourceLoader(this.resourceLoader);

    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);
        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {

                // verify annotated class is an interface
                AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
                AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
                Assert.isTrue(annotationMetadata.isInterface(),
                        "@FeignClient can only be specified on an interface");

                BeanDefinitionHolder holder = createBeanDefinition(annotationMetadata);
                BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
            }/*w  w  w  .j a v  a  2s  . com*/
        }
    }
}

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

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        BeanDefinitionRegistry registry) {
    if (importingClassMetadata != null
            && importingClassMetadata.isAnnotated(MessagingGateway.class.getName())) {
        Assert.isTrue(importingClassMetadata.isInterface(),
                "@MessagingGateway can only be specified on an interface");
        List<MultiValueMap<String, Object>> valuesHierarchy = captureMetaAnnotationValues(
                importingClassMetadata);
        Map<String, Object> annotationAttributes = importingClassMetadata
                .getAnnotationAttributes(MessagingGateway.class.getName());
        replaceEmptyOverrides(valuesHierarchy, annotationAttributes);
        annotationAttributes.put("serviceInterface", importingClassMetadata.getClassName());

        BeanDefinitionReaderUtils.registerBeanDefinition(this.parse(annotationAttributes), registry);
    }/*  www.ja v a2  s.co m*/
}