]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeManagerVariableBuilder.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / NodeManagerVariableBuilder.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeManagerVariableBuilder.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeManagerVariableBuilder.java
new file mode 100644 (file)
index 0000000..d498694
--- /dev/null
@@ -0,0 +1,32 @@
+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