Search in sources :

Example 6 with BeanComponentDefinitionBuilder

use of org.springframework.data.config.BeanComponentDefinitionBuilder 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)

Aggregations

BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)6 BeanComponentDefinitionBuilder (org.springframework.data.config.BeanComponentDefinitionBuilder)6 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)3 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1