X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fscl%2FAbstractCompileStructuralValueRequest.java;h=5e8538a69a80aca2ca8560577d6df868175bf332;hp=c4b4e341fb85b2aa551612e028a2dafca387f06c;hb=844ae73ef4a9109b12d4d810b9d3bc5e147e298f;hpb=15f274a205dabc11df9bf880291320fa5274e535 diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java index c4b4e341f..5e8538a69 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java @@ -9,10 +9,10 @@ import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.common.request.RuntimeEnvironmentRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext; import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest; -import org.simantics.db.layer0.util.RuntimeEnvironmentRequest; import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.elaboration.expressions.EApply; @@ -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 { + 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); + } + }