Search in sources :

Example 1 with PropertyValue

use of org.springframework.beans.PropertyValue in project hudson-2.x by hudson.

the class DefaultRuntimeSpringConfiguration method registerBeansWithContext.

public void registerBeansWithContext(StaticApplicationContext applicationContext) {
    for (BeanConfiguration bc : beanConfigs.values()) {
        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("[RuntimeConfiguration] Registering bean [" + bc.getName() + "]");
            if (LOGGER.isLoggable(Level.FINEST)) {
                PropertyValue[] pvs = bc.getBeanDefinition().getPropertyValues().getPropertyValues();
                for (PropertyValue pv : pvs) {
                    LOGGER.finest("[RuntimeConfiguration] With property [" + pv.getName() + "] set to [" + pv.getValue() + "]");
                }
            }
        }
        if (applicationContext.containsBeanDefinition(bc.getName()))
            applicationContext.removeBeanDefinition(bc.getName());
        applicationContext.registerBeanDefinition(bc.getName(), bc.getBeanDefinition());
    }
    for (String key : beanDefinitions.keySet()) {
        BeanDefinition bd = beanDefinitions.get(key);
        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("[RuntimeConfiguration] Registering bean [" + key + "]");
            if (LOGGER.isLoggable(Level.FINEST)) {
                for (PropertyValue pv : bd.getPropertyValues().getPropertyValues()) {
                    LOGGER.finest("[RuntimeConfiguration] With property [" + pv.getName() + "] set to [" + pv.getValue() + "]");
                }
            }
        }
        if (applicationContext.containsBean(key)) {
            applicationContext.removeBeanDefinition(key);
        }
        applicationContext.registerBeanDefinition(key, bd);
    }
}
Also used : PropertyValue(org.springframework.beans.PropertyValue) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 2 with PropertyValue

use of org.springframework.beans.PropertyValue in project spring-boot by spring-projects.

the class PropertySourcesPropertyValues method putIfAbsent.

private PropertyValue putIfAbsent(String propertyName, Object value, PropertySource<?> source) {
    if (value != null && !this.propertyValues.containsKey(propertyName)) {
        PropertySource<?> collectionOwner = this.collectionOwners.putIfAbsent(COLLECTION_PROPERTY.matcher(propertyName).replaceAll("[]"), source);
        if (collectionOwner == null || collectionOwner == source) {
            PropertyValue propertyValue = new OriginCapablePropertyValue(propertyName, value, propertyName, source);
            this.propertyValues.put(propertyName, propertyValue);
            return propertyValue;
        }
    }
    return null;
}
Also used : PropertyValue(org.springframework.beans.PropertyValue)

Example 3 with PropertyValue

use of org.springframework.beans.PropertyValue in project spring-boot by spring-projects.

the class RelaxedDataBinder method getSortedPropertyNames.

private List<String> getSortedPropertyNames(MutablePropertyValues propertyValues) {
    List<String> names = new LinkedList<>();
    for (PropertyValue propertyValue : propertyValues.getPropertyValueList()) {
        names.add(propertyValue.getName());
    }
    sortPropertyNames(names);
    return names;
}
Also used : PropertyValue(org.springframework.beans.PropertyValue) LinkedList(java.util.LinkedList)

Example 4 with PropertyValue

use of org.springframework.beans.PropertyValue in project spring-boot by spring-projects.

the class RelaxedDataBinder method getPropertyValuesForNamePrefix.

private MutablePropertyValues getPropertyValuesForNamePrefix(MutablePropertyValues propertyValues) {
    if (!StringUtils.hasText(this.namePrefix) && !this.ignoreNestedProperties) {
        return propertyValues;
    }
    MutablePropertyValues rtn = new MutablePropertyValues();
    for (PropertyValue value : propertyValues.getPropertyValues()) {
        String name = value.getName();
        for (String prefix : new RelaxedNames(stripLastDot(this.namePrefix))) {
            for (String separator : new String[] { ".", "_" }) {
                String candidate = (StringUtils.hasLength(prefix) ? prefix + separator : prefix);
                if (name.startsWith(candidate)) {
                    name = name.substring(candidate.length());
                    if (!(this.ignoreNestedProperties && name.contains("."))) {
                        PropertyOrigin propertyOrigin = OriginCapablePropertyValue.getOrigin(value);
                        rtn.addPropertyValue(new OriginCapablePropertyValue(name, value.getValue(), propertyOrigin));
                    }
                }
            }
        }
    }
    return rtn;
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) PropertyValue(org.springframework.beans.PropertyValue)

Example 5 with PropertyValue

use of org.springframework.beans.PropertyValue in project spring-boot by spring-projects.

the class PropertySourcesPropertyValuesTests method testOrderPreserved.

@Test
public void testOrderPreserved() {
    LinkedHashMap<String, Object> map = new LinkedHashMap<>();
    map.put("one", 1);
    map.put("two", 2);
    map.put("three", 3);
    map.put("four", 4);
    map.put("five", 5);
    this.propertySources.addFirst(new MapPropertySource("ordered", map));
    PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(this.propertySources);
    PropertyValue[] values = propertyValues.getPropertyValues();
    assertThat(values).hasSize(6);
    Collection<String> names = new ArrayList<>();
    for (PropertyValue value : values) {
        names.add(value.getName());
    }
    assertThat(names).containsExactly("one", "two", "three", "four", "five", "name");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) ArrayList(java.util.ArrayList) PropertyValue(org.springframework.beans.PropertyValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

PropertyValue (org.springframework.beans.PropertyValue)41 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)16 Test (org.junit.Test)15 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)8 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)7 FieldAccessBean (org.springframework.tests.sample.beans.FieldAccessBean)6 ArrayList (java.util.ArrayList)5 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)5 ITestBean (org.springframework.tests.sample.beans.ITestBean)5 TestBean (org.springframework.tests.sample.beans.TestBean)5 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)4 BeanWrapper (org.springframework.beans.BeanWrapper)3 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)3 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)3 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 BeansException (org.springframework.beans.BeansException)2