Search in sources :

Example 51 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project qi4j-sdk by Qi4j.

the class Qi4jServiceBeanDefinitionParser method parse.

@Override
public final BeanDefinition parse(Element anElement, ParserContext aParserContext) {
    String serviceId = anElement.getAttribute(SERVICE_ID);
    // Service factory bean
    BeanDefinitionBuilder builder = rootBeanDefinition(ServiceFactoryBean.class);
    builder.addConstructorArgReference(BEAN_ID_QI4J_APPLICATION);
    builder.addConstructorArgValue(serviceId);
    AbstractBeanDefinition definition = builder.getBeanDefinition();
    // Register service factory bean
    BeanDefinitionRegistry definitionRegistry = aParserContext.getRegistry();
    definitionRegistry.registerBeanDefinition(serviceId, definition);
    return definition;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 52 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition in project cxf by apache.

the class AbstractFactoryBeanDefinitionParser method doParse.

@Override
protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    Class<?> factoryClass = getFactoryClass();
    BeanDefinitionBuilder factoryBean = bean;
    if (!FactoryBean.class.isAssignableFrom(factoryClass)) {
        factoryBean = BeanDefinitionBuilder.rootBeanDefinition(getFactoryClass());
    }
    NamedNodeMap atts = element.getAttributes();
    boolean createdFromAPI = false;
    boolean setBus = false;
    for (int i = 0; i < atts.getLength(); i++) {
        Attr node = (Attr) atts.item(i);
        String val = node.getValue();
        String pre = node.getPrefix();
        String name = node.getLocalName();
        if ("createdFromAPI".equals(name)) {
            factoryBean.setAbstract(true);
            bean.setAbstract(true);
            createdFromAPI = true;
        } else if ("abstract".equals(name)) {
            factoryBean.setAbstract(true);
            bean.setAbstract(true);
        } else if ("depends-on".equals(name)) {
            factoryBean.addDependsOn(val);
            bean.addDependsOn(val);
        } else if (!"id".equals(name) && !"name".equals(name) && isAttribute(pre, name)) {
            if ("bus".equals(name)) {
                setBus = true;
                if (!val.startsWith("#")) {
                    // bus attributes always need to be a reference
                    val = "#" + val;
                }
            }
            mapAttribute(factoryBean, element, name, val);
        }
    }
    if (!setBus) {
        addBusWiringAttribute(factoryBean, BusWiringType.PROPERTY);
    }
    Node node = element.getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String name = node.getLocalName();
            mapElement(ctx, factoryBean, (Element) node, name);
        }
        node = node.getNextSibling();
    }
    String id = getIdOrName(element);
    BeanDefinition container = ctx.getContainingBeanDefinition();
    boolean noFactory = false;
    if (StringUtils.isEmpty(id)) {
        if (container == null) {
            id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), ctx.getRegistry(), false);
        } else {
            id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), ctx.getRegistry(), true);
            noFactory = true;
        // inner bean, no need for the factory to be public at all
        }
    }
    if (createdFromAPI) {
        id = id + getSuffix();
    }
    if (FactoryBean.class.isAssignableFrom(getFactoryClass())) {
        if (!noFactory) {
            AbstractBeanDefinition def = factoryBean.getRawBeanDefinition().cloneBeanDefinition();
            def.setBeanClass(getRawFactoryClass());
            def.setAbstract(factoriesAreAbstract);
            def.setLazyInit(true);
            ctx.getRegistry().registerBeanDefinition(id + getFactoryIdSuffix(), def);
        }
        bean.getBeanDefinition().setAttribute("id", id);
    } else {
        String factoryId = id + getFactoryIdSuffix();
        ctx.getRegistry().registerBeanDefinition(factoryId, factoryBean.getBeanDefinition());
        bean.getRawBeanDefinition().setAttribute("id", id);
        bean.getRawBeanDefinition().setFactoryBeanName(factoryId);
        bean.getRawBeanDefinition().setFactoryMethodName("create");
    }
    if (getDestroyMethod() != null) {
        bean.setDestroyMethodName(getDestroyMethod());
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) NamedNodeMap(org.w3c.dom.NamedNodeMap) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) Node(org.w3c.dom.Node) FactoryBean(org.springframework.beans.factory.FactoryBean) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) Attr(org.w3c.dom.Attr)

Example 53 with AbstractBeanDefinition

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

the class MappingMongoConverterParser method potentiallyCreateMappingContext.

public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext, BeanDefinition conversionsDefinition, String converterId) {
    String ctxRef = element.getAttribute("mapping-context-ref");
    if (StringUtils.hasText(ctxRef)) {
        return ctxRef;
    }
    BeanComponentDefinitionBuilder componentDefinitionBuilder = new BeanComponentDefinitionBuilder(element, parserContext);
    BeanDefinitionBuilder mappingContextBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoMappingContext.class);
    Set<String> classesToAdd = getInititalEntityClasses(element);
    if (classesToAdd != null) {
        mappingContextBuilder.addPropertyValue("initialEntitySet", classesToAdd);
    }
    if (conversionsDefinition != null) {
        AbstractBeanDefinition simpleTypesDefinition = new GenericBeanDefinition();
        simpleTypesDefinition.setFactoryBeanName("customConversions");
        simpleTypesDefinition.setFactoryMethodName("getSimpleTypeHolder");
        mappingContextBuilder.addPropertyValue("simpleTypeHolder", simpleTypesDefinition);
    }
    parseFieldNamingStrategy(element, parserContext.getReaderContext(), mappingContextBuilder);
    ctxRef = converterId == null || DEFAULT_CONVERTER_BEAN_NAME.equals(converterId) ? MAPPING_CONTEXT_BEAN_NAME : converterId + "." + MAPPING_CONTEXT_BEAN_NAME;
    parserContext.registerBeanComponent(componentDefinitionBuilder.getComponent(mappingContextBuilder, ctxRef));
    return ctxRef;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanComponentDefinitionBuilder(org.springframework.data.config.BeanComponentDefinitionBuilder)

Example 54 with AbstractBeanDefinition

use of org.springframework.beans.factory.support.AbstractBeanDefinition 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

AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)54 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)14 Test (org.junit.Test)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)5 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)5 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)4 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)4 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)4 BeanComponentDefinitionBuilder (org.springframework.data.config.BeanComponentDefinitionBuilder)4 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)3 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)3 ArrayList (java.util.ArrayList)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)2 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)2 ChildBeanDefinition (org.springframework.beans.factory.support.ChildBeanDefinition)2