Search in sources :

Example 51 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class XmlBeanFactoryTests method testAutowireWithParent.

@Test
public void testAutowireWithParent() throws Exception {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT);
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("name", "kerry");
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    bd.setPropertyValues(pvs);
    lbf.registerBeanDefinition("spouse", bd);
    xbf.setParentBeanFactory(lbf);
    doTestAutowire(xbf);
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 52 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class AbstractListenerContainerParser method parseCommonContainerProperties.

protected MutablePropertyValues parseCommonContainerProperties(Element containerEle, ParserContext parserContext) {
    MutablePropertyValues properties = new MutablePropertyValues();
    String destinationType = containerEle.getAttribute(DESTINATION_TYPE_ATTRIBUTE);
    boolean pubSubDomain = false;
    boolean subscriptionDurable = false;
    boolean subscriptionShared = false;
    if (DESTINATION_TYPE_SHARED_DURABLE_TOPIC.equals(destinationType)) {
        pubSubDomain = true;
        subscriptionDurable = true;
        subscriptionShared = true;
    } else if (DESTINATION_TYPE_SHARED_TOPIC.equals(destinationType)) {
        pubSubDomain = true;
        subscriptionShared = true;
    } else if (DESTINATION_TYPE_DURABLE_TOPIC.equals(destinationType)) {
        pubSubDomain = true;
        subscriptionDurable = true;
    } else if (DESTINATION_TYPE_TOPIC.equals(destinationType)) {
        pubSubDomain = true;
    } else if ("".equals(destinationType) || DESTINATION_TYPE_QUEUE.equals(destinationType)) {
    // the default: queue
    } else {
        parserContext.getReaderContext().error("Invalid listener container 'destination-type': only " + "\"queue\", \"topic\", \"durableTopic\", \"sharedTopic\", \"sharedDurableTopic\" supported.", containerEle);
    }
    properties.add("pubSubDomain", pubSubDomain);
    properties.add("subscriptionDurable", subscriptionDurable);
    properties.add("subscriptionShared", subscriptionShared);
    boolean replyPubSubDomain = false;
    String replyDestinationType = containerEle.getAttribute(RESPONSE_DESTINATION_TYPE_ATTRIBUTE);
    if (DESTINATION_TYPE_TOPIC.equals(replyDestinationType)) {
        replyPubSubDomain = true;
    } else if (DESTINATION_TYPE_QUEUE.equals(replyDestinationType)) {
        replyPubSubDomain = false;
    } else if (!StringUtils.hasText(replyDestinationType)) {
        // the default: same value as pubSubDomain
        replyPubSubDomain = pubSubDomain;
    } else if (StringUtils.hasText(replyDestinationType)) {
        parserContext.getReaderContext().error("Invalid listener container 'response-destination-type': only " + "\"queue\", \"topic\" supported.", containerEle);
    }
    properties.add("replyPubSubDomain", replyPubSubDomain);
    if (containerEle.hasAttribute(CLIENT_ID_ATTRIBUTE)) {
        String clientId = containerEle.getAttribute(CLIENT_ID_ATTRIBUTE);
        if (!StringUtils.hasText(clientId)) {
            parserContext.getReaderContext().error("Listener 'client-id' attribute contains empty value.", containerEle);
        }
        properties.add("clientId", clientId);
    }
    if (containerEle.hasAttribute(MESSAGE_CONVERTER_ATTRIBUTE)) {
        String messageConverter = containerEle.getAttribute(MESSAGE_CONVERTER_ATTRIBUTE);
        if (!StringUtils.hasText(messageConverter)) {
            parserContext.getReaderContext().error("listener container 'message-converter' attribute contains empty value.", containerEle);
        } else {
            properties.add("messageConverter", new RuntimeBeanReference(messageConverter));
        }
    }
    return properties;
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 53 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class JcaListenerContainerParser method parseSpecificContainerProperties.

@Override
protected MutablePropertyValues parseSpecificContainerProperties(Element containerEle, ParserContext parserContext) {
    MutablePropertyValues properties = new MutablePropertyValues();
    if (containerEle.hasAttribute(RESOURCE_ADAPTER_ATTRIBUTE)) {
        String resourceAdapterBeanName = containerEle.getAttribute(RESOURCE_ADAPTER_ATTRIBUTE);
        if (!StringUtils.hasText(resourceAdapterBeanName)) {
            parserContext.getReaderContext().error("Listener container 'resource-adapter' attribute contains empty value.", containerEle);
        } else {
            properties.add("resourceAdapter", new RuntimeBeanReference(resourceAdapterBeanName));
        }
    }
    String activationSpecFactoryBeanName = containerEle.getAttribute(ACTIVATION_SPEC_FACTORY_ATTRIBUTE);
    String destinationResolverBeanName = containerEle.getAttribute(DESTINATION_RESOLVER_ATTRIBUTE);
    if (StringUtils.hasText(activationSpecFactoryBeanName)) {
        if (StringUtils.hasText(destinationResolverBeanName)) {
            parserContext.getReaderContext().error("Specify either 'activation-spec-factory' or " + "'destination-resolver', not both. If you define a dedicated JmsActivationSpecFactory bean, " + "specify the custom DestinationResolver there (if possible).", containerEle);
        }
        properties.add("activationSpecFactory", new RuntimeBeanReference(activationSpecFactoryBeanName));
    }
    if (StringUtils.hasText(destinationResolverBeanName)) {
        properties.add("destinationResolver", new RuntimeBeanReference(destinationResolverBeanName));
    }
    String transactionManagerBeanName = containerEle.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE);
    if (StringUtils.hasText(transactionManagerBeanName)) {
        properties.add("transactionManager", new RuntimeBeanReference(transactionManagerBeanName));
    }
    String phase = containerEle.getAttribute(PHASE_ATTRIBUTE);
    if (StringUtils.hasText(phase)) {
        properties.add("phase", phase);
    }
    return properties;
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 54 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class JmsListenerContainerParser method parseSpecificContainerProperties.

@Override
protected MutablePropertyValues parseSpecificContainerProperties(Element containerEle, ParserContext parserContext) {
    MutablePropertyValues properties = new MutablePropertyValues();
    boolean isSimpleContainer = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE).startsWith("simple");
    String connectionFactoryBeanName = "connectionFactory";
    if (containerEle.hasAttribute(CONNECTION_FACTORY_ATTRIBUTE)) {
        connectionFactoryBeanName = containerEle.getAttribute(CONNECTION_FACTORY_ATTRIBUTE);
        if (!StringUtils.hasText(connectionFactoryBeanName)) {
            parserContext.getReaderContext().error("Listener container 'connection-factory' attribute contains empty value.", containerEle);
        }
    }
    if (StringUtils.hasText(connectionFactoryBeanName)) {
        properties.add("connectionFactory", new RuntimeBeanReference(connectionFactoryBeanName));
    }
    String taskExecutorBeanName = containerEle.getAttribute(TASK_EXECUTOR_ATTRIBUTE);
    if (StringUtils.hasText(taskExecutorBeanName)) {
        properties.add("taskExecutor", new RuntimeBeanReference(taskExecutorBeanName));
    }
    String errorHandlerBeanName = containerEle.getAttribute(ERROR_HANDLER_ATTRIBUTE);
    if (StringUtils.hasText(errorHandlerBeanName)) {
        properties.add("errorHandler", new RuntimeBeanReference(errorHandlerBeanName));
    }
    String destinationResolverBeanName = containerEle.getAttribute(DESTINATION_RESOLVER_ATTRIBUTE);
    if (StringUtils.hasText(destinationResolverBeanName)) {
        properties.add("destinationResolver", new RuntimeBeanReference(destinationResolverBeanName));
    }
    String cache = containerEle.getAttribute(CACHE_ATTRIBUTE);
    if (StringUtils.hasText(cache)) {
        if (isSimpleContainer) {
            if (!("auto".equals(cache) || "consumer".equals(cache))) {
                parserContext.getReaderContext().warning("'cache' attribute not actively supported for listener container of type \"simple\". " + "Effective runtime behavior will be equivalent to \"consumer\" / \"auto\".", containerEle);
            }
        } else {
            properties.add("cacheLevelName", "CACHE_" + cache.toUpperCase());
        }
    }
    Integer acknowledgeMode = parseAcknowledgeMode(containerEle, parserContext);
    if (acknowledgeMode != null) {
        if (acknowledgeMode == Session.SESSION_TRANSACTED) {
            properties.add("sessionTransacted", Boolean.TRUE);
        } else {
            properties.add("sessionAcknowledgeMode", acknowledgeMode);
        }
    }
    String transactionManagerBeanName = containerEle.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE);
    if (StringUtils.hasText(transactionManagerBeanName)) {
        if (isSimpleContainer) {
            parserContext.getReaderContext().error("'transaction-manager' attribute not supported for listener container of type \"simple\".", containerEle);
        } else {
            properties.add("transactionManager", new RuntimeBeanReference(transactionManagerBeanName));
        }
    }
    String concurrency = containerEle.getAttribute(CONCURRENCY_ATTRIBUTE);
    if (StringUtils.hasText(concurrency)) {
        properties.add("concurrency", concurrency);
    }
    String prefetch = containerEle.getAttribute(PREFETCH_ATTRIBUTE);
    if (StringUtils.hasText(prefetch)) {
        if (!isSimpleContainer) {
            properties.add("maxMessagesPerTask", prefetch);
        }
    }
    String phase = containerEle.getAttribute(PHASE_ATTRIBUTE);
    if (StringUtils.hasText(phase)) {
        properties.add("phase", phase);
    }
    String receiveTimeout = containerEle.getAttribute(RECEIVE_TIMEOUT_ATTRIBUTE);
    if (StringUtils.hasText(receiveTimeout)) {
        if (!isSimpleContainer) {
            properties.add("receiveTimeout", receiveTimeout);
        }
    }
    String backOffBeanName = containerEle.getAttribute(BACK_OFF_ATTRIBUTE);
    if (StringUtils.hasText(backOffBeanName)) {
        if (!isSimpleContainer) {
            properties.add("backOff", new RuntimeBeanReference(backOffBeanName));
        }
    } else {
        // No need to consider this if back-off is set
        String recoveryInterval = containerEle.getAttribute(RECOVERY_INTERVAL_ATTRIBUTE);
        if (StringUtils.hasText(recoveryInterval)) {
            if (!isSimpleContainer) {
                properties.add("recoveryInterval", recoveryInterval);
            }
        }
    }
    return properties;
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 55 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class StaticApplicationContextTests method createContext.

