コード例 #1
0
  public static void templateChild(
      FormInstance dm, String prefixPath, TreeReference parent, Restorable r) {
    TreeReference childRef =
        (prefixPath == null ? parent : RestoreUtils.childRef(prefixPath, parent));
    childRef = childRef(r.getRestorableType(), childRef);

    templateData(r, dm, childRef);
  }
コード例 #2
0
  public static FormInstance createDataModel(Restorable r) {
    FormInstance dm = newDataModel(r.getRestorableType());

    if (r instanceof Persistable) {
      addData(dm, RECORD_ID_TAG, new Integer(((Persistable) r).getID()));
    }

    return dm;
  }
コード例 #3
0
  public static void importRMS(FormInstance dm, IStorageUtility storage, Class type, String path) {
    if (!Externalizable.class.isAssignableFrom(type) || !Restorable.class.isAssignableFrom(type)) {
      return;
    }

    boolean idMatters = Persistable.class.isAssignableFrom(type);

    String childName = ((Restorable) PrototypeFactory.getInstance(type)).getRestorableType();
    TreeElement e = dm.resolveReference(absRef(path, dm));
    Vector children = e.getChildrenWithName(childName);

    for (int i = 0; i < children.size(); i++) {
      FormInstance child = subDataModel((TreeElement) children.elementAt(i));

      Restorable inst = (Restorable) PrototypeFactory.getInstance(type);

      // restore record id first so 'importData' has access to it
      int recID = -1;
      if (idMatters) {
        recID = ((Integer) getValue(RECORD_ID_TAG, child)).intValue();
        ((Persistable) inst).setID(recID);
      }

      inst.importData(child);

      try {
        if (idMatters) {
          storage.write((Persistable) inst);
        } else {
          storage.add((Externalizable) inst);
        }
      } catch (Exception ex) {
        throw new RuntimeException(
            "Error importing RMS during restore! ["
                + type.getName()
                + ":"
                + recID
                + "]; "
                + ex.getMessage());
      }
    }
  }
コード例 #4
0
  public static void templateData(Restorable r, FormInstance dm, TreeReference parent) {
    if (parent == null) {
      parent = topRef(dm);
      applyDataType(dm, "timestamp", parent, Date.class);
    }

    if (r instanceof Persistable) {
      applyDataType(dm, RECORD_ID_TAG, parent, Integer.class);
    }

    r.templateData(dm, parent);
  }