コード例 #1
0
  /**
   * Recursively-copies properties from the Object, up the inheritance hierarchy, to the destination
   * Resource.
   *
   * @param type the Type of the object being copied. May be a super-type of the 'from' object.
   * @param from the instance of Object being copied.
   * @param to the destination Resource instance.
   */
  private void copyProperties0(Class<?> type, Object from, Resource to) {
    if (type == null) return;
    if (Resource.class.isAssignableFrom(type)) {
      to.from((Resource) from);
      return;
    }

    Field[] fields = getDeclaredFields(type);

    try {
      for (Field f : fields) {
        if (isIncluded(f)) {
          f.setAccessible(true);
          Object value = f.get(from);

          if (value != null) {
            addProperty(to, f, value);
          }
        }
      }
    } catch (IllegalAccessException e) {
      throw new ResourceException(e);
    }

    copyProperties0(type.getSuperclass(), from, to);
  }