X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FSubstructureMapRequest.java;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FSubstructureMapRequest.java;h=2aafa7c25c5643bd672c0ac6ec90ffd1b7073eaf;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SubstructureMapRequest.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SubstructureMapRequest.java new file mode 100644 index 000000000..2aafa7c25 --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SubstructureMapRequest.java @@ -0,0 +1,62 @@ +package org.simantics.modeling; + +import gnu.trove.map.hash.THashMap; + +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.PropertyInfo; +import org.simantics.db.layer0.request.PropertyInfoRequest; +import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource; +import org.simantics.layer0.Layer0; +import org.simantics.scl.compiler.types.Type; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.utils.datastructures.Pair; + +/** + * Deprecated: Use ComponentTypeSubstructure that supports deep references + */ +@Deprecated +public class SubstructureMapRequest extends ResourceRead>>{ + + public SubstructureMapRequest(Resource type) { + super(type); + } + + private void collect(ReadGraph graph, Resource t, THashMap> result) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + for(Resource relation : graph.getObjects(t, L0.DomainOf)) { + if(graph.isSubrelationOf(relation, L0.HasProperty)) { + PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(relation)); + result.put(propertyInfo.name, Pair.make("#" + propertyInfo.name, SCLTypeUtils.getType(propertyInfo))); + } + } + } + + @Override + public THashMap> perform(ReadGraph graph) throws DatabaseException { + THashMap> propertyMap = new THashMap>(); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource composite = graph.getPossibleObject(resource, STR.IsDefinedBy); + if(composite != null) { + for(Map.Entry child : graph.sync(new UnescapedChildMapOfResource(composite)).entrySet()) { + for(PropertyInfo property : graph.sync(new UnescapedPropertyMapOfResource(child.getValue())).values()) { + propertyMap.put(child.getKey() + "." + property.name, + Pair.make("/" + child.getKey() + "#" + property.name, + SCLTypeUtils.getType(property))); + } + } + } + + collect(graph, resource, propertyMap); + for(Resource t : graph.getSupertypes(resource)) collect(graph, t, propertyMap); + + return propertyMap; + + } + +}