use of org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder in project spring-integration by spring-projects.
the class MqttParserUtils method parseCommon.
static void parseCommon(Element element, BeanDefinitionBuilder builder, ParserContext parserContext) {
ValueHolder holder;
int n = 0;
String url = element.getAttribute("url");
if (StringUtils.hasText(url)) {
builder.addConstructorArgValue(url);
holder = builder.getRawBeanDefinition().getConstructorArgumentValues().getIndexedArgumentValues().get(n++);
holder.setType("java.lang.String");
}
builder.addConstructorArgValue(element.getAttribute("client-id"));
holder = builder.getRawBeanDefinition().getConstructorArgumentValues().getIndexedArgumentValues().get(n);
holder.setType("java.lang.String");
String clientFactory = element.getAttribute("client-factory");
if (StringUtils.hasText(clientFactory)) {
builder.addConstructorArgReference(clientFactory);
} else {
if (!StringUtils.hasText(url)) {
parserContext.getReaderContext().error("If no 'url' attribute is provided, a 'client-factory' " + "(with serverURIs) is required", element);
}
builder.addConstructorArgValue(new RootBeanDefinition(DefaultMqttPahoClientFactory.class));
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "converter");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
}
use of org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder in project spock by spockframework.
the class SpockMockPostprocessor method register.
/**
* Register the processor with a {@link BeanDefinitionRegistry}. Not required when
* using the Spocks {@link spock.lang.Specification} as registration is automatic.
*
* @param registry the bean definition registry
* @param postProcessor the post processor class to register
* @param definitions the initial mock/spy definitions
*/
@SuppressWarnings("unchecked")
static void register(BeanDefinitionRegistry registry, Class<? extends SpockMockPostprocessor> postProcessor, Set<Definition> definitions) {
SpyPostProcessor.register(registry);
BeanDefinition definition = getOrAddBeanDefinition(registry, postProcessor);
ValueHolder constructorArg = definition.getConstructorArgumentValues().getIndexedArgumentValue(0, Set.class);
Set<Definition> existing = (Set<Definition>) constructorArg.getValue();
if (definitions != null) {
existing.addAll(definitions);
}
}
use of org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder in project spring-boot by spring-projects.
the class MockitoPostProcessor method register.
/**
* Register the processor with a {@link BeanDefinitionRegistry}. Not required when
* using the {@link SpringRunner} as registration is automatic.
* @param registry the bean definition registry
* @param postProcessor the post processor class to register
* @param definitions the initial mock/spy definitions
*/
@SuppressWarnings("unchecked")
public static void register(BeanDefinitionRegistry registry, Class<? extends MockitoPostProcessor> postProcessor, Set<Definition> definitions) {
SpyPostProcessor.register(registry);
BeanDefinition definition = getOrAddBeanDefinition(registry, postProcessor);
ValueHolder constructorArg = definition.getConstructorArgumentValues().getIndexedArgumentValue(0, Set.class);
Set<Definition> existing = (Set<Definition>) constructorArg.getValue();
if (definitions != null) {
existing.addAll(definitions);
}
}
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);
}
use of org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder in project spring-native by spring-projects-experimental.
the class InjectedConstructionResolver method resolveArgumentValues.
private ConstructorArgumentValues resolveArgumentValues(DefaultListableBeanFactory beanFactory) {
ConstructorArgumentValues resolvedValues = new ConstructorArgumentValues();
BeanDefinition beanDefinition = this.beanDefinitionResolver.apply(beanFactory);
if (beanDefinition == null || !beanDefinition.hasConstructorArgumentValues()) {
return resolvedValues;
}
ConstructorArgumentValues argumentValues = beanDefinition.getConstructorArgumentValues();
ValueResolver valueResolver = BeanDefinitionValueResolverAccessor.get(beanFactory, this.beanName, beanDefinition);
for (Map.Entry<Integer, ConstructorArgumentValues.ValueHolder> entry : argumentValues.getIndexedArgumentValues().entrySet()) {
int index = entry.getKey();
ConstructorArgumentValues.ValueHolder valueHolder = entry.getValue();
if (valueHolder.isConverted()) {
resolvedValues.addIndexedArgumentValue(index, valueHolder);
} else {
Object resolvedValue = valueResolver.resolveValueIfNecessary("constructor argument", valueHolder.getValue());
ConstructorArgumentValues.ValueHolder resolvedValueHolder = new ConstructorArgumentValues.ValueHolder(resolvedValue, valueHolder.getType(), valueHolder.getName());
resolvedValueHolder.setSource(valueHolder);
resolvedValues.addIndexedArgumentValue(index, resolvedValueHolder);
}
}
return resolvedValues;
}
Aggregations