use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class AnnotationBeanNameGeneratorTests method generateBeanNameFromMetaComponentWithStringValue.
@Test
public void generateBeanNameFromMetaComponentWithStringValue() {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromStringMeta.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertThat(beanName).isEqualTo("henry");
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class AbstractInterceptorDrivenBeanDefinitionDecorator method decorate.
@Override
public final BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definitionHolder, ParserContext parserContext) {
BeanDefinitionRegistry registry = parserContext.getRegistry();
// get the root bean name - will be the name of the generated proxy factory bean
String existingBeanName = definitionHolder.getBeanName();
BeanDefinition targetDefinition = definitionHolder.getBeanDefinition();
BeanDefinitionHolder targetHolder = new BeanDefinitionHolder(targetDefinition, existingBeanName + ".TARGET");
// delegate to subclass for interceptor definition
BeanDefinition interceptorDefinition = createInterceptorDefinition(node);
// generate name and register the interceptor
String interceptorName = existingBeanName + '.' + getInterceptorNameSuffix(interceptorDefinition);
BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(interceptorDefinition, interceptorName), registry);
BeanDefinitionHolder result = definitionHolder;
if (!isProxyFactoryBeanDefinition(targetDefinition)) {
// create the proxy definition
RootBeanDefinition proxyDefinition = new RootBeanDefinition();
// create proxy factory bean definition
proxyDefinition.setBeanClass(ProxyFactoryBean.class);
proxyDefinition.setScope(targetDefinition.getScope());
proxyDefinition.setLazyInit(targetDefinition.isLazyInit());
// set the target
proxyDefinition.setDecoratedDefinition(targetHolder);
proxyDefinition.getPropertyValues().add("target", targetHolder);
// create the interceptor names list
proxyDefinition.getPropertyValues().add("interceptorNames", new ManagedList<String>());
// copy autowire settings from original bean definition.
proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
proxyDefinition.setPrimary(targetDefinition.isPrimary());
if (targetDefinition instanceof AbstractBeanDefinition) {
proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
}
// wrap it in a BeanDefinitionHolder with bean name
result = new BeanDefinitionHolder(proxyDefinition, existingBeanName);
}
addInterceptorNameToList(interceptorName, result.getBeanDefinition());
return result;
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project qi4j-sdk by Qi4j.
the class Qi4jServiceBeanDefinitionParser method parse.
@Override
public final BeanDefinition parse(Element anElement, ParserContext aParserContext) {
String serviceId = anElement.getAttribute(SERVICE_ID);
// Service factory bean
BeanDefinitionBuilder builder = rootBeanDefinition(ServiceFactoryBean.class);
builder.addConstructorArgReference(BEAN_ID_QI4J_APPLICATION);
builder.addConstructorArgValue(serviceId);
AbstractBeanDefinition definition = builder.getBeanDefinition();
// Register service factory bean
BeanDefinitionRegistry definitionRegistry = aParserContext.getRegistry();
definitionRegistry.registerBeanDefinition(serviceId, definition);
return definition;
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project qi4j-sdk by Qi4j.
the class Qi4jBootstrapBeanDefinitionParser method registerBean.
private void registerBean(ParserContext aParserContext, BeanDefinition aBeanDefinition) {
BeanDefinitionRegistry registry = aParserContext.getRegistry();
registry.registerBeanDefinition(BEAN_ID_QI4J_APPLICATION, aBeanDefinition);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project grails-core by grails.
the class ClosureClassIgnoringComponentScanBeanDefinitionParser method createScanner.
@Override
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
final ClassPathBeanDefinitionScanner scanner = super.createScanner(readerContext, useDefaultFilters);
BeanDefinitionRegistry beanDefinitionRegistry = readerContext.getRegistry();
GrailsPluginManager pluginManager = null;
if (beanDefinitionRegistry instanceof HierarchicalBeanFactory) {
HierarchicalBeanFactory beanFactory = (HierarchicalBeanFactory) beanDefinitionRegistry;
BeanFactory parent = beanFactory.getParentBeanFactory();
if (parent != null && parent.containsBean(GrailsPluginManager.BEAN_NAME)) {
pluginManager = parent.getBean(GrailsPluginManager.BEAN_NAME, GrailsPluginManager.class);
}
}
if (pluginManager != null) {
List<TypeFilter> typeFilters = pluginManager.getTypeFilters();
for (TypeFilter typeFilter : typeFilters) {
scanner.addIncludeFilter(typeFilter);
}
}
return scanner;
}
Aggregations