]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeManagerVariableBuilder.java
Merge commit 'ad8333027322fda6b9a8a524c7a7e15a54c52f38'
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / NodeManagerVariableBuilder.java
1 package org.simantics.db.layer0.variable;\r
2 \r
3 import org.simantics.databoard.Bindings;\r
4 import org.simantics.db.ReadGraph;\r
5 import org.simantics.db.Resource;\r
6 import org.simantics.db.exception.DatabaseException;\r
7 import org.simantics.layer0.Layer0;\r
8 \r
9 abstract public class NodeManagerVariableBuilder implements VariableBuilder {\r
10 \r
11     @Override\r
12     public Variable buildChild(ReadGraph graph, Variable parent, VariableNode node, Resource child) throws DatabaseException {\r
13         Layer0 L0 = Layer0.getInstance(graph);\r
14         String childName = graph.getRelatedValue(child, L0.HasName, Bindings.STRING);\r
15         String sessionName = parent.getURI(graph) + "/" + childName;\r
16         return createChild(graph, parent, sessionName, child);\r
17     }\r
18     \r
19     protected Variable createChild(ReadGraph graph, Variable parent, String sessionName, Resource child) throws DatabaseException {\r
20         NodeSupport<?> support = getNodeSupport(graph, sessionName);\r
21         return new StandardGraphChildVariable(parent, new VariableNode(support, getRoot(graph, support, sessionName)), child);\r
22     }\r
23 \r
24     @Override\r
25     public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode node, Resource subject, Resource predicate) throws DatabaseException {\r
26         throw new UnsupportedOperationException();\r
27     }\r
28     \r
29     protected abstract NodeSupport<?> getNodeSupport(ReadGraph graph, String sessionName) throws DatabaseException;\r
30     protected abstract Object getRoot(ReadGraph graph, NodeSupport<?> support, String sessionName) throws DatabaseException;\r
31 \r
32 }\r