Search in sources :

Example 81 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, "credentials", "credentials");
    MongoParsingUtils.parseMongoClientOptions(element, builder);
    MongoParsingUtils.parseReplicaSet(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 serverAddressPropertyEditor = helper.getComponent(MongoParsingUtils.getServerAddressPropertyEditorBuilder());
    parserContext.registerBeanComponent(serverAddressPropertyEditor);
    BeanComponentDefinition writeConcernEditor = helper.getComponent(MongoParsingUtils.getWriteConcernPropertyEditorBuilder());
    parserContext.registerBeanComponent(writeConcernEditor);
    BeanComponentDefinition readPreferenceEditor = helper.getComponent(MongoParsingUtils.getReadPreferencePropertyEditorBuilder());
    parserContext.registerBeanComponent(readPreferenceEditor);
    BeanComponentDefinition credentialsEditor = helper.getComponent(MongoParsingUtils.getMongoCredentialPropertyEditor());
    parserContext.registerBeanComponent(credentialsEditor);
    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 82 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)

Aggregations

BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)82 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)53 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)33 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)28 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)24 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)17 Element (org.w3c.dom.Element)16 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)11 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)11 ManagedList (org.springframework.beans.factory.support.ManagedList)10 Test (org.junit.Test)7 ComponentDefinition (org.springframework.beans.factory.parsing.ComponentDefinition)7 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)6 ManagedMap (org.springframework.beans.factory.support.ManagedMap)4 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)3 BeanComponentDefinitionBuilder (org.springframework.data.config.BeanComponentDefinitionBuilder)3 Method (java.lang.reflect.Method)2 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 PropertyValue (org.springframework.beans.PropertyValue)2 BeanReference (org.springframework.beans.factory.config.BeanReference)2