]> gerrit.simantics Code Review - simantics/platform.git/blob
2c2f0f7b2176e1e60785be6014918be6936bd06d
[simantics/platform.git] /
1 package org.simantics.structural2.scl;\r
2 \r
3 import gnu.trove.map.hash.THashMap;\r
4 \r
5 import java.util.Map;\r
6 \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
17 \r
18 public class ReadComponentTypeInterfaceRequest extends ResourceRead<Map<String, ComponentTypeProperty>> {\r
19         \r
20     Environment environment;\r
21     \r
22         public ReadComponentTypeInterfaceRequest(Resource resource, Environment environment) {\r
23                 super(resource);\r
24                 this.environment = environment;\r
25         }\r
26 \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
34                                 Type type;\r
35                                 try {\r
36                                     type = Environments.getType(environment, typeName);\r
37                                 } catch(SCLExpressionCompilationException e) {\r
38                                     e.printStackTrace();\r
39                                     continue;\r
40                                 }\r
41                                 ComponentTypeProperty property = new ComponentTypeProperty(relation, type);\r
42                                 result.put(name, property);\r
43                         }\r
44                 }\r
45         }\r
46         \r
47         @Override\r
48         public Map<String, ComponentTypeProperty> perform(ReadGraph graph)\r
49                         throws DatabaseException {\r
50                 \r
51                 THashMap<String, ComponentTypeProperty> result = \r
52                                 new THashMap<String, ComponentTypeProperty>();\r
53                 \r
54                 collect(graph, resource, result);\r
55                 for(Resource t : graph.getSupertypes(resource)) collect(graph, t, result);\r
56                 \r
57                 return result;\r
58                 \r
59         }\r
60 \r
61 }\r