Search in sources :

Example 96 with BeanComponentDefinition

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

the class MongoClientParser method parse.

/*
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
	 */
public BeanDefinition parse(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);
    String id = element.getAttribute("id");
    BeanComponentDefinitionBuilder helper = new BeanComponentDefinitionBuilder(element, parserContext);
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MongoClientFactoryBean.class);
    ParsingUtils.setPropertyValue(builder, element, "port", "port");
    ParsingUtils.setPropertyValue(builder, element, "host", "host");
    ParsingUtils.setPropertyValue(builder, element, "credential", "credential");
    ParsingUtils.setPropertyValue(builder, element, "replica-set", "replicaSet");
    ParsingUtils.setPropertyValue(builder, element, "connection-string", "connectionString");
    MongoParsingUtils.parseMongoClientSettings(element, builder);
    String defaultedId = StringUtils.hasText(id) ? id : BeanNames.MONGO_BEAN_NAME;
    parserContext.pushContainingComponent(new CompositeComponentDefinition("Mongo", source));
    BeanComponentDefinition mongoComponent = helper.getComponent(builder, defaultedId);
    parserContext.registerBeanComponent(mongoComponent);
    BeanComponentDefinition connectionStringPropertyEditor = helper.getComponent(MongoParsingUtils.getConnectionStringPropertyEditorBuilder());
    parserContext.registerBeanComponent(connectionStringPropertyEditor);
    BeanComponentDefinition serverAddressPropertyEditor = helper.getComponent(MongoParsingUtils.getServerAddressPropertyEditorBuilder());
    parserContext.registerBeanComponent(serverAddressPropertyEditor);
    BeanComponentDefinition writeConcernEditor = helper.getComponent(MongoParsingUtils.getWriteConcernPropertyEditorBuilder());
    parserContext.registerBeanComponent(writeConcernEditor);
    BeanComponentDefinition readConcernEditor = helper.getComponent(MongoParsingUtils.getReadConcernPropertyEditorBuilder());
    parserContext.registerBeanComponent(readConcernEditor);
    BeanComponentDefinition readPreferenceEditor = helper.getComponent(MongoParsingUtils.getReadPreferencePropertyEditorBuilder());
    parserContext.registerBeanComponent(readPreferenceEditor);
    BeanComponentDefinition credentialsEditor = helper.getComponent(MongoParsingUtils.getMongoCredentialPropertyEditor());
    parserContext.registerBeanComponent(credentialsEditor);
    BeanComponentDefinition uuidRepresentationEditor = helper.getComponent(MongoParsingUtils.getUUidRepresentationEditorBuilder());
    parserContext.registerBeanComponent(uuidRepresentationEditor);
    parserContext.popAndRegisterContainingComponent();
    return mongoComponent.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanComponentDefinitionBuilder(org.springframework.data.config.BeanComponentDefinitionBuilder)

Example 97 with BeanComponentDefinition

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

the class MongoTemplateParser method parseInternal.

/*
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
	 */
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanComponentDefinitionBuilder helper = new BeanComponentDefinitionBuilder(element, parserContext);
    String converterRef = element.getAttribute("converter-ref");
    String dbFactoryRef = element.getAttribute("db-factory-ref");
    BeanDefinitionBuilder mongoTemplateBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoTemplate.class);
    setPropertyValue(mongoTemplateBuilder, element, "write-concern", "writeConcern");
    if (StringUtils.hasText(dbFactoryRef)) {
        mongoTemplateBuilder.addConstructorArgReference(dbFactoryRef);
    } else {
        mongoTemplateBuilder.addConstructorArgReference(BeanNames.DB_FACTORY_BEAN_NAME);
    }
    if (StringUtils.hasText(converterRef)) {
        mongoTemplateBuilder.addConstructorArgReference(converterRef);
    }
    BeanDefinitionBuilder writeConcernPropertyEditorBuilder = getWriteConcernPropertyEditorBuilder();
    BeanComponentDefinition component = helper.getComponent(writeConcernPropertyEditorBuilder);
    parserContext.registerBeanComponent(component);
    return (AbstractBeanDefinition) helper.getComponentIdButFallback(mongoTemplateBuilder, BeanNames.MONGO_TEMPLATE_BEAN_NAME).getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanComponentDefinitionBuilder(org.springframework.data.config.BeanComponentDefinitionBuilder)

Example 98 with BeanComponentDefinition

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

the class MappingMongoConverterParser method getValidator.

@Nullable
private RuntimeBeanReference getValidator(Object source, ParserContext parserContext) {
    if (!JSR_303_PRESENT) {
        return null;
    }
    RootBeanDefinition validatorDef = new RootBeanDefinition("org.springframework.validation.beanvalidation.LocalValidatorFactoryBean");
    validatorDef.setSource(source);
    validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
    parserContext.registerBeanComponent(new BeanComponentDefinition(validatorDef, validatorName));
    return new RuntimeBeanReference(validatorName);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Nullable(org.springframework.lang.Nullable)

Example 99 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project leopard by tanhaichao.

the class RegisterComponentUtil method registerComponent.

public static BeanDefinition registerComponent(ParserContext parserContext, BeanDefinitionBuilder builder, String id) {
    BeanDefinition definition = builder.getBeanDefinition();
    if (!parserContext.isNested()) {
        String[] aliases = new String[0];
        BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
        BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
        parserContext.registerComponent(componentDefinition);
    }
    return definition;
}
Also used : BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 100 with BeanComponentDefinition

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

the class AbstractUserDetailsServiceBeanDefinitionParser method parse.

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(getBeanClassName(element));
    doParse(element, parserContext, builder);
    RootBeanDefinition userService = (RootBeanDefinition) builder.getBeanDefinition();
    String beanId = resolveId(element, userService, parserContext);
    parserContext.registerBeanComponent(new BeanComponentDefinition(userService, beanId));
    String cacheRef = element.getAttribute(CACHE_REF);
    // Register a caching version of the user service if there's a cache-ref
    if (StringUtils.hasText(cacheRef)) {
        BeanDefinitionBuilder cachingUSBuilder = BeanDefinitionBuilder.rootBeanDefinition(CachingUserDetailsService.class);
        cachingUSBuilder.addConstructorArgReference(beanId);
        cachingUSBuilder.addPropertyValue("userCache", new RuntimeBeanReference(cacheRef));
        BeanDefinition cachingUserService = cachingUSBuilder.getBeanDefinition();
        parserContext.registerBeanComponent(new BeanComponentDefinition(cachingUserService, beanId + CACHING_SUFFIX));
    }
    return null;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

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