Search in sources :

Example 21 with ManagedList

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

the class AnnotationDrivenBeanDefinitionParser method getCallableInterceptors.

private ManagedList<?> getCallableInterceptors(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, "callable-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)

Example 22 with ManagedList

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

the class AnnotationDrivenBeanDefinitionParser method wrapLegacyResolvers.

private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
    ManagedList<Object> result = new ManagedList<>();
    for (Object object : list) {
        if (object instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
            String className = beanDef.getBeanDefinition().getBeanClassName();
            Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
            if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
                RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
                adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
                result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
                continue;
            }
        }
        result.add(object);
    }
    return result;
}
Also used : BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedList(org.springframework.beans.factory.support.ManagedList)

Example 23 with ManagedList

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

the class AnnotationDrivenBeanDefinitionParser method getMessageConverters.

private ManagedList<?> getMessageConverters(Element element, Object source, ParserContext parserContext) {
    Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
    ManagedList<? super Object> messageConverters = new ManagedList<>();
    if (convertersElement != null) {
        messageConverters.setSource(source);
        for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
            Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
            messageConverters.add(object);
        }
    }
    if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
        messageConverters.setSource(source);
        messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source));
        RootBeanDefinition stringConverterDef = createConverterDefinition(StringHttpMessageConverter.class, source);
        stringConverterDef.getPropertyValues().add("writeAcceptCharset", false);
        messageConverters.add(stringConverterDef);
        messageConverters.add(createConverterDefinition(ResourceHttpMessageConverter.class, source));
        messageConverters.add(createConverterDefinition(SourceHttpMessageConverter.class, source));
        messageConverters.add(createConverterDefinition(AllEncompassingFormHttpMessageConverter.class, source));
        if (romePresent) {
            messageConverters.add(createConverterDefinition(AtomFeedHttpMessageConverter.class, source));
            messageConverters.add(createConverterDefinition(RssChannelHttpMessageConverter.class, source));
        }
        if (jackson2XmlPresent) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2XmlHttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonFactoryDef.getPropertyValues().add("createXmlMapper", true);
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        } else if (jaxb2Present) {
            messageConverters.add(createConverterDefinition(Jaxb2RootElementHttpMessageConverter.class, source));
        }
        if (jackson2Present) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2HttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        } else if (gsonPresent) {
            messageConverters.add(createConverterDefinition(GsonHttpMessageConverter.class, source));
        }
        if (jackson2SmilePresent) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2SmileHttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonFactoryDef.getPropertyValues().add("factory", new SmileFactory());
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        }
        if (jackson2CborPresent) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2CborHttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonFactoryDef.getPropertyValues().add("factory", new CBORFactory());
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        }
    }
    return messageConverters;
}
Also used : SourceHttpMessageConverter(org.springframework.http.converter.xml.SourceHttpMessageConverter) AtomFeedHttpMessageConverter(org.springframework.http.converter.feed.AtomFeedHttpMessageConverter) CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) Element(org.w3c.dom.Element) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) ManagedList(org.springframework.beans.factory.support.ManagedList) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) RssChannelHttpMessageConverter(org.springframework.http.converter.feed.RssChannelHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)

Example 24 with ManagedList

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

the class AnnotationDrivenBeanDefinitionParser method extractBeanRefSubElements.

private ManagedList<BeanReference> extractBeanRefSubElements(Element parentElement, ParserContext parserContext) {
    ManagedList<BeanReference> list = new ManagedList<>();
    list.setSource(parserContext.extractSource(parentElement));
    for (Element refElement : DomUtils.getChildElementsByTagName(parentElement, "ref")) {
        BeanReference reference;
        if (StringUtils.hasText("bean")) {
            reference = new RuntimeBeanReference(refElement.getAttribute("bean"), false);
            list.add(reference);
        } else if (StringUtils.hasText("parent")) {
            reference = new RuntimeBeanReference(refElement.getAttribute("parent"), true);
            list.add(reference);
        } else {
            parserContext.getReaderContext().error("'bean' or 'parent' attribute is required for <ref> element", parserContext.extractSource(parentElement));
        }
    }
    return list;
}
Also used : Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) BeanReference(org.springframework.beans.factory.config.BeanReference) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 25 with ManagedList

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

the class AnnotationDrivenBeanDefinitionParser method extractBeanSubElements.

private ManagedList<Object> extractBeanSubElements(Element parentElement, ParserContext parserContext) {
    ManagedList<Object> list = new ManagedList<>();
    list.setSource(parserContext.extractSource(parentElement));
    for (Element beanElement : DomUtils.getChildElementsByTagName(parentElement, "bean", "ref")) {
        Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
        list.add(object);
    }
    return list;
}
Also used : Element(org.w3c.dom.Element) 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