class ConfigurationClassParser
extends java.lang.Object
Configuration
class definition, populating a collection of
ConfigurationClass
objects (parsing a single Configuration class may result in
any number of ConfigurationClass objects because one Configuration class may import
another using the Import
annotation).
This class helps separate the concern of parsing the structure of a Configuration
class from the concern of registering BeanDefinition objects based on the
content of that model (with the exception of @ComponentScan
annotations which
need to be registered immediately).
This ASM-based implementation avoids reflection and eager class loading in order to interoperate effectively with lazy class loading in a Spring ApplicationContext.
ConfigurationClassBeanDefinitionReader
Modifier and Type | Class and Description |
---|---|
private static class |
ConfigurationClassParser.CircularImportProblem
|
private static class |
ConfigurationClassParser.DeferredImportSelectorHolder |
(package private) static interface |
ConfigurationClassParser.ImportRegistry |
private static class |
ConfigurationClassParser.ImportStack |
private class |
ConfigurationClassParser.SourceClass
Simple wrapper that allows annotated source classes to be dealt with in a uniform
manor, regardless of how they are loaded.
|
Modifier and Type | Field and Description |
---|---|
private ComponentScanAnnotationParser |
componentScanParser |
private ConditionEvaluator |
conditionEvaluator |
private java.util.Set<ConfigurationClass> |
configurationClasses |
private static java.util.Comparator<ConfigurationClassParser.DeferredImportSelectorHolder> |
DEFERRED_IMPORT_COMPARATOR |
private java.util.List<ConfigurationClassParser.DeferredImportSelectorHolder> |
deferredImportSelectors |
private Environment |
environment |
private ConfigurationClassParser.ImportStack |
importStack |
private java.util.Map<java.lang.String,ConfigurationClass> |
knownSuperclasses |
private MetadataReaderFactory |
metadataReaderFactory |
private ProblemReporter |
problemReporter |
private MultiValueMap<java.lang.String,ResourcePropertySource> |
propertySources |
private BeanDefinitionRegistry |
registry |
private ResourceLoader |
resourceLoader |
Constructor and Description |
---|
ConfigurationClassParser(MetadataReaderFactory metadataReaderFactory,
ProblemReporter problemReporter,
Environment environment,
ResourceLoader resourceLoader,
BeanNameGenerator componentScanBeanNameGenerator,
BeanDefinitionRegistry registry)
Create a new
ConfigurationClassParser instance that will be used
to populate the set of configuration classes. |
Modifier and Type | Method and Description |
---|---|
ConfigurationClassParser.SourceClass |
asSourceClass(java.lang.Class<?> classType)
Factory method to obtain a
ConfigurationClassParser.SourceClass from a Class . |
ConfigurationClassParser.SourceClass |
asSourceClass(ConfigurationClass configurationClass)
Factory method to obtain a
ConfigurationClassParser.SourceClass from a ConfigurationClass . |
ConfigurationClassParser.SourceClass |
asSourceClass(java.lang.String className)
Factory method to obtain a
ConfigurationClassParser.SourceClass from a class name. |
java.util.Collection<ConfigurationClassParser.SourceClass> |
asSourceClasses(java.lang.String[] classNames)
Factory method to obtain
ConfigurationClassParser.SourceClass s from class names. |
private PropertySource<?> |
collatePropertySources(java.lang.String name,
java.util.List<ResourcePropertySource> propertySources) |
private void |
collectImports(ConfigurationClassParser.SourceClass sourceClass,
java.util.Set<ConfigurationClassParser.SourceClass> imports,
java.util.Set<ConfigurationClassParser.SourceClass> visited)
Recursively collect all declared
@Import values. |
protected ConfigurationClassParser.SourceClass |
doProcessConfigurationClass(ConfigurationClass configClass,
ConfigurationClassParser.SourceClass sourceClass)
Apply processing and build a complete
ConfigurationClass by reading the
annotations, members and methods from the source class. |
java.util.Set<ConfigurationClass> |
getConfigurationClasses() |
(package private) ConfigurationClassParser.ImportRegistry |
getImportRegistry() |
private java.util.Set<ConfigurationClassParser.SourceClass> |
getImports(ConfigurationClassParser.SourceClass sourceClass)
Returns
@Import class, considering all meta-annotations. |
java.util.List<PropertySource<?>> |
getPropertySources() |
private void |
invokeAwareMethods(java.lang.Object importStrategyBean)
Invoke
ResourceLoaderAware , BeanClassLoaderAware and
BeanFactoryAware contracts if implemented by the given bean . |
protected void |
parse(java.lang.Class<?> clazz,
java.lang.String beanName)
Parse the specified
@Configuration class. |
void |
parse(java.util.Set<BeanDefinitionHolder> configCandidates) |
protected void |
parse(java.lang.String className,
java.lang.String beanName)
Parse the specified
@Configuration class. |
protected void |
processConfigurationClass(ConfigurationClass configClass) |
private void |
processDeferredImportSelectors() |
private void |
processImports(ConfigurationClass configClass,
ConfigurationClassParser.SourceClass currentSourceClass,
java.util.Collection<ConfigurationClassParser.SourceClass> importCandidates,
boolean checkForCircularImports) |
private void |
processMemberClasses(ConfigurationClass configClass,
ConfigurationClassParser.SourceClass sourceClass)
Register member (nested) classes that happen to be configuration classes themselves.
|
private void |
processPropertySource(AnnotationAttributes propertySource)
Process the given
@PropertySource annotation metadata. |
void |
validate()
Validate each
ConfigurationClass object. |
private static final java.util.Comparator<ConfigurationClassParser.DeferredImportSelectorHolder> DEFERRED_IMPORT_COMPARATOR
private final MetadataReaderFactory metadataReaderFactory
private final ProblemReporter problemReporter
private final Environment environment
private final ResourceLoader resourceLoader
private final BeanDefinitionRegistry registry
private final ComponentScanAnnotationParser componentScanParser
private final java.util.Set<ConfigurationClass> configurationClasses
private final java.util.Map<java.lang.String,ConfigurationClass> knownSuperclasses
private final MultiValueMap<java.lang.String,ResourcePropertySource> propertySources
private final ConfigurationClassParser.ImportStack importStack
private final java.util.List<ConfigurationClassParser.DeferredImportSelectorHolder> deferredImportSelectors
private final ConditionEvaluator conditionEvaluator
public ConfigurationClassParser(MetadataReaderFactory metadataReaderFactory, ProblemReporter problemReporter, Environment environment, ResourceLoader resourceLoader, BeanNameGenerator componentScanBeanNameGenerator, BeanDefinitionRegistry registry)
ConfigurationClassParser
instance that will be used
to populate the set of configuration classes.public void parse(java.util.Set<BeanDefinitionHolder> configCandidates)
protected final void parse(java.lang.String className, java.lang.String beanName) throws java.io.IOException
@Configuration
class.className
- the name of the class to parsebeanName
- may be null, but if populated represents the bean id
(assumes that this configuration class was configured via XML)java.io.IOException
protected final void parse(java.lang.Class<?> clazz, java.lang.String beanName) throws java.io.IOException
@Configuration
class.clazz
- the Class to parsebeanName
- must not be null (as of Spring 3.1.1)java.io.IOException
protected void processConfigurationClass(ConfigurationClass configClass) throws java.io.IOException
java.io.IOException
protected final ConfigurationClassParser.SourceClass doProcessConfigurationClass(ConfigurationClass configClass, ConfigurationClassParser.SourceClass sourceClass) throws java.io.IOException
ConfigurationClass
by reading the
annotations, members and methods from the source class. This method can be called
multiple times as relevant sources are discovered.configClass
- the configuration class being buildsourceClass
- a source classnull
if none found or previously processedjava.io.IOException
private void processMemberClasses(ConfigurationClass configClass, ConfigurationClassParser.SourceClass sourceClass) throws java.io.IOException
sourceClass
- the source class to processjava.io.IOException
- if there is any problem reading metadata from a member classprivate void processPropertySource(AnnotationAttributes propertySource) throws java.io.IOException
@PropertySource
annotation metadata.propertySource
- metadata for the @PropertySource
annotation foundjava.io.IOException
- if loading a property source failedprivate java.util.Set<ConfigurationClassParser.SourceClass> getImports(ConfigurationClassParser.SourceClass sourceClass) throws java.io.IOException
@Import
class, considering all meta-annotations.java.io.IOException
private void collectImports(ConfigurationClassParser.SourceClass sourceClass, java.util.Set<ConfigurationClassParser.SourceClass> imports, java.util.Set<ConfigurationClassParser.SourceClass> visited) throws java.io.IOException
@Import
values. Unlike most
meta-annotations it is valid to have several @Import
s declared with
different values; the usual process of returning values from the first
meta-annotation on a class is not sufficient.
For example, it is common for a @Configuration
class to declare direct
@Import
s in addition to meta-imports originating from an @Enable
annotation.
sourceClass
- the class to searchimports
- the imports collected so farvisited
- used to track visited classes to prevent infinite recursionjava.io.IOException
- if there is any problem reading metadata from the named classprivate void processDeferredImportSelectors()
private void processImports(ConfigurationClass configClass, ConfigurationClassParser.SourceClass currentSourceClass, java.util.Collection<ConfigurationClassParser.SourceClass> importCandidates, boolean checkForCircularImports) throws java.io.IOException
java.io.IOException
private void invokeAwareMethods(java.lang.Object importStrategyBean)
ResourceLoaderAware
, BeanClassLoaderAware
and
BeanFactoryAware
contracts if implemented by the given bean
.public void validate()
ConfigurationClass
object.public java.util.Set<ConfigurationClass> getConfigurationClasses()
public java.util.List<PropertySource<?>> getPropertySources()
private PropertySource<?> collatePropertySources(java.lang.String name, java.util.List<ResourcePropertySource> propertySources)
ConfigurationClassParser.ImportRegistry getImportRegistry()
public ConfigurationClassParser.SourceClass asSourceClass(ConfigurationClass configurationClass) throws java.io.IOException
ConfigurationClassParser.SourceClass
from a ConfigurationClass
.java.io.IOException
public ConfigurationClassParser.SourceClass asSourceClass(java.lang.Class<?> classType) throws java.io.IOException, java.lang.ClassNotFoundException
ConfigurationClassParser.SourceClass
from a Class
.java.io.IOException
java.lang.ClassNotFoundException
public java.util.Collection<ConfigurationClassParser.SourceClass> asSourceClasses(java.lang.String[] classNames) throws java.io.IOException, java.lang.ClassNotFoundException
ConfigurationClassParser.SourceClass
s from class names.java.io.IOException
java.lang.ClassNotFoundException
public ConfigurationClassParser.SourceClass asSourceClass(java.lang.String className) throws java.io.IOException, java.lang.ClassNotFoundException
ConfigurationClassParser.SourceClass
from a class name.java.io.IOException
java.lang.ClassNotFoundException