Search in sources :

Example 46 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-data-mongodb by spring-projects.

the class MongoDbFactoryParser method registerMongoBeanDefinition.

/**
 * Registers a default {@link BeanDefinition} of a {@link Mongo} instance and returns the name under which the
 * {@link Mongo} instance was registered under.
 *
 * @param element must not be {@literal null}.
 * @param parserContext must not be {@literal null}.
 * @return
 */
private BeanDefinition registerMongoBeanDefinition(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder mongoBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoClientFactoryBean.class);
    setPropertyValue(mongoBuilder, element, "host");
    setPropertyValue(mongoBuilder, element, "port");
    return getSourceBeanDefinition(mongoBuilder, parserContext, element);
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder)

Example 47 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-data-mongodb by spring-projects.

the class MongoDbFactoryParser 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) {
    // Common setup
    BeanDefinitionBuilder dbFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(SimpleMongoDbFactory.class);
    setPropertyValue(dbFactoryBuilder, element, "write-concern", "writeConcern");
    BeanDefinition mongoUri = getMongoUri(element, parserContext);
    if (mongoUri != null) {
        dbFactoryBuilder.addConstructorArgValue(mongoUri);
        return getSourceBeanDefinition(dbFactoryBuilder, parserContext, element);
    }
    BeanComponentDefinitionBuilder helper = new BeanComponentDefinitionBuilder(element, parserContext);
    String mongoRef = element.getAttribute("mongo-ref");
    String dbname = element.getAttribute("dbname");
    // Defaulting
    if (StringUtils.hasText(mongoRef)) {
        dbFactoryBuilder.addConstructorArgReference(mongoRef);
    } else {
        dbFactoryBuilder.addConstructorArgValue(registerMongoBeanDefinition(element, parserContext));
    }
    dbFactoryBuilder.addConstructorArgValue(StringUtils.hasText(dbname) ? dbname : "db");
    BeanDefinitionBuilder writeConcernPropertyEditorBuilder = getWriteConcernPropertyEditorBuilder();
    BeanComponentDefinition component = helper.getComponent(writeConcernPropertyEditorBuilder);
    parserContext.registerBeanComponent(component);
    return (AbstractBeanDefinition) helper.getComponentIdButFallback(dbFactoryBuilder, BeanNames.DB_FACTORY_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) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) BeanComponentDefinitionBuilder(org.springframework.data.config.BeanComponentDefinitionBuilder)

Example 48 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-data-mongodb by spring-projects.

the class MongoJmxParser method createBeanDefEntry.

protected void createBeanDefEntry(Class<?> clazz, CompositeComponentDefinition compositeDef, String mongoRefName, Object eleSource, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(clazz);
    builder.getRawBeanDefinition().setSource(eleSource);
    builder.addConstructorArgReference(mongoRefName);
    BeanDefinition assertDef = builder.getBeanDefinition();
    String assertName = parserContext.getReaderContext().registerWithGeneratedName(assertDef);
    compositeDef.addNestedComponent(new BeanComponentDefinition(assertDef, assertName));
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 49 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-data-mongodb by spring-projects.

the class MongoParsingUtils method getWriteConcernPropertyEditorBuilder.

/**
 * Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
 * {@link WriteConcernPropertyEditor}.
 *
 * @return
 */
static BeanDefinitionBuilder getWriteConcernPropertyEditorBuilder() {
    Map<String, Class<?>> customEditors = new ManagedMap<String, Class<?>>();
    customEditors.put("com.mongodb.WriteConcern", WriteConcernPropertyEditor.class);
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
    builder.addPropertyValue("customEditors", customEditors);
    return builder;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 50 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-data-mongodb by spring-projects.

the class MongoParsingUtils method getServerAddressPropertyEditorBuilder.

/**
 * One should only register one bean definition but want to have the convenience of using
 * AbstractSingleBeanDefinitionParser but have the side effect of registering a 'default' property editor with the
 * container.
 */
static BeanDefinitionBuilder getServerAddressPropertyEditorBuilder() {
    Map<String, String> customEditors = new ManagedMap<String, String>();
    customEditors.put("com.mongodb.ServerAddress[]", "org.springframework.data.mongodb.config.ServerAddressPropertyEditor");
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
    builder.addPropertyValue("customEditors", customEditors);
    return builder;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Aggregations

BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)524 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)116 Element (org.w3c.dom.Element)96 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)61 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)58 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)53 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)47 ManagedList (org.springframework.beans.factory.support.ManagedList)33 ManagedMap (org.springframework.beans.factory.support.ManagedMap)26 HashMap (java.util.HashMap)19 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)19 Test (org.junit.jupiter.api.Test)16 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)16 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)12 Node (org.w3c.dom.Node)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)10 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)10