Example #1
0
 /**
  * JavaBeansの値をマップにコピーします。
  *
  * @param src ソース
  * @param dest あて先
  */
 public static void copyProperties(Object src, Map dest) {
   if (src == null || dest == null) {
     return;
   }
   final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(src.getClass());
   final int size = beanDesc.getPropertyDescSize();
   for (int i = 0; i < size; ++i) {
     final PropertyDesc pd = beanDesc.getPropertyDesc(i);
     if (pd.isReadable() && pd.isWritable()) {
       final Object value = pd.getValue(src);
       dest.put(pd.getPropertyName(), value);
     }
   }
 }
Example #2
0
 /**
  * マップの値をJavaBeansにコピーします。
  *
  * @param src ソース
  * @param dest あて先
  */
 public static void copyProperties(Map src, Object dest) {
   if (src == null || dest == null) {
     return;
   }
   BeanDesc beanDesc = BeanDescFactory.getBeanDesc(dest.getClass());
   for (Iterator i = src.keySet().iterator(); i.hasNext(); ) {
     String key = (String) i.next();
     if (!beanDesc.hasPropertyDesc(key)) {
       continue;
     }
     PropertyDesc pd = beanDesc.getPropertyDesc(key);
     if (pd.isWritable()) {
       pd.setValue(dest, src.get(key));
     }
   }
 }
Example #3
0
  /**
   * JavaBeansの値をJavaBeansにコピーします。
   *
   * @param src ソース
   * @param dest あて先
   * @param includeNull <code>null</code>を含めるかどうか
   */
  public static void copyProperties(
      final Object src, final Object dest, final boolean includeNull) {
    final BeanDesc srcBeanDesc = BeanDescFactory.getBeanDesc(src.getClass());
    final BeanDesc destBeanDesc = BeanDescFactory.getBeanDesc(dest.getClass());

    final int propertyDescSize = destBeanDesc.getPropertyDescSize();
    for (int i = 0; i < propertyDescSize; i++) {
      final PropertyDesc destPropertyDesc = destBeanDesc.getPropertyDesc(i);
      final String propertyName = destPropertyDesc.getPropertyName();
      if (srcBeanDesc.hasPropertyDesc(propertyName)) {
        final PropertyDesc srcPropertyDesc = srcBeanDesc.getPropertyDesc(propertyName);
        if (destPropertyDesc.isWritable() && srcPropertyDesc.isReadable()) {
          final Object value = srcPropertyDesc.getValue(src);
          if (includeNull || value != null) {
            destPropertyDesc.setValue(dest, srcPropertyDesc.getValue(src));
          }
        }
      }
    }
  }