Search in sources :

Example 21 with ValueHolder

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

the class BusWiringBeanFactoryPostProcessor method insertConstructorArg.

/**
 * Insert the given value as the first constructor argument in the given set. To do this, we clear the
 * argument set, then re-insert all its generic arguments, then re-insert all its indexed arguments with
 * their indices incremented by 1, and finally set the first indexed argument (at index 0) to the given
 * value.
 *
 * @param constructorArgs the argument definition to modify.
 * @param valueToInsert the value to insert as the first argument.
 */
private void insertConstructorArg(ConstructorArgumentValues constructorArgs, Object valueToInsert) {
    List<ValueHolder> genericArgs = new ArrayList<>(CastUtils.<ValueHolder>cast(constructorArgs.getGenericArgumentValues()));
    Map<Integer, ValueHolder> indexedArgs = new HashMap<>(CastUtils.<Integer, ValueHolder>cast(constructorArgs.getIndexedArgumentValues()));
    constructorArgs.clear();
    for (ValueHolder genericValue : genericArgs) {
        constructorArgs.addGenericArgumentValue(genericValue);
    }
    for (Map.Entry<Integer, ValueHolder> entry : indexedArgs.entrySet()) {
        constructorArgs.addIndexedArgumentValue(entry.getKey() + 1, entry.getValue());
    }
    constructorArgs.addIndexedArgumentValue(0, valueToInsert);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with ValueHolder

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

the class UndertowHTTPServerEngineBeanDefinitionParser method doParse.

public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    String portStr = element.getAttribute("port");
    bean.addPropertyValue("port", portStr);
    String hostStr = element.getAttribute("host");
    if (hostStr != null && !"".equals(hostStr.trim())) {
        bean.addPropertyValue("host", hostStr);
    }
    String continuationsStr = element.getAttribute("continuationsEnabled");
    if (continuationsStr != null && continuationsStr.length() > 0) {
        bean.addPropertyValue("continuationsEnabled", continuationsStr);
    }
    String maxIdleTimeStr = element.getAttribute("maxIdleTime");
    if (maxIdleTimeStr != null && !"".equals(maxIdleTimeStr.trim())) {
        bean.addPropertyValue("maxIdleTime", maxIdleTimeStr);
    }
    ValueHolder busValue = ctx.getContainingBeanDefinition().getConstructorArgumentValues().getArgumentValue(0, Bus.class);
    bean.addPropertyValue("bus", busValue.getValue());
    try {
        Element elem = DOMUtils.getFirstElement(element);
        while (elem != null) {
            String name = elem.getLocalName();
            if ("tlsServerParameters".equals(name)) {
                mapTLSServerParameters(elem, bean);
            } else if ("threadingParameters".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "threadingParameters", ThreadingParametersType.class, UndertowHTTPServerEngineBeanDefinitionParser.class, "createThreadingParameters");
            } else if ("tlsServerParametersRef".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "tlsServerParametersRef", TLSServerParametersIdentifiedType.class, UndertowHTTPServerEngineBeanDefinitionParser.class, "createTLSServerParametersConfigRef");
            } else if ("threadingParametersRef".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "threadingParametersRef", ThreadingParametersIdentifiedType.class, UndertowHTTPServerEngineBeanDefinitionParser.class, "createThreadingParametersRef");
            } else if ("handlers".equals(name)) {
                List<?> handlers = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition());
                bean.addPropertyValue("handlers", handlers);
            }
            elem = org.apache.cxf.helpers.DOMUtils.getNextElement(elem);
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not process configuration.", e);
    }
    bean.setLazyInit(false);
}
Also used : ThreadingParametersType(org.apache.cxf.transports.http_undertow.configuration.ThreadingParametersType) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_undertow.configuration.ThreadingParametersIdentifiedType) Element(org.w3c.dom.Element) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException)

Example 23 with ValueHolder

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

the class NettyHttpServerEngineBeanDefinitionParser method doParse.

public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    String portStr = element.getAttribute("port");
    bean.addPropertyValue("port", portStr);
    String hostStr = element.getAttribute("host");
    if (hostStr != null && !"".equals(hostStr.trim())) {
        bean.addPropertyValue("host", hostStr);
    }
    String readIdleTimeStr = element.getAttribute("readIdleTime");
    if (readIdleTimeStr != null && !"".equals(readIdleTimeStr.trim())) {
        bean.addPropertyValue("readIdleTime", readIdleTimeStr);
    }
    String writeIdleTimeStr = element.getAttribute("writeIdleTime");
    if (writeIdleTimeStr != null && !"".equals(writeIdleTimeStr.trim())) {
        bean.addPropertyValue("writeIdleTime", writeIdleTimeStr);
    }
    String maxChunkContentSizeStr = element.getAttribute("maxChunkContentSize");
    if (maxChunkContentSizeStr != null && !"".equals(maxChunkContentSizeStr.trim())) {
        bean.addPropertyValue("maxChunkContentSize", maxChunkContentSizeStr);
    }
    ValueHolder busValue = ctx.getContainingBeanDefinition().getConstructorArgumentValues().getArgumentValue(0, Bus.class);
    bean.addPropertyValue("bus", busValue.getValue());
    try {
        Element elem = DOMUtils.getFirstElement(element);
        while (elem != null) {
            String name = elem.getLocalName();
            if ("tlsServerParameters".equals(name)) {
                mapTLSServerParameters(elem, bean);
            } else if ("tlsServerParametersRef".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "tlsServerParametersRef", TLSServerParametersIdentifiedType.class, NettyHttpServerEngineBeanDefinitionParser.class, "createTLSServerParametersConfigRef");
            } else if ("threadingParameters".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "threadingParameters", ThreadingParametersType.class, NettyHttpServerEngineBeanDefinitionParser.class, "createThreadingParameters");
            } else if ("threadingParametersRef".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "threadingParametersRef", ThreadingParametersIdentifiedType.class, NettyHttpServerEngineBeanDefinitionParser.class, "createThreadingParametersRef");
            } else if ("sessionSupport".equals(name) || "reuseAddress".equals(name)) {
                String text = elem.getTextContent();
                bean.addPropertyValue(name, text);
            }
            elem = org.apache.cxf.helpers.DOMUtils.getNextElement(elem);
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not process configuration.", e);
    }
    bean.setLazyInit(false);
}
Also used : ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_netty_server.configuration.ThreadingParametersIdentifiedType) Element(org.w3c.dom.Element) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_netty_server.configuration.TLSServerParametersIdentifiedType)

