コード例 #1
0
ファイル: Macro.java プロジェクト: bramk/bnd
 public static Properties getParent(Properties p) {
   try {
     Field f = Properties.class.getDeclaredField("defaults");
     f.setAccessible(true);
     return (Properties) f.get(p);
   } catch (Exception e) {
     Field[] fields = Properties.class.getFields();
     System.err.println(Arrays.toString(fields));
     return null;
   }
 }
コード例 #2
0
  /**
   * Copy from the copy method in StructUtil. Did not want to drag that code in. maybe this actually
   * should go to struct.
   *
   * @param from
   * @param to
   * @param excludes
   * @return
   * @throws Exception
   */
  public static <T extends struct> T xcopy(struct from, T to, String... excludes) throws Exception {
    Arrays.sort(excludes);
    for (Field f : from.fields()) {
      if (Arrays.binarySearch(excludes, f.getName()) >= 0) continue;

      Object o = f.get(from);
      if (o == null) continue;

      Field tof = to.getField(f.getName());
      if (tof != null)
        try {
          tof.set(to, Converter.cnv(tof.getGenericType(), o));
        } catch (Exception e) {
          System.out.println(
              "Failed to convert "
                  + f.getName()
                  + " from "
                  + from.getClass()
                  + " to "
                  + to.getClass()
                  + " value "
                  + o
                  + " exception "
                  + e);
        }
    }

    return to;
  }