]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
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 (file)
index 0000000..2aafa7c
--- /dev/null
@@ -0,0 +1,62 @@
+package org.simantics.modeling;\r
+\r
+import gnu.trove.map.hash.THashMap;\r
+\r
+import java.util.Map;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ResourceRead;\r
+import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.PropertyInfo;\r
+import org.simantics.db.layer0.request.PropertyInfoRequest;\r
+import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.scl.compiler.types.Type;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+/**\r
+ * Deprecated: Use ComponentTypeSubstructure that supports deep references\r
+ */\r
+@Deprecated\r
+public class SubstructureMapRequest extends ResourceRead<THashMap<String, Pair<String,Type>>>{\r
+\r
+    public SubstructureMapRequest(Resource type) {\r
+        super(type);\r
+    }\r
+\r
+    private void collect(ReadGraph graph, Resource t, THashMap<String, Pair<String,Type>> result) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        for(Resource relation : graph.getObjects(t, L0.DomainOf)) {\r
+            if(graph.isSubrelationOf(relation, L0.HasProperty)) {\r
+                PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(relation));\r
+                result.put(propertyInfo.name, Pair.make("#" + propertyInfo.name, SCLTypeUtils.getType(propertyInfo)));\r
+            }\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public THashMap<String, Pair<String,Type>> perform(ReadGraph graph) throws DatabaseException {\r
+        THashMap<String, Pair<String,Type>> propertyMap = new THashMap<String, Pair<String,Type>>();\r
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
+        Resource composite = graph.getPossibleObject(resource, STR.IsDefinedBy);\r
+        if(composite != null) {\r
+               for(Map.Entry<String, Resource> child : graph.sync(new UnescapedChildMapOfResource(composite)).entrySet()) {\r
+                   for(PropertyInfo property : graph.sync(new UnescapedPropertyMapOfResource(child.getValue())).values()) {\r
+                       propertyMap.put(child.getKey() + "." + property.name,\r
+                               Pair.make("/" + child.getKey() + "#" + property.name, \r
+                                       SCLTypeUtils.getType(property)));\r
+                   }\r
+               }\r
+        }\r
+\r
+        collect(graph, resource, propertyMap);\r
+        for(Resource t : graph.getSupertypes(resource)) collect(graph, t, propertyMap);\r
+\r
+        return propertyMap;\r
+        \r
+    }\r
+\r
+}\r