]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/ProceduralSubstructureMapRequest.java
Fixed multiple issues causing dangling references to discarded queries
[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.Resource;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.request.PropertyInfo;
9 import org.simantics.db.layer0.request.PropertyInfoRequest;
10 import org.simantics.db.layer0.request.VariableRead;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.scl.compiler.types.Type;
13 import org.simantics.utils.datastructures.Pair;
14
15 public class ProceduralSubstructureMapRequest extends VariableRead<THashMap<String, Pair<String,Type>>>{
16
17     public ProceduralSubstructureMapRequest(Variable composite) {
18         super(composite);
19     }
20
21     @Override
22     public THashMap<String, Pair<String,Type>> perform(ReadGraph graph) throws DatabaseException {
23         THashMap<String, Pair<String,Type>> propertyMap = new THashMap<String, Pair<String,Type>>();
24         for(Variable child : variable.getChildren(graph)) {
25             for(Variable property : child.getProperties(graph)) {
26                 Resource predicate = property.getPossiblePredicateResource(graph);
27                 if (predicate == null)
28                     continue;
29                 
30                 PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(predicate));
31                 propertyMap.put(child.getName(graph) + "." + propertyInfo.name,
32                         Pair.make("/" + child.getName(graph) + "#" + propertyInfo.name,
33                                 SCLTypeUtils.getType(propertyInfo)));
34             }
35         }
36         for(Variable property : variable.getProperties(graph)) {
37             Resource predicate = property.getPossiblePredicateResource(graph);
38             if (predicate == null)
39                 continue;
40             
41             PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(predicate));
42             propertyMap.put(propertyInfo.name,
43                     Pair.make("#" + propertyInfo.name,
44                             SCLTypeUtils.getType(propertyInfo)));
45         }
46         
47         return propertyMap;
48     }
49
50 }