]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/DefinedUCInterfaceMap.java
Work in progress
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / DefinedUCInterfaceMap.java
1 package org.simantics.structural2;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
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;
16
17 public class DefinedUCInterfaceMap extends ResourceRead<Collection<InterfaceResolution>> {
18
19         public DefinedUCInterfaceMap(Resource resource) {
20                 super(resource);
21         }
22
23         @Override
24         public Collection<InterfaceResolution> perform(ReadGraph graph)
25                         throws DatabaseException {
26
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())));
40                                 }
41                         }
42                 return result;
43                 }
44                 return null;
45         }
46
47 }