ComponentManager.java 文件源码

java
阅读 31 收藏 0 点赞 0 评论 0

项目:FinanceAnalytics 作者:
/**
 * 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));
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号