]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java
Merge commit '876ede6'
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / scl / ReadComponentTypeInterfaceRequest.java
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.db.layer0.util.Layer0Utils;\r
13 import org.simantics.layer0.Layer0;\r
14 import org.simantics.scl.compiler.environment.Environment;\r
15 import org.simantics.scl.compiler.environment.Environments;\r
16 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;\r
17 import org.simantics.scl.compiler.types.Type;\r
18 \r
19 public class ReadComponentTypeInterfaceRequest extends ResourceRead<Map<String, ComponentTypeProperty>> {\r
20         \r
21     Environment environment;\r
22     \r
23         public ReadComponentTypeInterfaceRequest(Resource resource, Environment environment) {\r
24                 super(resource);\r
25                 this.environment = environment;\r
26         }\r
27 \r
28         private void collect(ReadGraph graph, Resource t, THashMap<String, ComponentTypeProperty> result) throws DatabaseException {\r
29                 Layer0 L0 = Layer0.getInstance(graph);\r
30                 Map<String,Resource> domain = Layer0Utils.getDomainOf(graph, t); \r
31                 for(Map.Entry<String, Resource> entry : domain.entrySet()) {\r
32                         String name = entry.getKey();\r
33                         Resource relation = entry.getValue();\r
34                         if(graph.isSubrelationOf(relation, L0.HasProperty)) {\r
35                                 String typeName = graph.getPossibleRelatedValue(relation, L0.RequiresValueType, Bindings.STRING);\r
36                                 if(typeName == null) continue;\r
37                                 Type type;\r
38                                 try {\r
39                                     type = Environments.getType(environment, typeName);\r
40                                 } catch(SCLExpressionCompilationException e) {\r
41                                     e.printStackTrace();\r
42                                     continue;\r
43                                 }\r
44                                 ComponentTypeProperty property = new ComponentTypeProperty(relation, type);\r
45                                 result.put(name, property);\r
46                         }\r
47                 }\r
48         }\r
49         \r
50         @Override\r
51         public Map<String, ComponentTypeProperty> perform(ReadGraph graph)\r
52                         throws DatabaseException {\r
53                 \r
54                 THashMap<String, ComponentTypeProperty> result = \r
55                                 new THashMap<String, ComponentTypeProperty>();\r
56                 \r
57                 collect(graph, resource, result);\r
58                 //for(Resource t : graph.getSupertypes(resource)) collect(graph, t, result);\r
59                 \r
60                 return result;\r
61                 \r
62         }\r
63 \r
64 }\r