Search in sources :

Example 16 with ValueHolder

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

the class AbstractConsumerEndpointParser method registerChannelForCreation.

private void registerChannelForCreation(ParserContext parserContext, String inputChannelName) {
    if (parserContext.getRegistry().containsBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)) {
        BeanDefinition channelRegistry = parserContext.getRegistry().getBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME);
        ConstructorArgumentValues caValues = channelRegistry.getConstructorArgumentValues();
        ValueHolder vh = caValues.getArgumentValue(0, Collection.class);
        if (vh == null) {
            // although it should never happen if it does we can fix it
            caValues.addIndexedArgumentValue(0, new ManagedSet<String>());
        }
        @SuppressWarnings("unchecked") Collection<String> channelCandidateNames = (Collection<String>) caValues.getArgumentValue(0, Collection.class).getValue();
        // NOSONAR
        channelCandidateNames.add(inputChannelName);
    } else {
        parserContext.getReaderContext().error("Failed to locate '" + IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME + "'", parserContext.getRegistry());
    }
}
Also used : Collection(java.util.Collection) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 17 with ValueHolder

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);
    }
}
Also used : ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)

Example 18 with ValueHolder

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);
    }
}
Also used : TreeSet(java.util.TreeSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)

Example 19 with ValueHolder

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

the class MongoDbFactoryParserIntegrationTests method setsUpMongoDbFactoryUsingAMongoUriWithoutCredentials.

// DATAMONGO-306
@Test
public void setsUpMongoDbFactoryUsingAMongoUriWithoutCredentials() {
    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongo-uri-no-credentials.xml"));
    BeanDefinition definition = factory.getBeanDefinition("mongoDbFactory");
    ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();
    assertThat(constructorArguments.getArgumentCount()).isOne();
    ValueHolder argument = constructorArguments.getArgumentValue(0, ConnectionString.class);
    assertThat(argument).isNotNull();
    MongoDatabaseFactory dbFactory = factory.getBean("mongoDbFactory", MongoDatabaseFactory.class);
    MongoDatabase db = dbFactory.getMongoDatabase();
    assertThat(db.getName()).isEqualTo("database");
}
Also used : MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) ClassPathResource(org.springframework.core.io.ClassPathResource) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.jupiter.api.Test)

Example 20 with ValueHolder

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

the class MongoDbFactoryParserIntegrationTests method setsUpClientUriWithId.

// DATAMONGO-1293
@Test
public void setsUpClientUriWithId() {
    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongo-client-uri-and-id.xml"));
    BeanDefinition definition = factory.getBeanDefinition("testMongo");
    ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();
    assertThat(constructorArguments.getArgumentCount()).isOne();
    ValueHolder argument = constructorArguments.getArgumentValue(0, ConnectionString.class);
    assertThat(argument).isNotNull();
}
Also used : BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder) ClassPathResource(org.springframework.core.io.ClassPathResource) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Test(org.junit.jupiter.api.Test)

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