Search in sources :

Example 46 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method getMessageChannel.

private RuntimeBeanReference getMessageChannel(String name, Element element, ParserContext context, Object source) {
    RootBeanDefinition executor;
    if (element == null) {
        executor = getDefaultExecutorBeanDefinition(name);
    } else {
        Element executorElem = DomUtils.getChildElementByTagName(element, "executor");
        if (executorElem == null) {
            executor = getDefaultExecutorBeanDefinition(name);
        } else {
            executor = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
            if (executorElem.hasAttribute("core-pool-size")) {
                executor.getPropertyValues().add("corePoolSize", executorElem.getAttribute("core-pool-size"));
            }
            if (executorElem.hasAttribute("max-pool-size")) {
                executor.getPropertyValues().add("maxPoolSize", executorElem.getAttribute("max-pool-size"));
            }
            if (executorElem.hasAttribute("keep-alive-seconds")) {
                executor.getPropertyValues().add("keepAliveSeconds", executorElem.getAttribute("keep-alive-seconds"));
            }
            if (executorElem.hasAttribute("queue-capacity")) {
                executor.getPropertyValues().add("queueCapacity", executorElem.getAttribute("queue-capacity"));
            }
        }
    }
    ConstructorArgumentValues argValues = new ConstructorArgumentValues();
    if (executor != null) {
        executor.getPropertyValues().add("threadNamePrefix", name + "-");
        String executorName = name + "Executor";
        registerBeanDefByName(executorName, executor, context, source);
        argValues.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName));
    }
    RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, argValues, null);
    ManagedList<? super Object> interceptors = new ManagedList<>();
    if (element != null) {
        Element interceptorsElement = DomUtils.getChildElementByTagName(element, "interceptors");
        interceptors.addAll(WebSocketNamespaceUtils.parseBeanSubElements(interceptorsElement, context));
    }
    interceptors.add(new ImmutableMessageChannelInterceptor());
    channelDef.getPropertyValues().add("interceptors", interceptors);
    registerBeanDefByName(name, channelDef, context, source);
    return new RuntimeBeanReference(name);
}
Also used : ImmutableMessageChannelInterceptor(org.springframework.messaging.support.ImmutableMessageChannelInterceptor) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 47 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project spring-framework by spring-projects.

the class ComponentBeanDefinitionParser method parseChildComponents.

private static void parseChildComponents(List<Element> childElements, BeanDefinitionBuilder factory) {
    ManagedList<BeanDefinition> children = new ManagedList<>(childElements.size());
    for (Element element : childElements) {
        children.add(parseComponentElement(element));
    }
    factory.addPropertyValue("children", children);
}
Also used : Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition)

Example 48 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project spring-framework by spring-projects.

the class AspectJAutoProxyBeanDefinitionParser method addIncludePatterns.

private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) {
    ManagedList<TypedStringValue> includePatterns = new ManagedList<>();
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node instanceof Element) {
            Element includeElement = (Element) node;
            TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name"));
            valueHolder.setSource(parserContext.extractSource(includeElement));
            includePatterns.add(valueHolder);
        }
    }
    if (!includePatterns.isEmpty()) {
        includePatterns.setSource(parserContext.extractSource(element));
        beanDef.getPropertyValues().add("includePatterns", includePatterns);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) TypedStringValue(org.springframework.beans.factory.config.TypedStringValue)

Example 49 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testPrototypeWithArrayConversionForFactoryMethod.

@Test
public void testPrototypeWithArrayConversionForFactoryMethod() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    List<String> list = new ManagedList<>();
    list.add("myName");
    list.add("myBeanName");
    RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
    bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    bd.setFactoryMethodName("create");
    bd.getConstructorArgumentValues().addGenericArgumentValue(list);
    lbf.registerBeanDefinition("test", bd);
    DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
    assertEquals("myName", tb.getName());
    assertEquals("myBeanName", tb.getBeanName());
    DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
    assertTrue(tb != tb2);
    assertEquals("myName", tb2.getName());
    assertEquals("myBeanName", tb2.getBeanName());
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedList(org.springframework.beans.factory.support.ManagedList) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) Test(org.junit.Test)

Example 50 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project spring-framework by spring-projects.

the class BeanDefinitionParserDelegate method parseListElement.

/**
	 * Parse a list element.
	 */
public List<Object> parseListElement(Element collectionEle, BeanDefinition bd) {
    String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
    NodeList nl = collectionEle.getChildNodes();
    ManagedList<Object> target = new ManagedList<>(nl.getLength());
    target.setSource(extractSource(collectionEle));
    target.setElementTypeName(defaultElementType);
    target.setMergeEnabled(parseMergeAttribute(collectionEle));
    parseCollectionElements(nl, target, bd, defaultElementType);
    return target;
}
Also used : NodeList(org.w3c.dom.NodeList) ManagedList(org.springframework.beans.factory.support.ManagedList)

Aggregations

ManagedList (org.springframework.beans.factory.support.ManagedList)60 Element (org.w3c.dom.Element)37 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)27 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)26 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)20 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)18 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)10 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)10 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 Node (org.w3c.dom.Node)6 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)5 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 GroovyObject (groovy.lang.GroovyObject)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BeanReference (org.springframework.beans.factory.config.BeanReference)3 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)3 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)3 ManagedMap (org.springframework.beans.factory.support.ManagedMap)3