]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java
Simantics Console
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / scl / AbstractCompileStructuralValueRequest.java
index c4b4e341fb85b2aa551612e028a2dafca387f06c..fce1abaa2d8a62fa3fcadfd97c12c66b037e0655 100644 (file)
@@ -26,6 +26,8 @@ import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.structural2.scl.AbstractCompileStructuralValueRequest.CompilationContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Compiles an SCL expression that is attached to a literal
@@ -35,6 +37,8 @@ import org.simantics.structural2.scl.AbstractCompileStructuralValueRequest.Compi
  */
 public abstract class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
     
+    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCompileStructuralValueRequest.class);
+
     protected final Resource relation;
     
     public static class CompilationContext extends AbstractExpressionCompilationContext {
@@ -53,8 +57,27 @@ public abstract class AbstractCompileStructuralValueRequest extends AbstractExpr
 
     @Override
     abstract protected String getExpressionText(ReadGraph graph) throws DatabaseException;
+    
+    /*
+     * @throws DatabaseException is an index root could not be found
+     */
     abstract protected Resource getIndexRoot(ReadGraph graph) throws DatabaseException;
+    /*
+     * Does not throw if the graph is valid.
+     * 
+     * @return null if component type was not availble
+     * 
+     */
     abstract protected Resource getComponentType(ReadGraph graph) throws DatabaseException;
+
+    protected Resource getPossibleIndexRoot(ReadGraph graph) throws DatabaseException {
+        try {
+            return getIndexRoot(graph);
+        } catch (DatabaseException e) {
+            LOGGER.error("Error while resolving index root during structural value compilation", e);
+            return null;
+        }
+    }
     
     @Override
     protected Type getExpectedType(ReadGraph graph, CompilationContext context)
@@ -135,4 +158,23 @@ public abstract class AbstractCompileStructuralValueRequest extends AbstractExpr
             return null;
     }
     
+    @Override
+    protected String getContextDescription(ReadGraph graph) throws DatabaseException {
+        Resource componentType = getComponentType(graph);
+        if(componentType != null) {
+            String uri = graph.getPossibleURI(componentType);
+            if(uri != null)
+                return uri;
+        }
+        // OK, no component type - report index root then
+        Resource indexRoot = getPossibleIndexRoot(graph);
+        if(indexRoot != null) {
+            String uri = graph.getPossibleURI(componentType);
+            if(uri != null)
+                return uri;
+        }
+        // OK, nothing - report default
+        return super.getContextDescription(graph);
+    }
+    
 }