Search in sources :

Example 6 with PropertyValues

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

the class SpringProfileDocumentMatcher method extractSpringProfiles.

protected List<String> extractSpringProfiles(Properties properties) {
    SpringProperties springProperties = new SpringProperties();
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new PropertiesPropertySource("profiles", properties));
    PropertyValues propertyValues = new PropertySourcesPropertyValues(propertySources);
    new RelaxedDataBinder(springProperties, "spring").bind(propertyValues);
    List<String> profiles = springProperties.getProfiles();
    return profiles;
}
Also used : PropertySourcesPropertyValues(org.springframework.boot.bind.PropertySourcesPropertyValues) PropertyValues(org.springframework.beans.PropertyValues) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertySources(org.springframework.core.env.MutablePropertySources) PropertySourcesPropertyValues(org.springframework.boot.bind.PropertySourcesPropertyValues)

Example 7 with PropertyValues

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

the class BeanComponentDefinition method findInnerBeanDefinitionsAndBeanReferences.

private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
    List<BeanDefinition> innerBeans = new ArrayList<>();
    List<BeanReference> references = new ArrayList<>();
    PropertyValues propertyValues = beanDefinition.getPropertyValues();
    for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
        PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
        Object value = propertyValue.getValue();
        if (value instanceof BeanDefinitionHolder) {
            innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
        } else if (value instanceof BeanDefinition) {
            innerBeans.add((BeanDefinition) value);
        } else if (value instanceof BeanReference) {
            references.add((BeanReference) value);
        }
    }
    this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
    this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
Also used : PropertyValues(org.springframework.beans.PropertyValues) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) ArrayList(java.util.ArrayList) PropertyValue(org.springframework.beans.PropertyValue) BeanReference(org.springframework.beans.factory.config.BeanReference) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 8 with PropertyValues

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

the class AbstractAutowireCapableBeanFactory method unsatisfiedNonSimpleProperties.

/**
	 * Return an array of non-simple bean properties that are unsatisfied.
	 * These are probably unsatisfied references to other beans in the
	 * factory. Does not include simple properties like primitives or Strings.
	 * @param mbd the merged bean definition the bean was created with
	 * @param bw the BeanWrapper the bean was created with
	 * @return an array of bean property names
	 * @see org.springframework.beans.BeanUtils#isSimpleProperty
	 */
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
    Set<String> result = new TreeSet<>();
    PropertyValues pvs = mbd.getPropertyValues();
    PropertyDescriptor[] pds = bw.getPropertyDescriptors();
    for (PropertyDescriptor pd : pds) {
        if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) && !BeanUtils.isSimpleProperty(pd.getPropertyType())) {
            result.add(pd.getName());
        }
    }
    return StringUtils.toStringArray(result);
}
Also used : PropertyValues(org.springframework.beans.PropertyValues) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) PropertyDescriptor(java.beans.PropertyDescriptor) TreeSet(java.util.TreeSet)

Example 9 with PropertyValues

use of org.springframework.beans.PropertyValues in project canal by alibaba.

the class PropertiesConfigurationFactory method doBindPropertiesToTarget.

private void doBindPropertiesToTarget() throws BindException {
    RelaxedDataBinder dataBinder = (this.targetName != null ? new RelaxedDataBinder(this.target, this.targetName) : new RelaxedDataBinder(this.target));
    if (this.validator != null && this.validator.supports(dataBinder.getTarget().getClass())) {
        dataBinder.setValidator(this.validator);
    }
    if (this.conversionService != null) {
        dataBinder.setConversionService(this.conversionService);
    }
    dataBinder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
    dataBinder.setIgnoreNestedProperties(this.ignoreNestedProperties);
    dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
    dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);
    customizeBinder(dataBinder);
    if (this.applicationContext != null) {
        ResourceEditorRegistrar resourceEditorRegistrar = new ResourceEditorRegistrar(this.applicationContext, this.applicationContext.getEnvironment());
        resourceEditorRegistrar.registerCustomEditors(dataBinder);
    }
    Iterable<String> relaxedTargetNames = getRelaxedTargetNames();
    Set<String> names = getNames(relaxedTargetNames);
    PropertyValues propertyValues = getPropertySourcesPropertyValues(names, relaxedTargetNames);
    dataBinder.bind(propertyValues);
    if (this.validator != null) {
        dataBinder.validate();
    }
    checkForBindingErrors(dataBinder);
}
Also used : PropertyValues(org.springframework.beans.PropertyValues) ResourceEditorRegistrar(org.springframework.beans.support.ResourceEditorRegistrar)

Aggregations

PropertyValues (org.springframework.beans.PropertyValues)9 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 BeanWrapper (org.springframework.beans.BeanWrapper)3 PropertyDescriptor (java.beans.PropertyDescriptor)2 BeansException (org.springframework.beans.BeansException)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 ResourceEditor (org.springframework.core.io.ResourceEditor)2 ResourceLoader (org.springframework.core.io.ResourceLoader)2 ServletContextResourceLoader (org.springframework.web.context.support.ServletContextResourceLoader)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 PropertyValue (org.springframework.beans.PropertyValue)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)1 BeanPostProcessor (org.springframework.beans.factory.config.BeanPostProcessor)1 BeanReference (org.springframework.beans.factory.config.BeanReference)1 InstantiationAwareBeanPostProcessor (org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor)1 SmartInstantiationAwareBeanPostProcessor (org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)1