]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/ProceduralSubstructureMapRequest.java
Multiple readers and variable optimization
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / ProceduralSubstructureMapRequest.java
1 package org.simantics.modeling;
2
3 import gnu.trove.map.hash.THashMap;
4
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.request.PropertyInfo;
8 import org.simantics.db.layer0.request.PropertyInfoRequest;
9 import org.simantics.db.layer0.request.VariableRead;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.scl.compiler.types.Type;
12 import org.simantics.utils.datastructures.Pair;
13
14 public class ProceduralSubstructureMapRequest extends VariableRead<THashMap<String, Pair<String,Type>>>{
15
16     public ProceduralSubstructureMapRequest(Variable composite) {
17         super(composite);
18     }
19
20     @Override
21     public THashMap<String, Pair<String,Type>> perform(ReadGraph graph) throws DatabaseException {
22         THashMap<String, Pair<String,Type>> propertyMap = new THashMap<String, Pair<String,Type>>();
23         for(Variable child : variable.getChildren(graph)) {
24                 for(Variable property : child.getProperties(graph)) {
25                     PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(property.getPredicateResource(graph)));
26                 propertyMap.put(child.getName(graph) + "." + propertyInfo.name,
27                         Pair.make("/" + child.getName(graph) + "#" + propertyInfo.name,
28                                 SCLTypeUtils.getType(propertyInfo)));
29                 }
30         }
31         for(Variable property : variable.getProperties(graph)) {
32             PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(property.getPredicateResource(graph)));
33             propertyMap.put(propertyInfo.name,
34                     Pair.make("#" + propertyInfo.name,
35                             SCLTypeUtils.getType(propertyInfo)));
36         }
37         return propertyMap;
38     }
39
40 }