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);
}
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);
}
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);
}
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);
}
}
}
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);
}
Aggregations