]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/SubstructureMapRequest.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / SubstructureMapRequest.java
1 package org.simantics.modeling;\r
2 \r
3 import gnu.trove.map.hash.THashMap;\r
4 \r
5 import java.util.Map;\r
6 \r
7 import org.simantics.db.ReadGraph;\r
8 import org.simantics.db.Resource;\r
9 import org.simantics.db.common.request.ResourceRead;\r
10 import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
11 import org.simantics.db.exception.DatabaseException;\r
12 import org.simantics.db.layer0.request.PropertyInfo;\r
13 import org.simantics.db.layer0.request.PropertyInfoRequest;\r
14 import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;\r
15 import org.simantics.layer0.Layer0;\r
16 import org.simantics.scl.compiler.types.Type;\r
17 import org.simantics.structural.stubs.StructuralResource2;\r
18 import org.simantics.utils.datastructures.Pair;\r
19 \r
20 /**\r
21  * Deprecated: Use ComponentTypeSubstructure that supports deep references\r
22  */\r
23 @Deprecated\r
24 public class SubstructureMapRequest extends ResourceRead<THashMap<String, Pair<String,Type>>>{\r
25 \r
26     public SubstructureMapRequest(Resource type) {\r
27         super(type);\r
28     }\r
29 \r
30     private void collect(ReadGraph graph, Resource t, THashMap<String, Pair<String,Type>> result) throws DatabaseException {\r
31         Layer0 L0 = Layer0.getInstance(graph);\r
32         for(Resource relation : graph.getObjects(t, L0.DomainOf)) {\r
33             if(graph.isSubrelationOf(relation, L0.HasProperty)) {\r
34                 PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(relation));\r
35                 result.put(propertyInfo.name, Pair.make("#" + propertyInfo.name, SCLTypeUtils.getType(propertyInfo)));\r
36             }\r
37         }\r
38     }\r
39     \r
40     @Override\r
41     public THashMap<String, Pair<String,Type>> perform(ReadGraph graph) throws DatabaseException {\r
42         THashMap<String, Pair<String,Type>> propertyMap = new THashMap<String, Pair<String,Type>>();\r
43         StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
44         Resource composite = graph.getPossibleObject(resource, STR.IsDefinedBy);\r
45         if(composite != null) {\r
46                 for(Map.Entry<String, Resource> child : graph.sync(new UnescapedChildMapOfResource(composite)).entrySet()) {\r
47                     for(PropertyInfo property : graph.sync(new UnescapedPropertyMapOfResource(child.getValue())).values()) {\r
48                         propertyMap.put(child.getKey() + "." + property.name,\r
49                                 Pair.make("/" + child.getKey() + "#" + property.name, \r
50                                         SCLTypeUtils.getType(property)));\r
51                     }\r
52                 }\r
53         }\r
54 \r
55         collect(graph, resource, propertyMap);\r
56         for(Resource t : graph.getSupertypes(resource)) collect(graph, t, propertyMap);\r
57 \r
58         return propertyMap;\r
59         \r
60     }\r
61 \r
62 }\r