1 package org.simantics.document.server.request;
3 import gnu.trove.set.hash.THashSet;
5 import java.util.Collection;
6 import java.util.Collections;
9 import org.simantics.databoard.Bindings;
10 import org.simantics.db.AsyncReadGraph;
11 import org.simantics.db.ReadGraph;
12 import org.simantics.db.Resource;
13 import org.simantics.db.common.request.AsyncReadRequest;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.layer0.request.VariableChildren;
16 import org.simantics.db.layer0.request.VariableRead;
17 import org.simantics.db.layer0.variable.Variable;
18 import org.simantics.db.procedure.AsyncProcedure;
19 import org.simantics.document.base.ontology.DocumentationResource;
20 import org.simantics.utils.threads.logger.ITask;
21 import org.simantics.utils.threads.logger.ThreadLogger;
23 public class NodesRequest2 extends VariableRead<Set<Variable>> {
25 public NodesRequest2(Variable var) {
30 public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
32 ITask task = DocumentRequest.PROFILE ? ThreadLogger.task(this) : null;
34 DocumentationResource DOC = DocumentationResource.getInstance(graph);
36 Resource type = variable.getPossibleType(graph);
38 if(DocumentRequest.PROFILE) task.finish();
39 return Collections.emptySet();
42 if(!graph.isInheritedFrom(type, DOC.Components_Component)) {
43 if(DocumentRequest.PROFILE) task.finish();
44 return Collections.emptySet();
47 Boolean pathExists = variable.getPossiblePropertyValue(graph, DOC.Properties_pathExists, Bindings.BOOLEAN);
48 if(pathExists != null && !pathExists) {
49 if(DocumentRequest.PROFILE) task.finish();
50 return Collections.emptySet();
53 if(graph.isInheritedFrom(type, DOC.Components_PrimitiveComponent)) {
54 if(DocumentRequest.PROFILE) task.finish();
55 return Collections.singleton(variable);
57 Set<Variable> result = new THashSet<Variable>();
58 Collection<Variable> children = graph.syncRequest(new VariableChildren(variable));
59 graph.syncRequest(new AsyncReadRequest() {
62 public void run(AsyncReadGraph graph) throws DatabaseException {
64 for(Variable child : children) {
65 graph.asyncRequest(new NodesRequest2(child), new AsyncProcedure<Set<Variable>>() {
68 public void execute(AsyncReadGraph graph, Set<Variable> vars) {
69 synchronized(result) {
75 public void exception(AsyncReadGraph graph, Throwable throwable) {
85 if(DocumentRequest.PROFILE) task.finish();