More control over computational values served by ReadGraph.
gitlab #169
Change-Id: I304de13f97c25661fed2905e33887e315144591e
package org.simantics.db.common.request;
+import org.simantics.db.ComputationalValue;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.utils.Functions;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.layer0.Layer0;
-import org.simantics.scl.reflection.ReflectionUtils;
-import org.simantics.scl.reflection.ValueNotFoundException;
import org.simantics.scl.runtime.function.FunctionImpl3;
/**
super(resource);
}
- private static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
+ public static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
@Override
public Object apply(ReadGraph graph, Resource resource, Object context) {
@Override
public Object perform(ReadGraph graph) throws DatabaseException {
String uri = graph.getURI(resource);
- try {
- if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
- return ReflectionUtils.getValue(uri).getValue();
- } catch (ValueNotFoundException e) {
- throw new DatabaseException("Couldn't adapt the value " + uri, e);
- }
+ if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
+ ComputationalValue ev = graph.adapt(resource, ComputationalValue.class);
+ return ev.getValue(graph, resource);
+
}
}
import org.simantics.databoard.util.binary.BinaryFile;
import org.simantics.databoard.util.binary.RandomAccessBinary;
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ComputationalValue;
import org.simantics.db.DevelopmentKeys;
import org.simantics.db.ExternalValueSupport;
import org.simantics.db.ReadGraph;
return getValue(r, binding);
}
} else if(types.contains(L0.ExternalValue)) {
- try {
- return (T)ReflectionUtils.getValue(getURI(r)).getValue();
- } catch(ValueNotFoundException e) {
- throw new DatabaseException(e);
- } catch(ClassCastException e) {
- throw new DatabaseException(e);
+ ComputationalValue cv = syncRequest(new PossibleAdapter<ComputationalValue>(r, ComputationalValue.class), TransientCacheAsyncListener.instance());
+ if(cv != null) {
+ return cv.getValue(this, r);
+ } else {
+ // This should not even be possible since L0 defines an adapter for all values
+ try {
+ return (T)ReflectionUtils.getValue(getURI(r)).getValue();
+ } catch(ValueNotFoundException e) {
+ throw new DatabaseException(e);
+ } catch(ClassCastException e) {
+ throw new DatabaseException(e);
+ }
}
}
else {
</resource>
</target>
+ <target interface="org.simantics.db.ComputationalValue">
+ <!-- TODO: should be ExternalValue but handle all values to minimise regressions for the time being -->
+ <type uri="http://www.simantics.org/Layer0-0.0/Value"
+ class="org.simantics.db.layer0.adapter.ReflectionComputationalValue">
+ </type>
+ <resource uri="http://www.simantics.org/Layer0-0.0/Functions/sclValue"
+ class="org.simantics.db.layer0.adapter.SCLComputationalValue">
+ </resource>
+ </target>
+
</adapters>
--- /dev/null
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.db.ConverterComputationalValue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.function.FunctionImpl3;
+
+abstract public class ContextualRelatedValue implements ConverterComputationalValue {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
+
+ return (T)new FunctionImpl3<ReadGraph, Resource, Object, Object>() {
+
+ @Override
+ public Object apply(ReadGraph graph, Resource converter, Object context) {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ if(context instanceof Variable) {
+ Variable variable = (Variable)context;
+ try {
+ Function1<Object,Object> fn = getFunction(graph, variable.getParent(graph).getRepresents(graph), variable.getRepresents(graph), variable.getPredicateResource(graph));
+ sclContext.put("graph", graph);
+ return fn.apply(variable);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ } if (context instanceof Resource) {
+ Resource resource = (Resource)context;
+ try {
+ Function1<Object,Object> fn = getFunction(graph, null, resource, null);
+ return fn.apply(resource);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ } else {
+ throw new IllegalStateException("Unknown context " + context);
+ }
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+ }
+
+ };
+
+ }
+
+}
--- /dev/null
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.db.ComputationalValue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.reflection.ReflectionUtils;
+import org.simantics.scl.reflection.ValueNotFoundException;
+
+public class ReflectionComputationalValue implements ComputationalValue {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
+
+ try {
+ return (T)ReflectionUtils.getValue(graph.getURI(resource)).getValue();
+ } catch(ValueNotFoundException e) {
+ throw new DatabaseException(e);
+ } catch(ClassCastException e) {
+ throw new DatabaseException(e);
+ }
+
+ }
+
+}
--- /dev/null
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.scl.CompileResourceValueRequest;
+import org.simantics.db.layer0.scl.CompileValueRequest;
+import org.simantics.scl.runtime.function.Function1;
+
+public class SCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ if(s != null && p != null && o != null) {
+ return CompileValueRequest.compile(graph, s, o, p);
+ } else if (o != null) {
+ return CompileResourceValueRequest.compile(graph, o);
+ } else {
+ throw new DatabaseException("Could not compile SCL expression: s=" + s+ " p=" + p + " o=" + o);
+ }
+
+ }
+
+}
import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.db.request.Read;
return base;
}
- protected static String resolveExpectedValueType(ReadGraph graph, org.simantics.db.layer0.variable.Variable context) throws DatabaseException {
+ protected static String resolveExpectedValueType(ReadGraph graph, Resource predicate) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
- String valueType = graph.getPossibleRelatedValue(context.getPredicateResource(graph), L0.RequiresValueType, Bindings.STRING);
- return valueType;
+ return graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING);
}
+
}
*
* @author Antti Villberg
*/
-public class CompileResourceValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Resource> {
+public class CompileResourceValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
public static class CompilationContext extends AbstractExpressionCompilationContext {
public CompilationContext(RuntimeEnvironment runtimeEnvironment) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Resource,Object> exp = graph.syncRequest(new CompileResourceValueRequest(literal),
- TransientCacheListener.<Function1<Resource,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileResourceValueRequest(literal),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(literal);
} catch (DatabaseException e) {
}
}
+ public static Function1<Object,Object> compile(ReadGraph graph, Resource literal) throws DatabaseException {
+ return graph.syncRequest(new CompileResourceValueRequest(literal), TransientCacheListener.instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
*
* @author Tuukka Lehtonen
*/
-public class CompileValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+public class CompileValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
public static class CompilationContext extends AbstractExpressionCompilationContext {
public CompilationContext(RuntimeEnvironment runtimeEnvironment) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
}
}
+ public static Function1<Object,Object> compile(ReadGraph graph, Resource component, Resource literal, Resource predicate) throws DatabaseException {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(component, literal, predicate),
+ TransientCacheListener.instance());
+ sclContext.put("graph", graph);
+ return exp;
+ } catch (DatabaseException e) {
+ throw (DatabaseException)e;
+ } catch (Throwable t) {
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
--- /dev/null
+package org.simantics.db;
+
+import org.simantics.db.exception.DatabaseException;
+
+public interface ComputationalValue {
+
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException;
+
+}
--- /dev/null
+package org.simantics.db;
+
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.runtime.function.Function1;
+
+public interface ConverterComputationalValue extends ComputationalValue {
+
+ /*
+ * This computes the expression function that shall be called with given context as defined in ReadGraph.getRelatedValue2
+ * Context can be Resource (literal) or Variable.
+ * With Resource context this gets called with o != null and s==null and p==null
+ * With Variable property context this gets called with (represents of parent, represents, predicate resource)
+ */
+ Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException;
+
+}
<target interface="org.simantics.db.layer0.variable.VariableBuilder">
<type uri="http://www.simantics.org/Modeling-1.2/SCLCommandSession" class="org.simantics.document.server.state.StateVariableBuilder" />
</target>
+ <target interface="org.simantics.db.ComputationalValue">
+ <resource uri="http://www.simantics.org/Documentation-0.0/Functions/sclValue"
+ class="org.simantics.document.server.SCLComputationalValue">
+ </resource>
+ </target>
+ <target interface="org.simantics.db.ComputationalValue">
+ <resource uri="http://www.simantics.org/Documentation-0.0/Functions/sclHandlerValue"
+ class="org.simantics.document.server.HandlerSCLComputationalValue">
+ </resource>
+ </target>
</adapters>
\ No newline at end of file
--- /dev/null
+package org.simantics.document.server;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ContextualRelatedValue;
+import org.simantics.document.server.request.ServerSCLHandlerValueRequest;
+import org.simantics.scl.runtime.function.Function1;
+
+public class HandlerSCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return ServerSCLHandlerValueRequest.compile(graph, s, o, p);
+ }
+
+}
--- /dev/null
+package org.simantics.document.server;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ContextualRelatedValue;
+import org.simantics.document.server.request.ServerSCLValueRequest;
+import org.simantics.scl.runtime.function.Function1;
+
+public class SCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return ServerSCLValueRequest.compile(graph, s, o, p);
+ }
+
+}
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.base.ontology.DocumentationResource;
import org.simantics.document.server.request.ServerSCLHandlerValueRequest.CompilationContext;
import org.simantics.layer0.Layer0;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
import org.simantics.structural2.scl.ReadComponentTypeInterfaceRequest;
import org.simantics.utils.datastructures.Pair;
-public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
- private final Variable context;
private final Pair<Resource,Resource> componentTypeAndRoot;
private final Resource literal;
protected String possibleExpectedValueType;
}
}
- private ServerSCLHandlerValueRequest(Variable context, Pair<Resource,Resource> componentTypeAndRoot, Resource literal, String possibleExpectedValueType) {
- assert(literal != null);
- this.context = context;
- this.literal = literal;
- this.componentTypeAndRoot = componentTypeAndRoot;
- this.possibleExpectedValueType = possibleExpectedValueType;
+ private ServerSCLHandlerValueRequest(Pair<Resource,Resource> componentTypeAndRoot, Resource literal, String possibleExpectedValueType) {
+ assert(literal != null);
+ 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), resolveExpectedValueType(graph, context));
- }
+ public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
+ 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 {
Variable parent = property.getParent(graph);
Resource represents = parent.getRepresents(graph);
return Pair.make(parent.getType(graph), root);
}
+ 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();
+ }
public static List<TCon> getEffects(ReadGraph graph, Variable context) throws DatabaseException {
try {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
}
}
+ public static Function1<Object, Object> compile(ReadGraph graph, Variable context) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, context), TransientCacheListener.instance());
+ }
+
+ public static Function1<Object, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLHandlerValueRequest(graph, s, o, p), TransientCacheListener.<Function1<Object,Object>>instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
@Override
protected CompilationContext getCompilationContext(ReadGraph graph) throws DatabaseException {
-
- return graph.syncRequest(new VariableRead<CompilationContext>(context) {
-
- @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());
+
+ return graph.syncRequest(new UnaryRead<Pair<Resource,Resource>,CompilationContext>(componentTypeAndRoot) {
+
+ @Override
+ public CompilationContext perform(ReadGraph graph) throws DatabaseException {
+
+ 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());
+ return new CompilationContext(runtimeEnvironment, propertyMap);
+
+
+ }
+
+ });
-// 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);
-
- }
-
- });
-
}
@Override
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;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- 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;
- }
+ @Override
+ public int hashCode() {
+ return 31*(31*getClass().hashCode() + literal.hashCode()) + componentTypeAndRoot.hashCode();
+ }
-// @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);
-// }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ServerSCLHandlerValueRequest other = (ServerSCLHandlerValueRequest) obj;
+ return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
+ }
+
}
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.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.base.ontology.DocumentationResource;
import org.simantics.document.server.request.ServerSCLValueRequest.CompilationContext;
import org.simantics.layer0.Layer0;
import org.simantics.scl.compiler.common.names.Name;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
private final Pair<Resource,Resource> componentTypeAndRoot;
private final Resource literal;
}
public ServerSCLValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
- this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context));
+ this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context.getPredicateResource(graph)));
+ }
+
+ public ServerSCLValueRequest(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(parent.getType(graph), root);
}
+ 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));
+ // System.err.println("getComponentTypeAndRoot3 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root));
+ return Pair.make(type, root);
+ } else {
+ Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
+ if(doc != null) {
+ Resource componentType = graph.getSingleType(doc);
+ Resource root = graph.syncRequest(new IndexRoot(doc));
+ return Pair.make(componentType, root);
+ } else {
+ System.err.println("component = " + component);
+ Resource root = graph.syncRequest(new IndexRoot(component));
+// Resource componentType = graph.getSingleType(doc);
+ return Pair.make(null, root);
+ }
+ }
+ }
+ throw new IllegalStateException();
+ }
+
public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = compile(graph, context);
+ Function1<Object,Object> exp = compile(graph, context);
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
}
}
- public static Function1<Variable, Object> compile(ReadGraph graph, Variable context) throws DatabaseException {
- return graph.syncRequest(new ServerSCLValueRequest(graph, context), TransientCacheListener.<Function1<Variable,Object>>instance());
+ public static Function1<Object, Object> compile(ReadGraph graph, Variable context) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLValueRequest(graph, context), TransientCacheListener.instance());
}
+ public static Function1<Object, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLValueRequest(graph, s, o, p), TransientCacheListener.instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
}
- public static Function1<Variable, Object> validate(ReadGraph graph, Variable context) throws DatabaseException {
- return graph.syncRequest(new ServerSCLValueValidationRequest(graph, context), TransientCacheListener.<Function1<Variable,Object>>instance());
+ public static Function1<Object, Object> validate(ReadGraph graph, Variable context) throws DatabaseException {
+ return graph.syncRequest(new ServerSCLValueValidationRequest(graph, context), TransientCacheListener.instance());
}
public static class ServerSCLValueValidationRequest extends ServerSCLValueRequest {
L0.Functions.listResources : L0.ExternalValue
L0.Functions.resourceAsValue : L0.ExternalValue
L0.Functions.functionApplication : L0.ExternalValue
+
+// This was replaced by L0.Functions.sclValue to make things more uniform
L0.Functions.computeExpression : L0.ExternalValue
+ @L0.tag L0.Deprecated
+
+L0.Functions.sclValue : L0.ExternalValue
L0.Functions.composedPropertyValue : L0.ExternalValue
L0.Functions.standardValueAccessor : L0.ExternalValue
@L0.tag L0.Abstract
>-- L0.SCLValue.expression --> L0.String <R L0.HasProperty : L0.TotalFunction
>-- L0.SCLValue.environment --> L0.SCLValue.Environment <R L0.IsRelatedTo : L0.TotalFunction
- @L0.assert L0.ConvertsToValueWith L0.Functions.computeExpression
+ @L0.assert L0.ConvertsToValueWith L0.Functions.sclValue
L0.SCLValueType <T L0.Entity
>-- L0.SCLValueType.validator ==> "Variable -> <ReadGraph> String" <R L0.HasProperty
</resource>
</target>
+ <target interface="org.simantics.db.ComputationalValue">
+ <resource uri="http://www.simantics.org/Modeling-0.0/Functions/sclValue"
+ class="org.simantics.modeling.SCLComputationalValue">
+ </resource>
+ </target>
+
</adapters>
\ No newline at end of file
--- /dev/null
+package org.simantics.modeling;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ContextualRelatedValue;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.structural2.scl.CompileStructuralValueRequest;
+
+public class SCLComputationalValue extends ContextualRelatedValue {
+
+ @Override
+ public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return CompileStructuralValueRequest.compile(graph, s, o, p);
+ }
+
+}
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLQueryRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileSCLQueryRequest(graph, context),
+ TransientCacheListener.<Function1<Object,Object>>instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileSCLValueRequest(graph, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileStructuralValueRequest(graph, context) {
+ Function1<Object,Object> exp = graph.syncRequest(new CompileStructuralValueRequest(graph, context) {
protected String getExpressionText(ReadGraph graph) throws DatabaseException {
return expression;
}
},
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
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;
*
* @author Antti Villberg
*/
-abstract public class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+abstract public class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Object> {
protected final Resource relation;
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Variable,Object> exp = graph.syncRequest(new CompileProceduralExpressionValueRequest(graph, expression, context),
- TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileProceduralExpressionValueRequest(graph, expression, context),
+ TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (DatabaseException e) {
Object oldGraph = sclContext.get("graph");
CompileStructuralValueRequest request = new CompileStructuralValueRequest(graph, context);
try {
- Function1<Variable,Object> exp = graph.syncRequest(request, TransientCacheListener.<Function1<Variable,Object>>instance());
+ Function1<Object,Object> exp = graph.syncRequest(request, TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp.apply(context);
} catch (Throwable t) {
}
}
+ public static Function1<Object, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return graph.syncRequest(new CompileStructuralValueRequest(s, o, p), TransientCacheListener.instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {