1 package org.simantics.structural2.scl;
3 import gnu.trove.map.hash.THashMap;
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;
19 public class ReadComponentTypeInterfaceRequest extends ResourceRead<Map<String, ComponentTypeProperty>> {
21 Environment environment;
23 public ReadComponentTypeInterfaceRequest(Resource resource, Environment environment) {
25 this.environment = environment;
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;
39 type = Environments.getType(environment, typeName);
40 } catch(SCLExpressionCompilationException e) {
44 ComponentTypeProperty property = new ComponentTypeProperty(relation, type);
45 result.put(name, property);
51 public Map<String, ComponentTypeProperty> perform(ReadGraph graph)
52 throws DatabaseException {
54 THashMap<String, ComponentTypeProperty> result =
55 new THashMap<String, ComponentTypeProperty>();
57 collect(graph, resource, result);
58 //for(Resource t : graph.getSupertypes(resource)) collect(graph, t, result);