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