/** * TODO: confusion between root and its first child? * * @return This model's root tree element */ public TreeElement getRoot() { if (root.getNumChildren() == 0) { throw new SystemException("root node has no children"); } return(root.getChildAt(0)); }
// determine if nodes are homogeneous, meaning their descendant structure is 'identical' for repeat purposes // identical means all children match, and the children's children match, and so on // repeatable children are ignored; as they do not have to exist in the same quantity for nodes to be homogeneous // however, the child repeatable nodes MUST be verified amongst themselves for homogeneity later // this function ignores the names of the two nodes public static Boolean isHomogeneous(TreeElement a, TreeElement b) { if (a.isLeaf() && b.isLeaf()) { return(true); } else if (a.isChildable() && b.isChildable()) { // verify that every (non-repeatable) node in a exists in b and vice // versa for (int k = 0; k < 2; k++) { TreeElement n1 = (k == 0 ? a : b); TreeElement n2 = (k == 0 ? b : a); for (int i = 0; i < n1.getNumChildren(); i++) { TreeElement child1 = n1.getChildAt(i); if (child1.repeatable) { continue; } TreeElement child2 = n2.getChild(child1.getName(), 0); if (child2 == null) { return(false); } if (child2.repeatable) { throw new SystemException("shouldn't happen"); } } } // compare children for (int i = 0; i < a.getNumChildren(); i++) { TreeElement childA = a.getChildAt(i); if (childA.repeatable) { continue; } TreeElement childB = b.getChild(childA.getName(), 0); if (!isHomogeneous(childA, childB)) { return(false); } } return(true); } else { return(false); } }
public void importData(FormInstance dm) { name = (String)RestoreUtils.getValue("name", dm); formId = ((int)RestoreUtils.getValue("form-id", dm)); dateSaved = (DateTime)RestoreUtils.getValue("saved-on", dm); schema = (String)RestoreUtils.getValue("schema", dm); Boolean sent = RestoreUtils.getBoolean(RestoreUtils .getValue("sent", dm)); TreeElement names = dm.resolveReference(RestoreUtils.absRef("namespace", dm)); if (names != null) { for (int i = 0; i < names.getNumChildren(); i++) { TreeElement child = names.getChildAt(i); String name_ = child.getName(); Object value = RestoreUtils.getValue("namespace/" + name_, dm); if (value != null) { namespaces.Add(name_, value); } } } ///////////// throw new SystemException("FormInstance.importData(): must be updated to use new transport layer"); // if (sent) { // ITransportManager tm = TransportManager._(); // tm.markSent(id, false); // } ///////////// // IStorageUtility forms = StorageManager.getStorage(FormDef.STORAGE_KEY); // FormDef f = (FormDef)forms.read(formId); // setRoot(processSavedDataModel(dm.resolveReference(RestoreUtils.absRef("data", dm)), f.getDataModel(), f)); }