Java Code Examples for org.springframework.beans.MutablePropertyValues#getPropertyValueList()

The following examples show how to use org.springframework.beans.MutablePropertyValues#getPropertyValueList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnakeToCamelRequestDataBinder.java    From softservice with MIT License 6 votes vote down vote up
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
    super.addBindValues(mpvs, request);

    //处理JsonProperty注释的对象
    Class<?> targetClass = getTarget().getClass();
    Field[] fields = targetClass.getDeclaredFields();
    for (Field field : fields) {
        JsonProperty jsonPropertyAnnotation = field.getAnnotation(JsonProperty.class);
        if (jsonPropertyAnnotation != null && mpvs.contains(jsonPropertyAnnotation.value())) {
            if (!mpvs.contains(field.getName())) {
                mpvs.add(field.getName(), mpvs.getPropertyValue(jsonPropertyAnnotation.value()).getValue());
            }
        }
    }

    List<PropertyValue> covertValues = new ArrayList<PropertyValue>();
    for (PropertyValue propertyValue : mpvs.getPropertyValueList()) {
        if(propertyValue.getName().contains("_")) {
            String camelName = SnakeToCamelRequestParameterUtil.convertSnakeToCamel(propertyValue.getName());
            if (!mpvs.contains(camelName)) {
                covertValues.add(new PropertyValue(camelName, propertyValue.getValue()));
            }
        }
    }
    mpvs.getPropertyValueList().addAll(covertValues);
}
 
Example 2
Source File: BeanExtender.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
{
    ParameterCheck.mandatory("beanName", beanName);
    ParameterCheck.mandatory("extendingBeanName", extendingBeanName);

    // check for bean name
    if (!beanFactory.containsBean(beanName))
    {
        throw new NoSuchBeanDefinitionException("Can't find bean '" + beanName + "' to be extended.");
    }

    // check for extending bean
    if (!beanFactory.containsBean(extendingBeanName))
    {
        throw new NoSuchBeanDefinitionException("Can't find bean '" + extendingBeanName + "' that is going to extend original bean definition.");
    }

    // get the bean definitions
    BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
    BeanDefinition extendingBeanDefinition = beanFactory.getBeanDefinition(extendingBeanName);

    // update class
    if (StringUtils.isNotBlank(extendingBeanDefinition.getBeanClassName()) &&
        !beanDefinition.getBeanClassName().equals(extendingBeanDefinition.getBeanClassName()))
    {
        beanDefinition.setBeanClassName(extendingBeanDefinition.getBeanClassName());
    }

    // update properties
    MutablePropertyValues properties = beanDefinition.getPropertyValues();
    MutablePropertyValues extendingProperties = extendingBeanDefinition.getPropertyValues();
    for (PropertyValue propertyValue : extendingProperties.getPropertyValueList())
    {
        properties.add(propertyValue.getName(), propertyValue.getValue());
    }
}
 
Example 3
Source File: SnakeToLowerCamelCaseRequestDataBinder.java    From spring-boot-doma2-sample with Apache License 2.0 5 votes vote down vote up
/**
 * プロパティ名を取得します。
 * 
 * @param mpvs
 * @return
 */
private List<String> getPropertyNames(MutablePropertyValues mpvs) {
    val list = new ArrayList<String>();
    for (val pv : mpvs.getPropertyValueList()) {
        list.add(pv.getName());
    }
    return list;
}
 
Example 4
Source File: SpringValueDefinitionProcessor.java    From apollo with Apache License 2.0 5 votes vote down vote up
private void processPropertyValues(BeanDefinitionRegistry beanRegistry) {
  if (!PROPERTY_VALUES_PROCESSED_BEAN_FACTORIES.add(beanRegistry)) {
    // already initialized
    return;
  }

  if (!beanName2SpringValueDefinitions.containsKey(beanRegistry)) {
    beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.<String, SpringValueDefinition>create());
  }

  Multimap<String, SpringValueDefinition> springValueDefinitions = beanName2SpringValueDefinitions.get(beanRegistry);

  String[] beanNames = beanRegistry.getBeanDefinitionNames();
  for (String beanName : beanNames) {
    BeanDefinition beanDefinition = beanRegistry.getBeanDefinition(beanName);
    MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
    List<PropertyValue> propertyValues = mutablePropertyValues.getPropertyValueList();
    for (PropertyValue propertyValue : propertyValues) {
      Object value = propertyValue.getValue();
      if (!(value instanceof TypedStringValue)) {
        continue;
      }
      String placeholder = ((TypedStringValue) value).getValue();
      Set<String> keys = placeholderHelper.extractPlaceholderKeys(placeholder);

      if (keys.isEmpty()) {
        continue;
      }

      for (String key : keys) {
        springValueDefinitions.put(beanName, new SpringValueDefinition(key, placeholder, propertyValue.getName()));
      }
    }
  }
}
 
Example 5
Source File: UnderlineBeanWrapper.java    From onetwo with Apache License 2.0 5 votes vote down vote up
protected MutablePropertyValues convertMutablePropertyValues(MutablePropertyValues mpvs){
	MutablePropertyValues newMpvs = new MutablePropertyValues();
	for(PropertyValue pv : mpvs.getPropertyValueList()){
		String propertyName = transformPropertyName(pv.getName());
		newMpvs.addPropertyValue(propertyName, pv.getValue());
	}
	return newMpvs;
}