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