Search in sources :

Example 31 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerMessageConverter.

private RuntimeBeanReference registerMessageConverter(Element element, ParserContext context, Object source) {
    Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
    ManagedList<? super Object> converters = new ManagedList<>();
    if (convertersElement != null) {
        converters.setSource(source);
        for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
            Object object = context.getDelegate().parsePropertySubElement(beanElement, null);
            converters.add(object);
        }
    }
    if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
        converters.setSource(source);
        converters.add(new RootBeanDefinition(StringMessageConverter.class));
        converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
        if (jackson2Present) {
            RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class);
            RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
            resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
            jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef);
            // Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically
            GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition();
            jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
            jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
            jacksonFactoryDef.setSource(source);
            jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef);
            converters.add(jacksonConverterDef);
        }
    }
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addIndexedArgumentValue(0, converters);
    RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cavs, null);
    String name = MESSAGE_CONVERTER_BEAN_NAME;
    registerBeanDefByName(name, messageConverterDef, context, source);
    return new RuntimeBeanReference(name);
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) ByteArrayMessageConverter(org.springframework.messaging.converter.ByteArrayMessageConverter) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 32 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerMessagingTemplate.

private RuntimeBeanReference registerMessagingTemplate(Element element, RuntimeBeanReference brokerChannel, RuntimeBeanReference messageConverter, ParserContext context, Object source) {
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addIndexedArgumentValue(0, brokerChannel);
    RootBeanDefinition beanDef = new RootBeanDefinition(SimpMessagingTemplate.class, cavs, null);
    if (element.hasAttribute("user-destination-prefix")) {
        beanDef.getPropertyValues().add("userDestinationPrefix", element.getAttribute("user-destination-prefix"));
    }
    beanDef.getPropertyValues().add("messageConverter", messageConverter);
    String name = MESSAGING_TEMPLATE_BEAN_NAME;
    registerBeanDefByName(name, beanDef, context, source);
    return new RuntimeBeanReference(name);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 33 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues 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 34 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project redisson by redisson.

the class RedissonNamespaceParserSupport method addConstructorArgs.

public void addConstructorArgs(Object value, Class type, BeanDefinition bd) {
    ConstructorArgumentValues.ValueHolder vHolder = new ConstructorArgumentValues.ValueHolder(value, type.getName());
    ConstructorArgumentValues args = bd.getConstructorArgumentValues();
    args.addIndexedArgumentValue(args.getArgumentCount(), vHolder);
}
Also used : ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 35 with ConstructorArgumentValues

use of org.springframework.beans.factory.config.ConstructorArgumentValues in project hudson-2.x by hudson.

the class DefaultBeanConfiguration method createBeanDefinition.

protected AbstractBeanDefinition createBeanDefinition() {
    AbstractBeanDefinition bd;
    if (constructorArgs.size() > 0) {
        ConstructorArgumentValues cav = new ConstructorArgumentValues();
        for (Object constructorArg : constructorArgs) {
            cav.addGenericArgumentValue(constructorArg);
        }
        if (StringUtils.isBlank(parentName)) {
            bd = new RootBeanDefinition(clazz, cav, null);
        } else {
            bd = new ChildBeanDefinition(parentName, clazz, cav, null);
        }
        bd.setSingleton(singleton);
    } else {
        if (StringUtils.isBlank(parentName)) {
            bd = new RootBeanDefinition(clazz, singleton);
        } else {
            bd = new ChildBeanDefinition(parentName, clazz, null, null);
            bd.setSingleton(singleton);
        }
    }
    wrapper = new BeanWrapperImpl(bd);
    return bd;
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(org.springframework.beans.factory.support.ChildBeanDefinition) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Aggregations

ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)96 Test (org.junit.Test)63 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)50 BeanCreationException (org.springframework.beans.factory.BeanCreationException)23 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)20 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)15 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)14 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)9 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)9 ValueHolder (org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)8 DependencyDescriptor (org.springframework.beans.factory.config.DependencyDescriptor)8 Element (org.w3c.dom.Element)8 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)7 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)6 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5 LinkedHashSet (java.util.LinkedHashSet)4 InjectionPoint (org.springframework.beans.factory.InjectionPoint)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 ManagedList (org.springframework.beans.factory.support.ManagedList)4 MethodParameter (org.springframework.core.MethodParameter)4