Search in sources :

Example 26 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 27 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)

Example 28 with ValueHolder

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

the class InjectedConstructionResolver method resolve.

@Override
public InjectedElementAttributes resolve(DefaultListableBeanFactory beanFactory, boolean required) {
    int argumentCount = this.executable.getParameterCount();
    List<Object> arguments = new ArrayList<>();
    Set<String> autowiredBeans = new LinkedHashSet<>(argumentCount);
    TypeConverter typeConverter = beanFactory.getTypeConverter();
    ConstructorArgumentValues argumentValues = resolveArgumentValues(beanFactory);
    for (int i = 0; i < argumentCount; i++) {
        MethodParameter methodParam = createMethodParameter(i);
        ValueHolder valueHolder = argumentValues.getIndexedArgumentValue(i, null);
        if (valueHolder != null) {
            if (valueHolder.isConverted()) {
                arguments.add(valueHolder.getConvertedValue());
            } else {
                Object userValue = beanFactory.getTypeConverter().convertIfNecessary(valueHolder.getValue(), methodParam.getParameterType());
                arguments.add(userValue);
            }
        } else {
            DependencyDescriptor depDescriptor = new DependencyDescriptor(methodParam, true);
            depDescriptor.setContainingClass(this.targetType);
            try {
                Object arg = resolveDependency(() -> beanFactory.resolveDependency(depDescriptor, this.beanName, autowiredBeans, typeConverter), methodParam.getParameterType());
                arguments.add(arg);
            } catch (BeansException ex) {
                throw new UnsatisfiedDependencyException(null, this.beanName, new InjectionPoint(methodParam), ex);
            }
        }
    }
    return new InjectedElementAttributes(arguments);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) InjectionPoint(org.springframework.beans.factory.InjectionPoint) ArrayList(java.util.ArrayList) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) InjectionPoint(org.springframework.beans.factory.InjectionPoint) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) TypeConverter(org.springframework.beans.TypeConverter) UnsatisfiedDependencyException(org.springframework.beans.factory.UnsatisfiedDependencyException) MethodParameter(org.springframework.core.MethodParameter) BeansException(org.springframework.beans.BeansException)

Example 29 with ValueHolder

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

the class RepositoryBeanNameGenerator method getRepositoryInterfaceFrom.

/**
 * Returns the type configured for the {@code repositoryInterface} property of the given bean definition. Uses a
 * potential {@link Class} being configured as is or tries to load a class with the given value's {@link #toString()}
 * representation.
 *
 * @param beanDefinition
 * @return
 */
private Class<?> getRepositoryInterfaceFrom(BeanDefinition beanDefinition) {
    ValueHolder argumentValue = beanDefinition.getConstructorArgumentValues().getArgumentValue(0, Class.class);
    if (argumentValue == null) {
        throw new IllegalStateException(String.format("Failed to obtain first constructor parameter value of BeanDefinition %s!", beanDefinition));
    }
    Object value = argumentValue.getValue();
    if (value == null) {
        throw new IllegalStateException(String.format("Value of first constructor parameter value of BeanDefinition %s is null!", beanDefinition));
    } else if (value instanceof Class<?>) {
        return (Class<?>) value;
    } else {
        try {
            return ClassUtils.forName(value.toString(), beanClassLoader);
        } catch (Exception o_O) {
            throw new RuntimeException(o_O);
        }
    }
}
Also used : ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)

Example 30 with ValueHolder

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

the class InjectedConstructionResolver method resolve.

@Override
public InjectedElementAttributes resolve(DefaultListableBeanFactory beanFactory, boolean required) {
    int argumentCount = this.executable.getParameterCount();
    List<Object> arguments = new ArrayList<>();
    Set<String> autowiredBeans = new LinkedHashSet<>(argumentCount);
    TypeConverter typeConverter = beanFactory.getTypeConverter();
    ConstructorArgumentValues argumentValues = resolveArgumentValues(beanFactory);
    for (int i = 0; i < argumentCount; i++) {
        MethodParameter methodParam = createMethodParameter(i);
        ValueHolder valueHolder = argumentValues.getIndexedArgumentValue(i, null);
        if (valueHolder != null) {
            if (valueHolder.isConverted()) {
                arguments.add(valueHolder.getConvertedValue());
            } else {
                Object userValue = beanFactory.getTypeConverter().convertIfNecessary(valueHolder.getValue(), methodParam.getParameterType());
                arguments.add(userValue);
            }
        } else {
            DependencyDescriptor depDescriptor = new DependencyDescriptor(methodParam, true);
            depDescriptor.setContainingClass(this.targetType);
            try {
                Object arg = resolveDependency(() -> beanFactory.resolveDependency(depDescriptor, beanName, autowiredBeans, typeConverter), methodParam.getParameterType());
                arguments.add(arg);
            } catch (BeansException ex) {
                throw new UnsatisfiedDependencyException(null, beanName, new InjectionPoint(methodParam), ex);
            }
        }
    }
    return new InjectedElementAttributes(arguments);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DependencyDescriptor(org.springframework.beans.factory.config.DependencyDescriptor) InjectionPoint(org.springframework.beans.factory.InjectionPoint) ArrayList(java.util.ArrayList) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) InjectionPoint(org.springframework.beans.factory.InjectionPoint) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) TypeConverter(org.springframework.beans.TypeConverter) UnsatisfiedDependencyException(org.springframework.beans.factory.UnsatisfiedDependencyException) MethodParameter(org.springframework.core.MethodParameter) BeansException(org.springframework.beans.BeansException)

Aggregations

ValueHolder (org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)50 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)34 BeansException (org.springframework.beans.BeansException)13 InjectionPoint (org.springframework.beans.factory.InjectionPoint)13 LinkedHashSet (java.util.LinkedHashSet)12 TypeConverter (org.springframework.beans.TypeConverter)10 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)10 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)10 TypeMismatchException (org.springframework.beans.TypeMismatchException)8 BeanCreationException (org.springframework.beans.factory.BeanCreationException)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)7 MethodParameter (org.springframework.core.MethodParameter)7 Attr (org.w3c.dom.Attr)6 Set (java.util.Set)5 Test (org.junit.jupiter.api.Test)5 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)5 ParameterNameDiscoverer (org.springframework.core.ParameterNameDiscoverer)5