Search in sources :

Example 86 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project dubbo by alibaba.

the class DubboBeanDefinitionParser method parseMultiRef.

@SuppressWarnings("unchecked")
private static void parseMultiRef(String property, String value, RootBeanDefinition beanDefinition, ParserContext parserContext) {
    String[] values = value.split("\\s*[,]+\\s*");
    ManagedList list = null;
    for (int i = 0; i < values.length; i++) {
        String v = values[i];
        if (v != null && v.length() > 0) {
            if (list == null) {
                list = new ManagedList();
            }
            list.add(new RuntimeBeanReference(v));
        }
    }
    beanDefinition.getPropertyValues().addPropertyValue(property, list);
}
Also used : ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 87 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project dubbo by alibaba.

the class DubboBeanDefinitionParser method parseNested.

private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
    NodeList nodeList = element.getChildNodes();
    if (nodeList != null && nodeList.getLength() > 0) {
        boolean first = true;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                if (tag.equals(node.getNodeName()) || tag.equals(node.getLocalName())) {
                    if (first) {
                        first = false;
                        String isDefault = element.getAttribute("default");
                        if (isDefault == null || isDefault.length() == 0) {
                            beanDefinition.getPropertyValues().addPropertyValue("default", "false");
                        }
                    }
                    BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
                    if (subDefinition != null && ref != null && ref.length() > 0) {
                        subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
                    }
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 88 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterParser method parseConverter.

public BeanMetadataElement parseConverter(Element element, ParserContext parserContext) {
    String converterRef = element.getAttribute("ref");
    if (StringUtils.hasText(converterRef)) {
        return new RuntimeBeanReference(converterRef);
    }
    Element beanElement = DomUtils.getChildElementByTagName(element, "bean");
    if (beanElement != null) {
        BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(beanElement);
        beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(beanElement, beanDef);
        return beanDef;
    }
    parserContext.getReaderContext().error("Element <converter> must specify 'ref' or contain a bean definition for the converter", element);
    return null;
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 89 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project cxf by apache.

the class BusWiringBeanFactoryPostProcessor method getBusForName.

private Object getBusForName(String name, ConfigurableListableBeanFactory factory, boolean create, String cn) {
    if (!factory.containsBeanDefinition(name) && (create || Bus.DEFAULT_BUS_ID.equals(name))) {
        DefaultListableBeanFactory df = (DefaultListableBeanFactory) factory;
        RootBeanDefinition rbd = new RootBeanDefinition(SpringBus.class);
        if (cn != null) {
            rbd.setAttribute("busConfig", new RuntimeBeanReference(cn));
        }
        df.registerBeanDefinition(name, rbd);
    } else if (cn != null) {
        BeanDefinition bd = factory.getBeanDefinition(name);
        bd.getPropertyValues().addPropertyValue("busConfig", new RuntimeBeanReference(cn));
    }
    return new RuntimeBeanReference(name);
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 90 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project leopard by tanhaichao.

the class MemdbBeanDefinitionParserTest method parse.

@Test
public void parse() {
    MemdbBeanDefinitionParser beanDefinitionParser = Mockito.spy(new MemdbBeanDefinitionParser());
    Mockito.doReturn("1").when(this.element).getAttribute("maxSize");
    Mockito.doReturn("redis").when(this.element).getAttribute("redis-ref");
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
    beanDefinitionParser.doParse(element, builder);
    RuntimeBeanReference redisReference = (RuntimeBeanReference) builder.getBeanDefinition().getPropertyValues().getPropertyValue("redis").getValue();
    Assert.assertEquals("redis", redisReference.getBeanName());
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Test(org.junit.Test)

Aggregations

RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)156 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)86 Element (org.w3c.dom.Element)47 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)39 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)33 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)32 ManagedList (org.springframework.beans.factory.support.ManagedList)27 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)24 Test (org.junit.Test)21 ManagedMap (org.springframework.beans.factory.support.ManagedMap)20 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)16 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)15 GroovyObject (groovy.lang.GroovyObject)12 TestBean (org.springframework.tests.sample.beans.TestBean)12 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)11 Map (java.util.Map)10 Node (org.w3c.dom.Node)10 HashMap (java.util.HashMap)9 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)8