]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural.synchronization.client / src / org / simantics / structural / synchronization / base / UpdateComponentUids.java
diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java
new file mode 100644 (file)
index 0000000..840d9ec
--- /dev/null
@@ -0,0 +1,27 @@
+package org.simantics.structural.synchronization.base;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+\r
+/**\r
+ * Utility for updating UIDs in the given component to correspond\r
+ * the RVIs of the given variable. This operation is needed when\r
+ * the mapping is part of a model that is imported to a new database\r
+ * and resource ids have been changed.\r
+ * \r
+ * @author Hannu Niemistö\r
+ */\r
+public class UpdateComponentUids {\r
+    \r
+    public static <T extends ComponentBase<T>> void update(ReadGraph graph, T component, Variable variable) throws DatabaseException {\r
+        component.uid = variable.getRVI(graph).toString();\r
+        for(Variable childVariable : variable.getChildren(graph)) {\r
+            String childName = childVariable.getName(graph);\r
+            T childComponent = component.getChild(childName);\r
+            if(childComponent != null)\r
+                update(graph, childComponent, childVariable);\r
+        }\r
+    }\r
+    \r
+}\r