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 long s = System.nanoTime();
27 DocumentationResource DOC = DocumentationResource.getInstance(graph);
29 Resource type = variable.getPossibleType(graph);
30 if(type == null) return Collections.emptySet();
32 if(!graph.isInheritedFrom(type, DOC.Components_Component)) return Collections.emptySet();
34 Boolean pathExists = variable.getPossiblePropertyValue(graph, DOC.Properties_pathExists, Bindings.BOOLEAN);
35 if(pathExists != null && !pathExists) return Collections.emptySet();
37 if(graph.isInheritedFrom(type, DOC.Components_PrimitiveComponent)) {
38 return Collections.singleton(variable);
40 Set<Variable> result = new THashSet<Variable>();
41 for(Variable child : variable.getChildren(graph)) {
42 Set<Variable> nodes = graph.syncRequest(new NodesRequest2(child));
46 if(DocumentRequest.PROFILE) {
47 long dura = System.nanoTime()-s;
48 System.err.println("NodesRequest2 " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms.");