Example 24 with ValueHolder

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

the class JettyHTTPServerEngineBeanDefinitionParser method doParse.

public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    String portStr = element.getAttribute("port");
    bean.addPropertyValue("port", portStr);
    String hostStr = element.getAttribute("host");
    if (hostStr != null && !"".equals(hostStr.trim())) {
        bean.addPropertyValue("host", hostStr);
    }
    String continuationsStr = element.getAttribute("continuationsEnabled");
    if (continuationsStr != null && continuationsStr.length() > 0) {
        bean.addPropertyValue("continuationsEnabled", continuationsStr);
    }
    String maxIdleTimeStr = element.getAttribute("maxIdleTime");
    if (maxIdleTimeStr != null && !"".equals(maxIdleTimeStr.trim())) {
        bean.addPropertyValue("maxIdleTime", maxIdleTimeStr);
    }
    String sendServerVersionStr = element.getAttribute("sendServerVersion");
    if (sendServerVersionStr != null && sendServerVersionStr.length() > 0) {
        bean.addPropertyValue("sendServerVersion", sendServerVersionStr);
    }
    ValueHolder busValue = ctx.getContainingBeanDefinition().getConstructorArgumentValues().getArgumentValue(0, Bus.class);
    bean.addPropertyValue("bus", busValue.getValue());
    try {
        Element elem = DOMUtils.getFirstElement(element);
        while (elem != null) {
            String name = elem.getLocalName();
            if ("tlsServerParameters".equals(name)) {
                mapTLSServerParameters(elem, bean);
            } else if ("threadingParameters".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "threadingParameters", ThreadingParametersType.class, JettyHTTPServerEngineBeanDefinitionParser.class, "createThreadingParameters");
            } else if ("tlsServerParametersRef".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "tlsServerParametersRef", TLSServerParametersIdentifiedType.class, JettyHTTPServerEngineBeanDefinitionParser.class, "createTLSServerParametersConfigRef");
            } else if ("threadingParametersRef".equals(name)) {
                mapElementToJaxbPropertyFactory(elem, bean, "threadingParametersRef", ThreadingParametersIdentifiedType.class, JettyHTTPServerEngineBeanDefinitionParser.class, "createThreadingParametersRef");
            } else if ("connector".equals(name)) {
                // only deal with the one connector here
                List<?> list = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition());
                bean.addPropertyValue("connector", list.get(0));
            } else if ("handlers".equals(name)) {
                List<?> handlers = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition());
                bean.addPropertyValue("handlers", handlers);
            } else if ("sessionTimeout".equals(name) || "sessionSupport".equals(name) || "reuseAddress".equals(name)) {
                String text = elem.getTextContent();
                bean.addPropertyValue(name, text);
            }
            elem = org.apache.cxf.helpers.DOMUtils.getNextElement(elem);
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not process configuration.", e);
    }
    bean.setLazyInit(false);
}
Also used : ThreadingParametersType(org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersType) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersIdentifiedType) Element(org.w3c.dom.Element) List(java.util.List) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException)

Example 25 with ValueHolder

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

the class ServletComponentScanRegistrar method updatePostProcessor.

private void updatePostProcessor(BeanDefinitionRegistry registry, Set<String> packagesToScan) {
    BeanDefinition definition = registry.getBeanDefinition(BEAN_NAME);
    ValueHolder constructorArguments = definition.getConstructorArgumentValues().getGenericArgumentValue(Set.class);
    @SuppressWarnings("unchecked") Set<String> mergedPackages = (Set<String>) constructorArguments.getValue();
    mergedPackages.addAll(packagesToScan);
    constructorArguments.setValue(mergedPackages);
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)

Aggregations

ValueHolder (org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)41 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)26 BeansException (org.springframework.beans.BeansException)11 LinkedHashSet (java.util.LinkedHashSet)10 InjectionPoint (org.springframework.beans.factory.InjectionPoint)10 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)10 TypeConverter (org.springframework.beans.TypeConverter)8 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)8 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 TypeMismatchException (org.springframework.beans.TypeMismatchException)6 BeanCreationException (org.springframework.beans.factory.BeanCreationException)6 MethodParameter (org.springframework.core.MethodParameter)6 HashSet (java.util.HashSet)5 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)5 Set (java.util.Set)4 Test (org.junit.jupiter.api.Test)4 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 ParameterNameDiscoverer (org.springframework.core.ParameterNameDiscoverer)4