Search in sources :

Example 21 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-integration by spring-projects.

the class MBeanTreePollingChannelAdapterParser method parseSource.

@Override
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(MBeanTreePollingMessageSource.class);
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "server", "server");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "query-name-ref", "queryNameReference");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "query-expression-ref", "queryExpressionReference");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "query-name", "queryName");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "query-expression", "queryExpression");
    if (StringUtils.hasText(element.getAttribute("query-name")) && StringUtils.hasText(element.getAttribute("query-name-ref"))) {
        parserContext.getReaderContext().error("Cannot have both `query-name' and 'query-name-ref'", element);
    }
    if (StringUtils.hasText(element.getAttribute("query-expression")) && StringUtils.hasText(element.getAttribute("query-expression-ref"))) {
        parserContext.getReaderContext().error("Cannot have both `query-expression' and 'query-expression-ref'", element);
    }
    BeanComponentDefinition innerBeanDef = IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext);
    String beanName = element.getAttribute("converter");
    if (innerBeanDef != null) {
        if (StringUtils.hasText(beanName)) {
            parserContext.getReaderContext().error("Cannot have both a 'converter' and an inner bean", element);
        }
        beanName = BeanDefinitionReaderUtils.generateBeanName(innerBeanDef.getBeanDefinition(), parserContext.getRegistry(), true);
        parserContext.getRegistry().registerBeanDefinition(beanName, innerBeanDef.getBeanDefinition());
    } else if (!StringUtils.hasText(beanName)) {
        BeanDefinitionBuilder childBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMBeanObjectConverter.class);
        beanName = BeanDefinitionReaderUtils.generateBeanName(childBuilder.getBeanDefinition(), parserContext.getRegistry(), true);
        parserContext.getRegistry().registerBeanDefinition(beanName, childBuilder.getBeanDefinition());
    }
    builder.addConstructorArgReference(beanName);
    return builder.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) DefaultMBeanObjectConverter(org.springframework.integration.jmx.DefaultMBeanObjectConverter)

Example 22 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-data-commons by spring-projects.

the class BeanComponentDefinitionBuilder method getComponent.

/**
 * Creates a new {@link BeanComponentDefinition} from the given {@link BeanDefinitionBuilder} using the given name and
 * raw source object.
 *
 * @param builder must not be {@literal null}.
 * @param name must not be {@literal null}.
 * @param rawSource
 * @return
 */
public BeanComponentDefinition getComponent(BeanDefinitionBuilder builder, String name, Object rawSource) {
    Assert.notNull(builder, "Builder must not be null!");
    Assert.hasText(name, "Name of bean must not be null or empty!");
    AbstractBeanDefinition definition = builder.getRawBeanDefinition();
    definition.setSource(context.extractSource(rawSource));
    return new BeanComponentDefinition(definition, name);
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 23 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-data-commons by spring-projects.

the class RepositoryBeanDefinitionParser method parse.

/*
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
	 */
@Nullable
public BeanDefinition parse(Element element, ParserContext parser) {
    XmlReaderContext readerContext = parser.getReaderContext();
    try {
        ResourceLoader resourceLoader = ConfigurationUtils.getRequiredResourceLoader(readerContext);
        Environment environment = readerContext.getEnvironment();
        BeanDefinitionRegistry registry = parser.getRegistry();
        XmlRepositoryConfigurationSource configSource = new XmlRepositoryConfigurationSource(element, parser, environment);
        RepositoryConfigurationDelegate delegate = new RepositoryConfigurationDelegate(configSource, resourceLoader, environment);
        RepositoryConfigurationUtils.exposeRegistration(extension, registry, configSource);
        for (BeanComponentDefinition definition : delegate.registerRepositoriesIn(registry, extension)) {
            readerContext.fireComponentRegistered(definition);
        }
    } catch (RuntimeException e) {
        handleError(e, element, readerContext);
    }
    return null;
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) XmlReaderContext(org.springframework.beans.factory.xml.XmlReaderContext) Environment(org.springframework.core.env.Environment) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) Nullable(org.springframework.lang.Nullable)

Example 24 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-security by spring-projects.

the class AuthenticationConfigBuilder method createUserDetailsServiceFactory.

private void createUserDetailsServiceFactory() {
    if (this.pc.getRegistry().containsBeanDefinition(BeanIds.USER_DETAILS_SERVICE_FACTORY)) {
        // Multiple <http> case
        return;
    }
    RootBeanDefinition bean = new RootBeanDefinition(UserDetailsServiceFactoryBean.class);
    bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    this.pc.registerBeanComponent(new BeanComponentDefinition(bean, BeanIds.USER_DETAILS_SERVICE_FACTORY));
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 25 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-security by spring-projects.

the class AuthenticationConfigBuilder method createRememberMeProvider.

private void createRememberMeProvider(String key) {
    RootBeanDefinition provider = new RootBeanDefinition(RememberMeAuthenticationProvider.class);
    provider.setSource(this.rememberMeFilter.getSource());
    provider.getConstructorArgumentValues().addGenericArgumentValue(key);
    String id = this.pc.getReaderContext().generateBeanName(provider);
    this.pc.registerBeanComponent(new BeanComponentDefinition(provider, id));
    this.rememberMeProviderRef = new RuntimeBeanReference(id);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Aggregations

BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)133 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)75 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)52 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)47 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)47 Element (org.w3c.dom.Element)29 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)22 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)22 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)20 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)16 ManagedList (org.springframework.beans.factory.support.ManagedList)14 Nullable (org.springframework.lang.Nullable)10 ComponentDefinition (org.springframework.beans.factory.parsing.ComponentDefinition)9 Test (org.junit.jupiter.api.Test)6 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)5 NodeList (org.w3c.dom.NodeList)5 Test (org.junit.Test)4 ManagedMap (org.springframework.beans.factory.support.ManagedMap)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)3 PropertyValue (org.springframework.beans.PropertyValue)3