--- /dev/null
+package org.simantics.db.layer0.variable;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+\r
+abstract public class NodeManagerVariableBuilder implements VariableBuilder {\r
+\r
+ @Override\r
+ public Variable buildChild(ReadGraph graph, Variable parent, VariableNode node, Resource child) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ String childName = graph.getRelatedValue(child, L0.HasName, Bindings.STRING);\r
+ String sessionName = parent.getURI(graph) + "/" + childName;\r
+ return createChild(graph, parent, sessionName, child);\r
+ }\r
+ \r
+ protected Variable createChild(ReadGraph graph, Variable parent, String sessionName, Resource child) throws DatabaseException {\r
+ NodeSupport<?> support = getNodeSupport(graph, sessionName);\r
+ return new StandardGraphChildVariable(parent, new VariableNode(support, getRoot(graph, support, sessionName)), child);\r
+ }\r
+\r
+ @Override\r
+ public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode node, Resource subject, Resource predicate) throws DatabaseException {\r
+ throw new UnsupportedOperationException();\r
+ }\r
+ \r
+ protected abstract NodeSupport<?> getNodeSupport(ReadGraph graph, String sessionName) throws DatabaseException;\r
+ protected abstract Object getRoot(ReadGraph graph, NodeSupport<?> support, String sessionName) throws DatabaseException;\r
+\r
+}\r