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