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;fp=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fscl%2FAbstractCompileStructuralValueRequest.java;h=fce1abaa2d8a62fa3fcadfd97c12c66b037e0655;hp=c4b4e341fb85b2aa551612e028a2dafca387f06c;hb=04bf1d8e31c85530bcd47d41051362533997134e;hpb=4c6e2a31144508a830489706ad4f80f338d0c3ae 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..fce1abaa2 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 @@ -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); + } + }