1 package org.simantics.document.server.request;
3 import gnu.trove.set.hash.THashSet;
5 import java.util.Collections;
8 import org.simantics.databoard.Bindings;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.request.VariableRead;
13 import org.simantics.db.layer0.variable.Variable;
14 import org.simantics.document.base.ontology.DocumentationResource;
16 public class NodesRequest2 extends VariableRead<Set<Variable>> {
18 public NodesRequest2(Variable var) {
23 public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
25 DocumentationResource DOC = DocumentationResource.getInstance(graph);
27 Resource type = variable.getPossibleType(graph);
28 if(type == null) return Collections.emptySet();
30 if(!graph.isInheritedFrom(type, DOC.Components_Component)) return Collections.emptySet();
32 Boolean pathExists = variable.getPossiblePropertyValue(graph, DOC.Properties_pathExists, Bindings.BOOLEAN);
33 if(pathExists != null && !pathExists) return Collections.emptySet();
35 if(graph.isInheritedFrom(type, DOC.Components_PrimitiveComponent)) {
36 return Collections.singleton(variable);
38 Set<Variable> result = new THashSet<Variable>();
39 for(Variable child : variable.getChildren(graph)) {
40 Set<Variable> nodes = graph.syncRequest(new NodesRequest2(child));