Search in sources :

Example 16 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project redisson by redisson.

the class RedissonLiveObjectDefinitionParser method parseNested.

@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    Class<?> apiClass;
    try {
        apiClass = Class.forName(helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE));
    } catch (ClassNotFoundException ex) {
        throw new IllegalArgumentException("The class [" + helper.getAttribute(element, RedissonNamespaceParserSupport.CLASS_ATTRIBUTE) + "] specified in \"api-class\" attribute has not " + "found. Please check the class path.", ex);
    }
    Assert.state(helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE) || helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE), "One of \"" + RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE + "\" or \"" + RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE + "\" attribute is required in the \"" + RedissonNamespaceParserSupport.LIVE_OBJECT_ELEMENT + "\" element.");
    builder.addPropertyValue("targetObject", new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.LIVE_OBJECT_SERVICE_REF_ATTRIBUTE)));
    builder.addPropertyValue("targetMethod", "get");
    ManagedList args = new ManagedList();
    args.add(apiClass);
    if (helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE)) {
        args.add(helper.getAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_ATTRIBUTE));
    }
    if (helper.hasAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE)) {
        args.add(new RuntimeBeanReference(helper.getAttribute(element, RedissonNamespaceParserSupport.OBJECT_ID_REF_ATTRIBUTE)));
    }
    builder.addPropertyValue("arguments", args);
}
Also used : ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 17 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project redisson by redisson.

the class RedissonMultiLockDefinitionParser method parseNested.

@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setDependsOn(element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
    List<Element> childElements = DomUtils.getChildElements(element);
    for (Element elt : childElements) {
        String localName = elt.getLocalName();
        if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(localName)) {
            //parsed elsewhere
            continue;
        }
        String id;
        if (BeanDefinitionParserDelegate.REF_ELEMENT.equals(localName)) {
            id = elt.getAttribute(BeanDefinitionParserDelegate.BEAN_REF_ATTRIBUTE);
        } else {
            if (!elt.hasAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE)) {
                helper.setAttribute(elt, RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE, element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
            }
            helper.populateIdAttribute(elt, builder, parserContext);
            parserContext.getDelegate().parseCustomElement(elt, bd);
            id = elt.getAttribute(RedissonNamespaceParserSupport.ID_ATTRIBUTE);
        }
        ConstructorArgumentValues args = builder.getRawBeanDefinition().getConstructorArgumentValues();
        if (args.getArgumentCount() > 0) {
            ConstructorArgumentValues.ValueHolder value = args.getIndexedArgumentValues().get(0);
            ManagedList list;
            if (value.getValue() instanceof ManagedList) {
                list = (ManagedList) value.getValue();
            } else {
                list = new ManagedList();
                list.add(value.getValue());
                value.setValue(list);
                value.setType(ManagedList.class.getName());
            }
            list.add(new RuntimeBeanReference(id));
        } else {
            builder.addConstructorArgReference(id);
        }
    }
}
Also used : Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 18 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project sharding-jdbc by dangdangdotcom.

the class ShardingJdbcDataSourceBeanDefinitionParser method parseBindingTablesConfig.

private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
    Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
    if (null == bindingTableRulesElement) {
        return Collections.emptyList();
    }
    List<Element> bindingTableRuleElements = DomUtils.getChildElementsByTagName(bindingTableRulesElement, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULE_TAG);
    BeanDefinitionBuilder bindingTableRuleFactory = BeanDefinitionBuilder.rootBeanDefinition(BindingTableRuleConfig.class);
    List<BeanDefinition> result = new ManagedList<>(bindingTableRuleElements.size());
    for (Element bindingTableRuleElement : bindingTableRuleElements) {
        bindingTableRuleFactory.addPropertyValue("tableNames", bindingTableRuleElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLES_ATTRIBUTE));
        result.add(bindingTableRuleFactory.getBeanDefinition());
    }
    return result;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 19 with ManagedList

use of org.springframework.beans.factory.support.ManagedList in project elastic-job by dangdangdotcom.

the class AbstractJobBeanDefinitionParser method createJobListeners.

private List<BeanDefinition> createJobListeners(final Element element) {
    Element listenerElement = DomUtils.getChildElementByTagName(element, LISTENER_TAG);
    Element distributedListenerElement = DomUtils.getChildElementByTagName(element, DISTRIBUTED_LISTENER_TAG);
    List<BeanDefinition> result = new ManagedList<>(2);
    if (null != listenerElement) {
        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(listenerElement.getAttribute(CLASS_ATTRIBUTE));
        factory.setScope(BeanDefinition.SCOPE_PROTOTYPE);
        result.add(factory.getBeanDefinition());
    }
    if (null != distributedListenerElement) {
        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(distributedListenerElement.getAttribute(CLASS_ATTRIBUTE));
        factory.setScope(BeanDefinition.SCOPE_PROTOTYPE);
        factory.addConstructorArgValue(distributedListenerElement.getAttribute(DISTRIBUTED_LISTENER_STARTED_TIMEOUT_MILLISECONDS_ATTRIBUTE));
        factory.addConstructorArgValue(distributedListenerElement.getAttribute(DISTRIBUTED_LISTENER_COMPLETED_TIMEOUT_MILLISECONDS_ATTRIBUTE));
        result.add(factory.getBeanDefinition());
    }
    return result;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 20 with ManagedList

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

the class AnnotationDrivenBeanDefinitionParser method getDeferredResultInterceptors.

private ManagedList<?> getDeferredResultInterceptors(Element element, Object source, ParserContext parserContext) {
    ManagedList<? super Object> interceptors = new ManagedList<>();
    Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
    if (asyncElement != null) {
        Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "deferred-result-interceptors");
        if (interceptorsElement != null) {
            interceptors.setSource(source);
            for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
                BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(converter);
                beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
                interceptors.add(beanDef);
            }
        }
    }
    return interceptors;
}
Also used : Element(org.w3c.dom.Element) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) 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