use of cn.taketoday.context.loader.ScopeMetadata in project today-infrastructure by TAKETODAY.
the class ClassPathBeanDefinitionScanner method scan.
/**
* Perform a scan within the specified base packages and consume the registered
* bean definitions.
* <p>This method does <i>not</i> register an annotation config processor
* but rather leaves this up to the caller.
*
* @param operator set of beans registered if any for tooling registration purposes
* @param basePackages the packages to check for annotated classes
*/
public void scan(@Nullable UnaryOperator<BeanDefinitionHolder> operator, String... basePackages) {
for (String basePackage : basePackages) {
try {
scanCandidateComponents(basePackage, (metadataReader, factory) -> {
ScannedGenericBeanDefinition candidate = new ScannedGenericBeanDefinition(metadataReader);
Resource resource = metadataReader.getResource();
candidate.setSource(resource);
candidate.setResource(resource);
ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(candidate);
candidate.setScope(scopeMetadata.getScopeName());
String beanName = beanNameGenerator.generateBeanName(candidate, registry);
postProcessBeanDefinition(candidate, beanName);
AnnotationConfigUtils.processCommonDefinitionAnnotations(candidate);
if (checkCandidate(beanName, candidate)) {
BeanDefinitionHolder holder = new BeanDefinitionHolder(candidate, beanName);
holder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, holder, registry);
if (operator != null) {
holder = operator.apply(holder);
}
registerBeanDefinition(holder, registry);
}
});
} catch (IOException ex) {
throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
}
}
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-infrastructure by TAKETODAY.
the class TestScopeMetadataResolver method resolveScopeMetadata.
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition beanDefinition) {
ScopeMetadata metadata = new ScopeMetadata();
metadata.setScopeName("myCustomScope");
return metadata;
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-framework by TAKETODAY.
the class ClassPathBeanDefinitionScanner method scan.
/**
* Perform a scan within the specified base packages and consume the registered
* bean definitions.
* <p>This method does <i>not</i> register an annotation config processor
* but rather leaves this up to the caller.
*
* @param operator set of beans registered if any for tooling registration purposes
* @param basePackages the packages to check for annotated classes
*/
public void scan(@Nullable UnaryOperator<BeanDefinitionHolder> operator, String... basePackages) {
for (String basePackage : basePackages) {
try {
scanCandidateComponents(basePackage, (metadataReader, factory) -> {
ScannedGenericBeanDefinition candidate = new ScannedGenericBeanDefinition(metadataReader);
Resource resource = metadataReader.getResource();
candidate.setSource(resource);
candidate.setResource(resource);
ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(candidate);
candidate.setScope(scopeMetadata.getScopeName());
String beanName = beanNameGenerator.generateBeanName(candidate, registry);
postProcessBeanDefinition(candidate, beanName);
AnnotationConfigUtils.processCommonDefinitionAnnotations(candidate);
if (checkCandidate(beanName, candidate)) {
BeanDefinitionHolder holder = new BeanDefinitionHolder(candidate, beanName);
holder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, holder, registry);
if (operator != null) {
holder = operator.apply(holder);
}
registerBeanDefinition(holder, registry);
}
});
} catch (IOException ex) {
throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
}
}
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-framework by TAKETODAY.
the class AnnotatedBeanDefinitionReader method doRegisterBean.
/**
* Register a bean from the given bean class, deriving its metadata from
* class-declared annotations.
*
* @param beanClass the class of the bean
* @param name an explicit name for the bean
* @param qualifiers specific qualifier annotations to consider, if any,
* in addition to qualifiers at the bean class level
* @param supplier a callback for creating an instance of the bean
* (may be {@code null})
* @param customizers one or more callbacks for customizing the factory's
* {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
*/
private <T> void doRegisterBean(Class<T> beanClass, @Nullable String name, @Nullable Class<? extends Annotation>[] qualifiers, @Nullable Supplier<T> supplier, @Nullable BeanDefinitionCustomizer[] customizers) {
AnnotatedGenericBeanDefinition definition = new AnnotatedGenericBeanDefinition(beanClass);
if (this.conditionEvaluator.shouldSkip(definition.getMetadata())) {
return;
}
definition.setInstanceSupplier(supplier);
ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(definition);
definition.setScope(scopeMetadata.getScopeName());
String beanName = name != null ? name : beanNameGenerator.generateBeanName(definition, registry);
AnnotationConfigUtils.processCommonDefinitionAnnotations(definition);
if (qualifiers != null) {
for (Class<? extends Annotation> qualifier : qualifiers) {
if (Primary.class == qualifier) {
definition.setPrimary(true);
} else if (Lazy.class == qualifier) {
definition.setLazyInit(true);
} else {
definition.addQualifier(new AutowireCandidateQualifier(qualifier));
}
}
}
applyDynamicCustomizers(definition, customizers);
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(definition, beanName);
definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
use of cn.taketoday.context.loader.ScopeMetadata in project today-framework by TAKETODAY.
the class TestScopeMetadataResolver method resolveScopeMetadata.
@Override
public ScopeMetadata resolveScopeMetadata(BeanDefinition beanDefinition) {
ScopeMetadata metadata = new ScopeMetadata();
metadata.setScopeName("myCustomScope");
return metadata;
}
Aggregations