use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class PropertyOverrideConfigurer method applyPropertyValue.
/**
* Apply the given property value to the corresponding bean.
*/
protected void applyPropertyValue(ConfigurableBeanFactory factory, String beanName, String property, String value) {
BeanDefinition bd = factory.getBeanDefinition(beanName);
BeanDefinition bdToUse = bd;
while (bd != null) {
bdToUse = bd;
bd = bd.getOriginatingBeanDefinition();
}
PropertyValue pv = new PropertyValue(property, value);
pv.setOptional(this.ignoreInvalidKeys);
bdToUse.getPropertyValues().add(pv);
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class WebDataBinder method checkFieldDefaults.
/**
* Check the given property values for field defaults,
* i.e. for fields that start with the field default prefix.
* <p>The existence of a field defaults indicates that the specified
* value should be used if the field is otherwise not present.
*
* @param values the property values to be bound (can be modified)
* @see #getFieldDefaultPrefix
*/
protected void checkFieldDefaults(PropertyValues values) {
String fieldDefaultPrefix = getFieldDefaultPrefix();
if (fieldDefaultPrefix != null) {
ConfigurablePropertyAccessor propertyAccessor = getPropertyAccessor();
for (PropertyValue pv : values.toArray()) {
if (pv.getName().startsWith(fieldDefaultPrefix)) {
String field = pv.getName().substring(fieldDefaultPrefix.length());
if (propertyAccessor.isWritableProperty(field) && !values.contains(field)) {
values.add(field, pv.getValue());
}
values.remove(pv);
}
}
}
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class WebDataBinder method checkFieldMarkers.
/**
* Check the given property values for field markers,
* i.e. for fields that start with the field marker prefix.
* <p>The existence of a field marker indicates that the specified
* field existed in the form. If the property values do not contain
* a corresponding field value, the field will be considered as empty
* and will be reset appropriately.
*
* @param values the property values to be bound (can be modified)
* @see #getFieldMarkerPrefix
* @see #getEmptyValue(String, Class)
*/
protected void checkFieldMarkers(PropertyValues values) {
String fieldMarkerPrefix = getFieldMarkerPrefix();
if (fieldMarkerPrefix != null) {
ConfigurablePropertyAccessor propertyAccessor = getPropertyAccessor();
for (PropertyValue pv : values.toArray()) {
if (pv.getName().startsWith(fieldMarkerPrefix)) {
String field = pv.getName().substring(fieldMarkerPrefix.length());
if (propertyAccessor.isWritableProperty(field) && !values.contains(field)) {
Class<?> fieldType = propertyAccessor.getPropertyType(field);
values.add(field, getEmptyValue(field, fieldType));
}
values.remove(pv);
}
}
}
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class AbstractDataBinderParameterResolver method resolveName.
@Nullable
@Override
protected Object resolveName(String name, ResolvableMethodParameter resolvable, RequestContext context) throws Exception {
final int parameterNameLength = name.length();
// prepare property values
final Map<String, String[]> parameters = context.getParameters();
final DefaultMultiValueMap<String, PropertyValue> propertyValues = new DefaultMultiValueMap<>();
for (final Map.Entry<String, String[]> entry : parameters.entrySet()) {
final String[] paramValues = entry.getValue();
if (ObjectUtils.isNotEmpty(paramValues)) {
final String requestParameterName = entry.getKey();
// users[key].userName=TODAY&users[key].age=20
if (requestParameterName.startsWith(name) && requestParameterName.charAt(parameterNameLength) == '[') {
// userList[0].name '.' 's index
final int separatorIndex = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(requestParameterName);
final String property = requestParameterName.substring(separatorIndex + 1);
final int closeKey = requestParameterName.indexOf(']');
final String key = requestParameterName.substring(parameterNameLength + 1, closeKey);
final PropertyValue propertyValue = new PropertyValue(property, paramValues[0]);
propertyValues.add(key, propertyValue);
}
}
}
return doBind(propertyValues, resolvable);
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class MetadataAttachmentTests method propertyMetadata.
@Test
public void propertyMetadata() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3");
PropertyValue pv = beanDefinition.getPropertyValues().get("name");
assertThat(pv.getAttribute("surname")).isEqualTo("Harrop");
}
Aggregations