]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java
840d9ec4c7dc5bd688f382939d04734e8c1fa998
[simantics/platform.git] / bundles / org.simantics.structural.synchronization.client / src / org / simantics / structural / synchronization / base / UpdateComponentUids.java
1 package org.simantics.structural.synchronization.base;\r
2 \r
3 import org.simantics.db.ReadGraph;\r
4 import org.simantics.db.exception.DatabaseException;\r
5 import org.simantics.db.layer0.variable.Variable;\r
6 \r
7 /**\r
8  * Utility for updating UIDs in the given component to correspond\r
9  * the RVIs of the given variable. This operation is needed when\r
10  * the mapping is part of a model that is imported to a new database\r
11  * and resource ids have been changed.\r
12  * \r
13  * @author Hannu Niemistö\r
14  */\r
15 public class UpdateComponentUids {\r
16     \r
17     public static <T extends ComponentBase<T>> void update(ReadGraph graph, T component, Variable variable) throws DatabaseException {\r
18         component.uid = variable.getRVI(graph).toString();\r
19         for(Variable childVariable : variable.getChildren(graph)) {\r
20             String childName = childVariable.getName(graph);\r
21             T childComponent = component.getChild(childName);\r
22             if(childComponent != null)\r
23                 update(graph, childComponent, childVariable);\r
24         }\r
25     }\r
26     \r
27 }\r