Java Code Examples for org.springframework.core.type.AnnotationMetadata#introspect()

The following examples show how to use org.springframework.core.type.AnnotationMetadata#introspect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationClassParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public SourceClass(Object source) {
	this.source = source;
	if (source instanceof Class) {
		this.metadata = AnnotationMetadata.introspect((Class<?>) source);
	}
	else {
		this.metadata = ((MetadataReader) source).getAnnotationMetadata();
	}
}
 
Example 2
Source File: ConfigurationClass.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new {@link ConfigurationClass} with the given name.
 * @param clazz the underlying {@link Class} to represent
 * @param beanName name of the {@code @Configuration} class bean
 * @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
 */
public ConfigurationClass(Class<?> clazz, String beanName) {
	Assert.notNull(beanName, "Bean name must not be null");
	this.metadata = AnnotationMetadata.introspect(clazz);
	this.resource = new DescriptiveResource(clazz.getName());
	this.beanName = beanName;
}
 
Example 3
Source File: ConfigurationClassUtils.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * 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.
 * @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 || beanDef.getFactoryMethodName() != 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();
		if (BeanFactoryPostProcessor.class.isAssignableFrom(beanClass) ||
				BeanPostProcessor.class.isAssignableFrom(beanClass) ||
				AopInfrastructureBean.class.isAssignableFrom(beanClass) ||
				EventListenerFactory.class.isAssignableFrom(beanClass)) {
			return false;
		}
		metadata = AnnotationMetadata.introspect(beanClass);
	}
	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;
		}
	}

	Map<String, Object> config = metadata.getAnnotationAttributes(Configuration.class.getName());
	if (config != null && !Boolean.FALSE.equals(config.get("proxyBeanMethods"))) {
		beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_FULL);
	}
	else if (config != null || isConfigurationCandidate(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.
	Integer order = getOrder(metadata);
	if (order != null) {
		beanDef.setAttribute(ORDER_ATTRIBUTE, order);
	}

	return true;
}
 
Example 4
Source File: AnnotatedGenericBeanDefinition.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Create a new AnnotatedGenericBeanDefinition for the given bean class.
 * @param beanClass the loaded bean class
 */
public AnnotatedGenericBeanDefinition(Class<?> beanClass) {
	setBeanClass(beanClass);
	this.metadata = AnnotationMetadata.introspect(beanClass);
}
 
Example 5
Source File: ConfigurationClass.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a new {@link ConfigurationClass} representing a class that was imported
 * using the {@link Import} annotation or automatically processed as a nested
 * configuration class (if imported is {@code true}).
 * @param clazz the underlying {@link Class} to represent
 * @param importedBy the configuration class importing this one (or {@code null})
 * @since 3.1.1
 */
public ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) {
	this.metadata = AnnotationMetadata.introspect(clazz);
	this.resource = new DescriptiveResource(clazz.getName());
	this.importedBy.add(importedBy);
}