1 package org.simantics.structural2.scl;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.request.ResourceRead;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.layer0.Layer0;
8 import org.simantics.structural.stubs.StructuralResource2;
9 import org.simantics.utils.datastructures.Pair;
12 * Given component finds a component type it belongs to
14 public class FindComponentTypeRequest extends ResourceRead<Pair<Resource,Integer>> {
16 public FindComponentTypeRequest(Resource resource) {
21 public Pair<Resource,Integer> perform(ReadGraph graph) throws DatabaseException {
22 StructuralResource2 STR = StructuralResource2.getInstance(graph);
23 Resource type = graph.getPossibleObject(resource, STR.Defines);
25 return Pair.make(type, 0);
27 Layer0 L0 = Layer0.getInstance(graph);
28 Resource parent = graph.getPossibleObject(resource, L0.PartOf);
30 Pair<Resource,Integer> result =
31 graph.syncRequest(new FindComponentTypeRequest(parent));
32 return Pair.make(result.first, result.second+1);
35 throw new DatabaseException("Unexpected graph structure at " + resource + ".");