1 package org.simantics.structural2.scl;
3 import gnu.trove.map.hash.THashMap;
5 import java.util.Collections;
8 import org.simantics.databoard.Bindings;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.common.request.ResourceRead;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.util.Layer0Utils;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.scl.compiler.environment.Environment;
16 import org.simantics.scl.compiler.environment.Environments;
17 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
18 import org.simantics.scl.compiler.types.Type;
20 public class ReadComponentTypeInterfaceRequest extends ResourceRead<Map<String, ComponentTypeProperty>> {
22 Environment environment;
24 public ReadComponentTypeInterfaceRequest(Resource resource, Environment environment) {
26 this.environment = environment;
29 private void collect(ReadGraph graph, Resource t, THashMap<String, ComponentTypeProperty> result) throws DatabaseException {
30 Layer0 L0 = Layer0.getInstance(graph);
31 Map<String,Resource> domain = Layer0Utils.getDomainOf(graph, t);
32 for(Map.Entry<String, Resource> entry : domain.entrySet()) {
33 String name = entry.getKey();
34 Resource relation = entry.getValue();
35 if(graph.isSubrelationOf(relation, L0.HasProperty)) {
36 String typeName = graph.getPossibleRelatedValue(relation, L0.RequiresValueType, Bindings.STRING);
37 if(typeName == null) continue;
40 type = Environments.getType(environment, typeName);
41 } catch(SCLExpressionCompilationException e) {
45 ComponentTypeProperty property = new ComponentTypeProperty(relation, type);
46 result.put(name, property);
52 public Map<String, ComponentTypeProperty> perform(ReadGraph graph)
53 throws DatabaseException {
55 return Collections.emptyMap();
57 THashMap<String, ComponentTypeProperty> result =
58 new THashMap<String, ComponentTypeProperty>();
60 // TODO: For Antti to consider
61 // resource == null with procedural user components
63 collect(graph, resource, result);
64 //for(Resource t : graph.getSupertypes(resource)) collect(graph, t, result);