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.DefaultDeferredImportSelectorGroup |
private static class |
ConfigurationClassParser.DeferredImportSelectorGrouping |
private class |
ConfigurationClassParser.DeferredImportSelectorGroupingHandler |
private class |
ConfigurationClassParser.DeferredImportSelectorHandler |
private static class |
ConfigurationClassParser.DeferredImportSelectorHolder |
private static class |
ConfigurationClassParser.ImportStack |
private class |
ConfigurationClassParser.SourceClass
Simple wrapper that allows annotated source classes to be dealt with
in a uniform manner, regardless of how they are loaded.
|
Modifier and Type | Field and Description |
---|---|
private ComponentScanAnnotationParser |
componentScanParser |
private ConditionEvaluator |
conditionEvaluator |
private java.util.Map<ConfigurationClass,ConfigurationClass> |
configurationClasses |
private static PropertySourceFactory |
DEFAULT_PROPERTY_SOURCE_FACTORY |
private static java.util.Comparator<ConfigurationClassParser.DeferredImportSelectorHolder> |
DEFERRED_IMPORT_COMPARATOR |
private ConfigurationClassParser.DeferredImportSelectorHandler |
deferredImportSelectorHandler |
private Environment |
environment |
private ConfigurationClassParser.ImportStack |
importStack |
private java.util.Map<java.lang.String,ConfigurationClass> |
knownSuperclasses |
private Log |
logger |
private MetadataReaderFactory |
metadataReaderFactory |
private ConfigurationClassParser.SourceClass |
objectSourceClass |
private ProblemReporter |
problemReporter |
private java.util.List<java.lang.String> |
propertySourceNames |
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 |
---|---|
private void |
addPropertySource(PropertySource<?> propertySource) |
(package private) ConfigurationClassParser.SourceClass |
asSourceClass(java.lang.Class<?> classType)
Factory method to obtain a
ConfigurationClassParser.SourceClass from a Class . |
private ConfigurationClassParser.SourceClass |
asSourceClass(ConfigurationClass configurationClass)
Factory method to obtain a
ConfigurationClassParser.SourceClass from a ConfigurationClass . |
(package private) ConfigurationClassParser.SourceClass |
asSourceClass(java.lang.String className)
Factory method to obtain a
ConfigurationClassParser.SourceClass from a class name. |
private java.util.Collection<ConfigurationClassParser.SourceClass> |
asSourceClasses(java.lang.String... classNames)
Factory method to obtain
SourceClasss from class names. |
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) ImportRegistry |
getImportRegistry() |
private java.util.Set<ConfigurationClassParser.SourceClass> |
getImports(ConfigurationClassParser.SourceClass sourceClass)
Returns
@Import class, considering all meta-annotations. |
private boolean |
isChainedImportOnStack(ConfigurationClass configClass) |
protected void |
parse(AnnotationMetadata metadata,
java.lang.String beanName) |
protected void |
parse(java.lang.Class<?> clazz,
java.lang.String beanName) |
void |
parse(java.util.Set<BeanDefinitionHolder> configCandidates) |
protected void |
parse(java.lang.String className,
java.lang.String beanName) |
protected void |
processConfigurationClass(ConfigurationClass configClass) |
private void |
processImports(ConfigurationClass configClass,
ConfigurationClassParser.SourceClass currentSourceClass,
java.util.Collection<ConfigurationClassParser.SourceClass> importCandidates,
boolean checkForCircularImports) |
private void |
processInterfaces(ConfigurationClass configClass,
ConfigurationClassParser.SourceClass sourceClass)
Register default methods on interfaces implemented by the configuration class.
|
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. |
private java.util.Set<MethodMetadata> |
retrieveBeanMethodMetadata(ConfigurationClassParser.SourceClass sourceClass)
Retrieve the metadata for all
@Bean methods. |
void |
validate()
Validate each
ConfigurationClass object. |
private static final PropertySourceFactory DEFAULT_PROPERTY_SOURCE_FACTORY
private static final java.util.Comparator<ConfigurationClassParser.DeferredImportSelectorHolder> DEFERRED_IMPORT_COMPARATOR
private final Log logger
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 ConditionEvaluator conditionEvaluator
private final java.util.Map<ConfigurationClass,ConfigurationClass> configurationClasses
private final java.util.Map<java.lang.String,ConfigurationClass> knownSuperclasses
private final java.util.List<java.lang.String> propertySourceNames
private final ConfigurationClassParser.ImportStack importStack
private final ConfigurationClassParser.DeferredImportSelectorHandler deferredImportSelectorHandler
private final ConfigurationClassParser.SourceClass objectSourceClass
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(@Nullable java.lang.String className, java.lang.String beanName) throws java.io.IOException
java.io.IOException
protected final void parse(java.lang.Class<?> clazz, java.lang.String beanName) throws java.io.IOException
java.io.IOException
protected final void parse(AnnotationMetadata metadata, java.lang.String beanName) throws java.io.IOException
java.io.IOException
public void validate()
ConfigurationClass
object.public java.util.Set<ConfigurationClass> getConfigurationClasses()
protected void processConfigurationClass(ConfigurationClass configClass) throws java.io.IOException
java.io.IOException
@Nullable 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
java.io.IOException
private void processInterfaces(ConfigurationClass configClass, ConfigurationClassParser.SourceClass sourceClass) throws java.io.IOException
java.io.IOException
private java.util.Set<MethodMetadata> retrieveBeanMethodMetadata(ConfigurationClassParser.SourceClass sourceClass)
@Bean
methods.private 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 void addPropertySource(PropertySource<?> propertySource)
private 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 processImports(ConfigurationClass configClass, ConfigurationClassParser.SourceClass currentSourceClass, java.util.Collection<ConfigurationClassParser.SourceClass> importCandidates, boolean checkForCircularImports)
private boolean isChainedImportOnStack(ConfigurationClass configClass)
ImportRegistry getImportRegistry()
private ConfigurationClassParser.SourceClass asSourceClass(ConfigurationClass configurationClass) throws java.io.IOException
ConfigurationClassParser.SourceClass
from a ConfigurationClass
.java.io.IOException
ConfigurationClassParser.SourceClass asSourceClass(@Nullable java.lang.Class<?> classType) throws java.io.IOException
ConfigurationClassParser.SourceClass
from a Class
.java.io.IOException
private java.util.Collection<ConfigurationClassParser.SourceClass> asSourceClasses(java.lang.String... classNames) throws java.io.IOException
SourceClasss
from class names.java.io.IOException
ConfigurationClassParser.SourceClass asSourceClass(@Nullable java.lang.String className) throws java.io.IOException
ConfigurationClassParser.SourceClass
from a class name.java.io.IOException