@Override
protected ConfigurableApplicationContext createContext() throws Exception {
    StaticApplicationContext parent = new StaticApplicationContext();
    Map<String, String> m = new HashMap<>();
    m.put("name", "Roderick");
    parent.registerPrototype("rod", TestBean.class, new MutablePropertyValues(m));
    m.put("name", "Albert");
    parent.registerPrototype("father", TestBean.class, new MutablePropertyValues(m));
    parent.refresh();
    parent.addApplicationListener(parentListener);
    parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1");
    this.sac = new StaticApplicationContext(parent);
    sac.registerSingleton("beanThatListens", BeanThatListens.class, new MutablePropertyValues());
    sac.registerSingleton("aca", ACATester.class, new MutablePropertyValues());
    sac.registerPrototype("aca-prototype", ACATester.class, new MutablePropertyValues());
    PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory());
    reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass()));
    sac.refresh();
    sac.addApplicationListener(listener);
    sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2");
    return sac;
}
Also used : HashMap(java.util.HashMap) PropertiesBeanDefinitionReader(org.springframework.beans.factory.support.PropertiesBeanDefinitionReader) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

MutablePropertyValues (org.springframework.beans.MutablePropertyValues)305 Test (org.junit.Test)269 TestBean (org.springframework.tests.sample.beans.TestBean)86 ITestBean (org.springframework.tests.sample.beans.ITestBean)82 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)73 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)68 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)35 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)24 PropertyEditorSupport (java.beans.PropertyEditorSupport)23 PropertyValue (org.springframework.beans.PropertyValue)16 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)16 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)15 ScannedGenericBeanDefinition (org.springframework.context.annotation.ScannedGenericBeanDefinition)14 HashMap (java.util.HashMap)13 BeanWrapper (org.springframework.beans.BeanWrapper)12 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)11 ParseException (java.text.ParseException)9 RelaxedDataBinder (org.springframework.boot.bind.RelaxedDataBinder)9 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)9