/**
* Intelligently sets the property.
* <p>
* This uses the repository to link properties declared with classifiers to the instance.
*
* @param bean the bean, not null
* @param mp the property, not null
* @param value the configured value, not null
* @throws ComponentConfigException if the property cannot be initialized
*/
protected void setPropertyInferType(Bean bean, MetaProperty<?> mp, String value) {
Class<?> propertyType = mp.propertyType();
if (isConvertibleFromString(mp.propertyType())) {
// set property by value type conversion from String
mp.set(bean, convert(propertyType, value));
} else if (Collection.class.isAssignableFrom(propertyType)) {
// set property by value type conversion from comma separated String
Class<?> collType = JodaBeanUtils.collectionType(mp, bean.getClass());
if (isConvertibleFromString(collType)) {
Iterable<String> split = Splitter.on(',').trimResults().split(value);
Builder<Object> builder = ImmutableList.builder();
for (String singleValue : split) {
builder.add(convert(collType, singleValue));
}
mp.set(bean, builder.build());
} else {
throw new ComponentConfigException(String.format("No mechanism found to set collection property %s from value: %s", mp, value));
}
} else {
throw new ComponentConfigException(String.format("No mechanism found to set property %s from value: %s", mp, value));
}
}
ComponentManager.java 文件源码
java
阅读 31
收藏 0
点赞 0
评论 0
项目:FinanceAnalytics
作者:
评论列表
文章目录