1 package org.simantics.modeling;
\r
3 import gnu.trove.map.hash.THashMap;
\r
5 import java.util.Map;
\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
21 * Deprecated: Use ComponentTypeSubstructure that supports deep references
\r
24 public class SubstructureMapRequest extends ResourceRead<THashMap<String, Pair<String,Type>>>{
\r
26 public SubstructureMapRequest(Resource type) {
\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
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
55 collect(graph, resource, propertyMap);
\r
56 for(Resource t : graph.getSupertypes(resource)) collect(graph, t, propertyMap);
\r