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

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

Introduction

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

Prototype

default boolean isAnnotated(String annotationName) 

Source Link

Document

Determine whether the underlying element has an annotation or meta-annotation of the given type defined.

Usage

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

/**
 * Check the given metadata for a full configuration class candidate (i.e. a
 * class annotated with {@code @Configuration}).
 * /*  w  w  w .  ja v  a2s. co m*/
 * @param metadata
 *            the metadata of the annotated class
 * @return {@code true} if the given class is to be processed as a full
 *         configuration class, including cross-method call interception
 */
public static boolean isFullConfigurationCandidate(AnnotationMetadata metadata) {
    return metadata.isAnnotated(Configuration.class.getName());
}

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 w w w  . j  a  v a 2  s .c om
 * @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:com.haulmont.chile.jpa.loader.JPAAnnotationsLoader.java

protected boolean isEmbeddableClass(AnnotationMetadata annotationMetadata) {
    return annotationMetadata.isAnnotated(Embeddable.class.getName())
            && annotationMetadata.isAnnotated(MetaClass.class.getName());
}

From source file:com.haulmont.chile.jpa.loader.JPAAnnotationsLoader.java

protected boolean isEntityClass(AnnotationMetadata annotationMetadata) {
    return annotationMetadata.isAnnotated(MappedSuperclass.class.getName())
            || annotationMetadata.isAnnotated(Entity.class.getName());
}

From source file:com.sxj.jsonrpc.client.spring.AutoJsonRpcClientProxyCreator.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(applicationContext);
    DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory;
    String resolvedPath = resolvePackageToScan();
    LOG.debug(format("Scanning '%s' for JSON-RPC service interfaces.", resolvedPath));
    try {/*from   ww  w. ja  v  a 2 s  . c  o m*/
        for (Resource resource : applicationContext.getResources(resolvedPath)) {
            if (resource.isReadable()) {
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                ClassMetadata classMetadata = metadataReader.getClassMetadata();
                AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
                String jsonRpcPathAnnotation = JsonRpcService.class.getName();
                if (annotationMetadata.isAnnotated(jsonRpcPathAnnotation)) {
                    String className = classMetadata.getClassName();
                    String path = (String) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation)
                            .get("value");
                    boolean useNamedParams = (Boolean) annotationMetadata
                            .getAnnotationAttributes(jsonRpcPathAnnotation).get("useNamedParams");
                    LOG.debug(format("Found JSON-RPC service to proxy [%s] on path '%s'.", className, path));
                    registerJsonProxyBean(dlbf, className, path, useNamedParams);
                }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(format("Cannot scan package '%s' for classes.", resolvedPath), e);
    }
}

From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcClientProxyCreator.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(applicationContext);
    DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory;
    String resolvedPath = resolvePackageToScan();
    LOG.debug(format("Scanning '%s' for JSON-RPC service interfaces.", resolvedPath));
    try {/*from   w  w  w  .j  a v a  2  s  .c om*/
        for (Resource resource : applicationContext.getResources(resolvedPath)) {
            if (resource.isReadable()) {
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                ClassMetadata classMetadata = metadataReader.getClassMetadata();
                AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
                String jsonRpcPathAnnotation = JsonRpcService.class.getName();
                if (annotationMetadata.isAnnotated(jsonRpcPathAnnotation)) {
                    String className = classMetadata.getClassName();
                    String path = (String) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation)
                            .get("value");
                    boolean useNamedParams = (Boolean) annotationMetadata
                            .getAnnotationAttributes(jsonRpcPathAnnotation).get("useNamedParams");
                    LOG.debug(format("Found JSON-RPC service to proxy [%s] on path '%s'.", className, path));
                    registerJsonProxyBean(dlbf, className, path, useNamedParams);
                }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(format("Cannot scan package '%s' for classes.", resolvedPath), e);
    }
}

From source file:com.haulmont.cuba.client.testsupport.CubaClientTestCase.java

protected List<String> getClasses(Resource[] resources) {
    List<String> classNames = new ArrayList<>();

    for (Resource resource : resources) {
        if (resource.isReadable()) {
            MetadataReader metadataReader;
            try {
                metadataReader = metadataReaderFactory.getMetadataReader(resource);
            } catch (IOException e) {
                throw new RuntimeException("Unable to read metadata resource", e);
            }//ww w  .  j ava  2  s.c om

            AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
            if (annotationMetadata.isAnnotated(com.haulmont.chile.core.annotations.MetaClass.class.getName())
                    || annotationMetadata.isAnnotated(MappedSuperclass.class.getName())
                    || annotationMetadata.isAnnotated(Entity.class.getName())) {
                ClassMetadata classMetadata = metadataReader.getClassMetadata();
                classNames.add(classMetadata.getClassName());
            }
        }
    }
    return classNames;
}

From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java

protected List<Class<?>> getClasses(Resource[] resources) {
    List<Class<?>> annotated = new ArrayList<>();

    for (Resource resource : resources) {
        if (resource.isReadable()) {
            MetadataReader metadataReader;
            try {
                metadataReader = metadataReaderFactory.getMetadataReader(resource);
            } catch (IOException e) {
                throw new RuntimeException("Unable to read metadata resource", e);
            }//ww w  .j a v  a 2 s.  com

            AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
            if (annotationMetadata.isAnnotated(com.haulmont.chile.core.annotations.MetaClass.class.getName())) {
                ClassMetadata classMetadata = metadataReader.getClassMetadata();
                Class c = ReflectionHelper.getClass(classMetadata.getClassName());
                annotated.add(c);
            }
        }
    }

    return annotated;
}

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);
    }//from w w w .j  a v  a 2 s .com
}