1 package org.simantics.document.server.request;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.request.IndexRoot;
6 import org.simantics.db.common.request.PossibleTypedParent;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext;
9 import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest;
10 import org.simantics.document.base.ontology.DocumentationResource;
11 import org.simantics.structural2.scl.FindPossibleComponentTypeRequest;
12 import org.simantics.utils.datastructures.Pair;
14 abstract public class ServerSCLValueRequestBase<CompilationContext extends AbstractExpressionCompilationContext> extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
16 static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal) throws DatabaseException {
17 if(component != null) {
18 Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
20 Resource root = graph.syncRequest(new IndexRoot(type));
21 return Pair.make(type, root);
23 Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
25 Resource componentType = graph.getSingleType(doc);
26 Resource root = graph.syncRequest(new IndexRoot(doc));
27 return Pair.make(componentType, root);
29 Resource root = graph.syncRequest(new IndexRoot(component));
30 return Pair.make(null, root);
33 // TODO: For Antti to consider and fix later
34 // Introduced to handle procedural user components where component == null
35 } else if (literal != null) {
36 Resource root = graph.syncRequest(new IndexRoot(literal));
37 return Pair.make(null, root);
39 throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null");