1 package org.simantics.structural2.scl;
\r
3 import gnu.trove.map.hash.THashMap;
\r
5 import java.util.Map;
\r
7 import org.simantics.databoard.Bindings;
\r
8 import org.simantics.db.ReadGraph;
\r
9 import org.simantics.db.Resource;
\r
10 import org.simantics.db.common.request.ResourceRead;
\r
11 import org.simantics.db.exception.DatabaseException;
\r
12 import org.simantics.layer0.Layer0;
\r
13 import org.simantics.scl.compiler.environment.Environment;
\r
14 import org.simantics.scl.compiler.environment.Environments;
\r
15 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
\r
16 import org.simantics.scl.compiler.types.Type;
\r
18 public class ReadComponentTypeInterfaceRequest extends ResourceRead<Map<String, ComponentTypeProperty>> {
\r
20 Environment environment;
\r
22 public ReadComponentTypeInterfaceRequest(Resource resource, Environment environment) {
\r
24 this.environment = environment;
\r
27 private void collect(ReadGraph graph, Resource t, THashMap<String, ComponentTypeProperty> result) throws DatabaseException {
\r
28 Layer0 L0 = Layer0.getInstance(graph);
\r
29 for(Resource relation : graph.getObjects(t, L0.DomainOf)) {
\r
30 if(graph.isSubrelationOf(relation, L0.HasProperty)) {
\r
31 String name = graph.getRelatedValue(relation, L0.HasName, Bindings.STRING);
\r
32 String typeName = graph.getPossibleRelatedValue(relation, L0.RequiresValueType, Bindings.STRING);
\r
33 if(typeName == null) continue;
\r
36 type = Environments.getType(environment, typeName);
\r
37 } catch(SCLExpressionCompilationException e) {
\r
38 e.printStackTrace();
\r
41 ComponentTypeProperty property = new ComponentTypeProperty(relation, type);
\r
42 result.put(name, property);
\r
48 public Map<String, ComponentTypeProperty> perform(ReadGraph graph)
\r
49 throws DatabaseException {
\r
51 THashMap<String, ComponentTypeProperty> result =
\r
52 new THashMap<String, ComponentTypeProperty>();
\r
54 collect(graph, resource, result);
\r
55 for(Resource t : graph.getSupertypes(resource)) collect(graph, t, result);
\r