1 package org.simantics.modeling;
3 import gnu.trove.map.hash.THashMap;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ResourceRead;
10 import org.simantics.db.common.uri.UnescapedChildMapOfResource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.request.PropertyInfo;
13 import org.simantics.db.layer0.request.PropertyInfoRequest;
14 import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
15 import org.simantics.layer0.Layer0;
16 import org.simantics.scl.compiler.types.Type;
17 import org.simantics.structural.stubs.StructuralResource2;
18 import org.simantics.utils.datastructures.Pair;
21 * Deprecated: Use ComponentTypeSubstructure that supports deep references
24 public class SubstructureMapRequest extends ResourceRead<THashMap<String, Pair<String,Type>>>{
26 public SubstructureMapRequest(Resource type) {
30 private void collect(ReadGraph graph, Resource t, THashMap<String, Pair<String,Type>> result) throws DatabaseException {
31 Layer0 L0 = Layer0.getInstance(graph);
32 for(Resource relation : graph.getObjects(t, L0.DomainOf)) {
33 if(graph.isSubrelationOf(relation, L0.HasProperty)) {
34 PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(relation));
35 result.put(propertyInfo.name, Pair.make("#" + propertyInfo.name, SCLTypeUtils.getType(propertyInfo)));
41 public THashMap<String, Pair<String,Type>> perform(ReadGraph graph) throws DatabaseException {
42 THashMap<String, Pair<String,Type>> propertyMap = new THashMap<String, Pair<String,Type>>();
43 StructuralResource2 STR = StructuralResource2.getInstance(graph);
44 Resource composite = graph.getPossibleObject(resource, STR.IsDefinedBy);
45 if(composite != null) {
46 for(Map.Entry<String, Resource> child : graph.sync(new UnescapedChildMapOfResource(composite)).entrySet()) {
47 for(PropertyInfo property : graph.sync(new UnescapedPropertyMapOfResource(child.getValue())).values()) {
48 propertyMap.put(child.getKey() + "." + property.name,
49 Pair.make("/" + child.getKey() + "#" + property.name,
50 SCLTypeUtils.getType(property)));
55 collect(graph, resource, propertyMap);
56 for(Resource t : graph.getSupertypes(resource)) collect(graph, t, propertyMap);