]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/ProceduralSubstructureMapRequest.java
Prevent exceptions in procedural substructure requests
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / ProceduralSubstructureMapRequest.java
index 4a87bc29f221cda8cfac71afa223c15f53654382..6256891b82ae17a96391e7a05399b2ef9ae3f640 100644 (file)
@@ -1,40 +1,50 @@
-package org.simantics.modeling;\r
-\r
-import gnu.trove.map.hash.THashMap;\r
-\r
-import org.simantics.db.ReadGraph;\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.VariableRead;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.scl.compiler.types.Type;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-public class ProceduralSubstructureMapRequest extends VariableRead<THashMap<String, Pair<String,Type>>>{\r
-\r
-    public ProceduralSubstructureMapRequest(Variable composite) {\r
-        super(composite);\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
-        for(Variable child : variable.getChildren(graph)) {\r
-               for(Variable property : child.getProperties(graph)) {\r
-                   PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(property.getPredicateResource(graph)));\r
-                propertyMap.put(child.getName(graph) + "." + propertyInfo.name,\r
-                        Pair.make("/" + child.getName(graph) + "#" + propertyInfo.name,\r
-                                SCLTypeUtils.getType(propertyInfo)));\r
-               }\r
-        }\r
-       for(Variable property : variable.getProperties(graph)) {\r
-           PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(property.getPredicateResource(graph)));\r
-            propertyMap.put(propertyInfo.name,\r
-                    Pair.make("#" + propertyInfo.name,\r
-                            SCLTypeUtils.getType(propertyInfo)));\r
-       }\r
-        return propertyMap;\r
-    }\r
-\r
-}\r
+package org.simantics.modeling;
+
+import gnu.trove.map.hash.THashMap;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+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.VariableRead;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.utils.datastructures.Pair;
+
+public class ProceduralSubstructureMapRequest extends VariableRead<THashMap<String, Pair<String,Type>>>{
+
+    public ProceduralSubstructureMapRequest(Variable composite) {
+        super(composite);
+    }
+
+    @Override
+    public THashMap<String, Pair<String,Type>> perform(ReadGraph graph) throws DatabaseException {
+        THashMap<String, Pair<String,Type>> propertyMap = new THashMap<String, Pair<String,Type>>();
+        for(Variable child : variable.getChildren(graph)) {
+            for(Variable property : child.getProperties(graph)) {
+                Resource predicate = property.getPossiblePredicateResource(graph);
+                if (predicate == null)
+                    continue;
+                
+                PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(predicate));
+                propertyMap.put(child.getName(graph) + "." + propertyInfo.name,
+                        Pair.make("/" + child.getName(graph) + "#" + propertyInfo.name,
+                                SCLTypeUtils.getType(propertyInfo)));
+            }
+        }
+        for(Variable property : variable.getProperties(graph)) {
+            Resource predicate = property.getPossiblePredicateResource(graph);
+            if (predicate == null)
+                continue;
+            
+            PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(predicate));
+            propertyMap.put(propertyInfo.name,
+                    Pair.make("#" + propertyInfo.name,
+                            SCLTypeUtils.getType(propertyInfo)));
+        }
+        
+        return propertyMap;
+    }
+
+}