package org.simantics.document.server.request;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.simantics.db.Resource;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.IndexRoot;
+import org.simantics.db.common.request.PossibleTypedParent;
+import org.simantics.db.common.request.UnaryRead;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.request.VariableRead;
import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext;
import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest;
import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2;
import org.simantics.db.layer0.variable.Variable;
-import org.simantics.document.server.Functions;
-import org.simantics.document.server.bean.DataDefinition;
+import org.simantics.document.base.ontology.DocumentationResource;
import org.simantics.document.server.request.ServerSCLHandlerValueRequest.CompilationContext;
import org.simantics.layer0.Layer0;
-import org.simantics.scl.compiler.constants.StringConstant;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
-import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
-import org.simantics.scl.compiler.elaboration.expressions.EVar;
import org.simantics.scl.compiler.elaboration.expressions.EVariable;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
- private final Variable context;
private final Pair<Resource,Resource> componentTypeAndRoot;
private final Resource literal;
+ protected String possibleExpectedValueType;
public static class CompilationContext extends AbstractExpressionCompilationContext {
public final Map<String, ComponentTypeProperty> propertyMap;
}
}
- private ServerSCLHandlerValueRequest(Variable context, Pair<Resource,Resource> componentTypeAndRoot, Resource literal) {
+ private ServerSCLHandlerValueRequest(Pair<Resource,Resource> componentTypeAndRoot, Resource literal, String possibleExpectedValueType) {
assert(literal != null);
- this.context = context;
this.literal = literal;
this.componentTypeAndRoot = componentTypeAndRoot;
+ this.possibleExpectedValueType = possibleExpectedValueType;
}
public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
- this(context, getComponentTypeAndRoot(graph, context), context.getRepresents(graph));
+ this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph)));
+ }
+
+ public ServerSCLHandlerValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p));
}
private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException {
return Pair.make(type, root);
}
}
- parent = parent.getParent(graph);
- Resource root = graph.syncRequest(new IndexRoot(property.getRepresents(graph)));
- return Pair.make(parent.getType(graph), root);
+ while(represents == null) {
+ parent = parent.getParent(graph);
+ represents = parent.getPossibleRepresents(graph);
+ }
+ Resource componentType = parent.getType(graph);
+ Resource root = graph.syncRequest(new IndexRoot(parent.getRepresents(graph)));
+ return Pair.make(componentType, root);
}
-
public static List<TCon> getEffects(ReadGraph graph, Variable context) throws DatabaseException {
try {
ServerSCLHandlerValueRequest req = new ServerSCLHandlerValueRequest(graph, context);
@Override
protected CompilationContext getCompilationContext(ReadGraph graph) throws DatabaseException {
- return graph.syncRequest(new VariableRead<CompilationContext>(context) {
+ return graph.syncRequest(new UnaryRead<Pair<Resource,Resource>,CompilationContext>(componentTypeAndRoot) {
@Override
public CompilationContext perform(ReadGraph graph) throws DatabaseException {
- Pair<Resource,Resource> parameter = getComponentTypeAndRoot(graph, variable);
RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second));
-
Map<String, ComponentTypeProperty> propertyMap =
graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
-
-// Map<String, ComponentTypeProperty> result = new HashMap<String,ComponentTypeProperty>(propertyMap);
-// for(DataDefinition dd : Functions.dataDefinitions(graph, variable)) {
-// result.put(dd.target, null);
-// }
-
return new CompilationContext(runtimeEnvironment, propertyMap);
+
}
});
return null;
}
+ @Override
+ protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException {
+ return super.getExpectedType(graph, context);
+ }
+
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((context == null) ? 0 : context.hashCode());
- return result;
+ return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode();
}
@Override
if (getClass() != obj.getClass())
return false;
ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest) obj;
- if (context == null) {
- if (other.context != null)
- return false;
- } else if (!context.equals(other.context))
- return false;
- return true;
+ return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
+ }
+
+ private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component) throws DatabaseException {
+ if(component != null) {
+ Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
+ if(type != null) {
+ Resource root = graph.syncRequest(new IndexRoot(type));
+ return Pair.make(type, root);
+ } else {
+ Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
+ Resource componentType = graph.getSingleType(doc);
+ Resource root = graph.syncRequest(new IndexRoot(doc));
+ return Pair.make(componentType, root);
+ }
+ }
+ throw new IllegalStateException();
}
-
-// @Override
-// public int hashCode() {
-// return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode();
-// }
-//
-// @Override
-// public boolean equals(Object obj) {
-// if(this == obj)
-// return true;
-// if(obj == null || obj.getClass() != getClass())
-// return false;
-// ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest)obj;
-// return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
-// }
}