import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest;
import org.simantics.db.layer0.util.RuntimeEnvironmentRequest;
import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2;
-import org.simantics.db.layer0.variable.Variable;
import org.simantics.layer0.Layer0;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
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
*
* @author Antti Villberg
*/
-abstract public class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+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 {
@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)
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);
+ }
+
}