1 package org.simantics.structural2;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import org.simantics.databoard.Bindings;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.Statement;
10 import org.simantics.db.common.request.ObjectsWithType;
11 import org.simantics.db.common.request.ResourceRead;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.layer0.Layer0;
14 import org.simantics.structural.stubs.StructuralResource2;
15 import org.simantics.structural2.Functions.InterfaceResolution;
17 public class DefinedUCInterfaceMap extends ResourceRead<Collection<InterfaceResolution>> {
19 public DefinedUCInterfaceMap(Resource resource) {
24 public Collection<InterfaceResolution> perform(ReadGraph graph)
25 throws DatabaseException {
27 StructuralResource2 STR = StructuralResource2.getInstance(graph);
28 Resource definition = graph.getPossibleObject(resource, STR.IsDefinedBy);
29 if(definition != null) {
30 Collection<InterfaceResolution> result = new ArrayList<InterfaceResolution>();
31 Layer0 L0 = Layer0.getInstance(graph);
32 for(Resource cp : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, STR.ConnectionRelation))) {
33 String cpName = graph.getRelatedValue(cp, L0.HasName, Bindings.STRING);
34 for(Resource conn : graph.getObjects(cp, STR.IsBoundBy)) {
35 Statement stm = graph.getPossibleStatement(conn, STR.Connects);
36 if(stm == null) continue;
37 Resource component = stm.getObject();
38 String componentName = graph.getRelatedValue(component, L0.HasName, Bindings.STRING);
39 result.add(new InterfaceResolution(cp, cpName, componentName, graph.getInverse(stm.getPredicate())));